I have a class that has 2 ways, I want to duplicate the class and then mimic the first method , But not the second.
Example
class C {void m1 () {...} boolean m2 () {... return flag;}} unit test code:
c cock = Mockito.mock (C.class); . (Mockito.doNothing) when (cMock) .m1 (); Mockito.when (cMock.m2 ()) thenCallRealMethod () .; The strange thing is that M2 is not being called. Do I miss anything here?
This is also where Mockito.spy can be used is. This allows you to partial mocks on real objects. c cock = Mockito.spy (new C ()); . (Mockito.doNothing) when (cMock) .m1 ();
No comments:
Post a Comment