I have a problem with Mockito.
Is it possible to do such a thing:
ClassX x = mock(ClassX.class)
when(x.methodB()).thenReturn("toto");
String result = x.methodA();
I am working with Mockito 1.7.
I saw that there was a "spyware" system, but they say that it is not recommended to use it (why?) On the element being tested ...
I tried this spy feature anyway, but I get weird behavior.
Check what I want to do:
Real code:
String methodA(String arg) {
return this.methodB(arg);
}
String methodB(String arg) {
return "toto";
}
Test code:
@Test
public void testTest() {
final ClassX x = spy( new ClassX() );
final String argument = "arg";
doReturn("good").when(helper).methodB(argument);
assertTrue( x.methodB(argument).equals("good") );
assertTrue( x.methodA(argument).equals("good") );
}
As they said, I avoided whenReturn syntax, which may be a spy problem (but it doesn’t work either way)
What is strange is that: assertTrue (x.methodB (argument) .equals ("good")); OK
Only the second assertTrue (x.methodA (argument) .equals ("good")); does not work
helper.methodA() "toto" → , mock
mockito, "" ??? , B, , B, ...
, ... , ? , ? , , ...