package pack1;
class ClassToBeTest{
private void method1(){
boolean check = method2();
}
private boolean method2(){
return false;
}
}
package pack2;
public class TestClass{
@Test
public void test_method1() {
Object obj = Deencapsulation.newInstance("pack1.ClassToBeTest");
Deencapsulation.invoke(obj, "method1");
}
}
We see above that the ClassToBeTested is not public and hence not accessible outside its package, whereas all our test classes are in different packages. We can invoke the method of the class using JMockit's Deencapsulation APIs but how do we mock the method2() ?