mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-07 19:00:45 +08:00
commit
682d822249
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.alibaba.demo.basic.model.mock;
|
||||
|
||||
public interface BasicColor {
|
||||
|
||||
String getColorIndex();
|
||||
|
||||
}
|
@ -20,4 +20,8 @@ public class BlackBox extends Box implements Color {
|
||||
return "black";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColorIndex() {
|
||||
return "idx";
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.alibaba.demo.basic.model.mock;
|
||||
|
||||
public interface Color {
|
||||
public interface Color extends BasicColor{
|
||||
|
||||
String getColor();
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user