I 'm a newie in Junit-testing but I have to test some code. I think now I know the basics of it, but I still got a problem on which I couldn't find anything on the Internet:
Here's the class I want to test:
public static void methodToTest(Label l2, Label l3, User u) {
int first = MyDB.someMethod(u.anotherMethod()).size();
int second = MyDB.someOtherMethod(u).size();
if (first == 1) {
l2.setCaption("...");
}
...
}
I don't want the System to create the Integers 'first' and 'second'. Instead I just want them to be '1' so I can test if the last lines of code work properly.
MyDB is a public class with static Methods (someMethod() and someOtherMethod())
I want to test the Method methodToTest. I tried to call this method with parms and at the end compare the modified params to the expected ones.
I use Mockito and PowerMockito.
This is one of my tries:
@PrepareForTest({ClassToTest.class, MyDB.class })
@RunWith(PowerMockRunner.class)
public class Test extends PowerMockTestCase{
PowerMockito.mockStatic(MyDB.class);
PowerMockito.doReturn(1).when(MyDB.someMethod(u.anotherMethod()).size());
PowerMockito.doReturn(1).when(MyDB.someOtherMethod(u).size());
ClassToTest.methodToTest(l1, l2, u);
assertTrue(l1.equals(l3) && l2.equals(l4));
}
The exception that I get is: 'Argument passed to when() is not a mock!'
I hope anyone can help me. I passed so many hours to solve this problem, without success.
Thank you!!!