Tutorial by Examples

One can verify whether a method was called on a mock by using Mockito.verify(). Original mock = Mockito.mock(Original.class); String param1 = "Expected param value"; int param2 = 100; // Expected param value //Do something with mock //Verify if mock was used properly Mockito.veri...
In some cases it may not suffice to know whether more that one methods were called. The calling order of methods is also important. In such case you may use InOrder class of Mockito to verify the order of methods. SomeClass mock1 = Mockito.mock(SomeClass.class); otherClass mock2 = Mockito.mock(Oth...
ArgumentCaptor will to receive the actual invocation arguments that has been passed to method. ArgumentCaptor<Foo> captor = ArgumentCaptor.forClass(Foo.class); verify(mockObj).doSomethind(captor.capture()); Foo invocationArg = captor.getValue(); //do any assertions on invocationArg For ...

Page 1 of 1