Last active
June 5, 2018 20:33
-
-
Save mingliangguo/404f37a25bd8a3752b5c786334af9683 to your computer and use it in GitHub Desktop.
mockito #test #mock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| when(someMock.someMethod()).thenAnswer(new Answer() { | |
| private int count = 0; | |
| public Object answer(InvocationOnMock invocation) { | |
| if (count++ == 1) | |
| return 1; | |
| return 2; | |
| } | |
| }); | |
| # use captor to capture function arguments | |
| ArgumentCaptor<HashSet> captor = ArgumentCaptor.forClass(HashSet.class); | |
| verify(obj).update(anyString(), captor.capture()); | |
| assertEquals("the captured HashSet should be empty.", 0, captor.getValue().size()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment