mercredi 23 septembre 2015

How to mock a method call without actually calling its submethods

I started using JUnits (Mockito) from yesterday. I searched for similar question, but didn't find. I have a class with method method1() which in turn calls method2(). I don't want to mock method2 I am mocking call to method1(). I was expecting that it would return the custom object(without going ahead and calling method2) which I want. But instead it proceeds and tries to call method2().

class A {
 method1() {
 //do something.
 method2();
}
}

I mocked method1 and return any object (say new Integer(1)). I dont want method2 to be called. but when I am debugging this Junit. It goes and calls method2. Hence fails.

Please help me achieve this.

Aucun commentaire:

Enregistrer un commentaire