Is it possible to Mock a single method of a Java class?
For example:
class A { long method1(); String method2(); int method3(); } // in
Use Mockito's spy mechanism:
Mockito's
A a = new A(); A aSpy = Mockito.spy(a); Mockito.when(aSpy.method1()).thenReturn(5l);
The use of a spy calls the default behavior of the wrapped object for any method that is not stubbed.
Mockito.spy()/@Spy