Skip to content

Instantly share code, notes, and snippets.

@mingliangguo
Last active June 5, 2018 20:33
Show Gist options
  • Select an option

  • Save mingliangguo/404f37a25bd8a3752b5c786334af9683 to your computer and use it in GitHub Desktop.

Select an option

Save mingliangguo/404f37a25bd8a3752b5c786334af9683 to your computer and use it in GitHub Desktop.
mockito #test #mock
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