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.

mockito.spy()/@spy


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -