mocking - How to mock a single method in java -
is possible mock single method of java class?
for example:
class { long method1(); string method2(); int method3(); } // in other class class b { void somemethod(a a) { // how mock a.method1(...) such a.method1() returns value of // choosing; // whilst leaving a.method2() , a.method3() untouched. } }
use mockito's spy mechanism:
a = new a(); aspy = mockito.spy(a); mockito.when(aspy.method1()).thenreturn(5l); the use of spy calls default behavior of wrapped object method not stubbed.
Comments
Post a Comment