Closed zcmgyu closed 7 years ago
You can find information and example tests for cases like this in the JMockit Tutorial .
Thanks for response from you @rliesenfeld. I'm sorry to bother you, could I ask you something more. I also tried your suggestion but I've received another exception like below:
Test method
public class TestInterfaceTest {
@Mocked TestClass sut;
@Test
public void mockAllClassesImplementingAnInterface() {
TestInterface testInterface = new MockTestInterface<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
Thanks a lot
I have interface like this. TestInterface:
A TestClass have field is a instance of that interface TestClass:
This test case manages to verify call method subMethod from that field/ TestInterfaceTest:
This is result:
I think that issue here is that Deencapsulation.invoke(Deencapsulation.getField(sut, "inner"), "callMethod") call to this method TestInterface#callMethod(). So, can't verify that i did invoke to subMethod() method
Could you give me some ideas to resolve this problem. Thanks you.