I want to mock private method of a class under test but method return false first two times when the method is called after that it should return false. Here is the code wha
Here, you can over-ride a particular method of the testing class with mock behavior.
For the below code:
public class ClassToTest
{
public void methodToTest()
{
Integer integerInstance = new Integer(0);
boolean returnValue= methodToMock(integerInstance);
if(returnValue)
{
System.out.println("methodToMock returned true");
}
else
{
System.out.println("methodToMock returned true");
}
System.out.println();
}
private boolean methodToMock(int value)
{
return true;
}
}
Test class would be:
public class ClassToTestTest{
@Test
public void testMethodToTest(){
new Mockup(){
@Mock
private boolean methodToMock(int value){
return true;
}
};
....
}
}