Version of JMockit that was used: 1.21 I have interface like this. TestInterface:
public interface TestInterface {
boolean callMethod();
}
A TestClass have field is a instance of that interface TestClass:
public class TestClass {
private final TestInterface inner = new TestInterface() {
@Override
public boolean callMethod() {
subMethod();
return false;
}
};
public void subMethod() { System.out.println("Sub method");
};
}
I try to verify calling method by fake an interfacein this tutorial. http://jmockit.org/tutorial/Faking.html#interfacesd
Test method.
public class TestInterfaceTest {
TestClass sut;
@Before
public void setUp() {
sut = Deencapsulation.newInstance(TestClass.class);
}
@Test
public void mockAllClassesImplementingAnInterface() {
TestInterface testInterface = new MockUp<TestInterface>() {
@Mock
public boolean callMethod(Invocation inv) {
inv.proceed(); // throw exception here -> Will my expected method be called here?
return true;
}
}.getMockInstance();
Deencapsulation.setField(sut, "INTER", testInterface);
new NonStrictExpectations() {
{
Deencapsulation.invoke(sut, "subMethod");
}
};
Boolean result = Deencapsulation.invoke(Deencapsulation.getField(sut, "INTER"), "callMethod");
assertTrue(result);
new Verifications() {
{
Deencapsulation.invoke(sut, "subMethod"); times = 1;
}
};
}
}
java.lang.IllegalArgumentException: No class with name "ndroid.examples.helloandroid.$Impl_TestInterface" found
If you guys don't mind, could you please tell me how to resolve this byg. Many thanks.