Merge pull request #231 from HankDevelop/0.6

接口继承支持
This commit is contained in:
Fan Lin 2021-10-27 07:27:46 +08:00 committed by GitHub
commit 682d822249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 1 deletions

View File

@ -59,4 +59,12 @@ public class DemoInherit {
BlackBox box = new BlackBox("");
return box.getColor();
}
/**
* call method defined in interface via sub class variable
*/
public String getColorIdxViaColor() {
Color color = new BlackBox("");
return color.getColorIndex();
}
}

View File

@ -0,0 +1,7 @@
package com.alibaba.demo.basic.model.mock;
public interface BasicColor {
String getColorIndex();
}

View File

@ -20,4 +20,8 @@ public class BlackBox extends Box implements Color {
return "black";
}
@Override
public String getColorIndex() {
return "idx";
}
}

View File

@ -1,6 +1,6 @@
package com.alibaba.demo.basic.model.mock;
public interface Color {
public interface Color extends BasicColor{
String getColor();

View File

@ -47,6 +47,11 @@ class DemoInheritTest {
private String get_color_from_blackbox(BlackBox self) {
return "color_from_blackbox";
}
@MockMethod(targetMethod = "getColorIndex")
private String get_colorIdx_from_color(Color self) {
return "colorIdx_from_color";
}
}
@Test
@ -91,4 +96,10 @@ class DemoInheritTest {
assertEquals("color_from_blackbox", color);
}
@Test
void should_mock_call_interface_method_by_sub_interface_object() {
String colorIdx = demoInherit.getColorIdxViaColor();
verify("get_colorIdx_from_color").withTimes(1);
assertEquals("colorIdx_from_color", colorIdx);
}
}

View File

@ -75,6 +75,12 @@ public class MockClassParser {
mns.addAll(getAllMethods(scn));
}
}
for(String interfaceClass : cn.interfaces) {
ClassNode scn = ClassUtil.getClassNode(interfaceClass);
if (scn != null) {
mns.addAll(getAllMethods(scn));
}
}
for (InnerClassNode innerClass : cn.innerClasses) {
if (innerClass.name.equals(cn.name + KOTLIN_POSTFIX_COMPANION)) {
ClassNode scn = ClassUtil.getClassNode(innerClass.name);