Extension of Mockito that provides easy to use matchers for Collections such as Lists, Sets,...
Simplify your unit tests from:
@Test
public void sendMessage() throws Exception {
User user = new User(mockWebService, USER_ID, PASSWORD);
ArgumentCaptor<List<String>> listArgumentCaptor = ArgumentCaptor.forClass(List.class);
String expectedMessage = "Test message";
user.sendMessage(expectedMessage);
verify(mockWebService).sendMessages(eq(user), listArgumentCaptor.capture());
List<String> messages = listArgumentCaptor.getValue();
String actualMessage = messages.get(0);
assertEquals(expectedMessage, actualMessage);
}
to:
@Test
public void customMatchers() throws Exception {
User user = new User(mockWebService, USER_ID, PASSWORD);
String expectedMessage = "Test message";
user.sendMessage(expectedMessage);
verify(mockWebService).sendMessages(listContains(expectedMessage));
}
verify(mock).someMethod(listContains(expectedObject));
verify(mock).someMethod(listContains(expectedObject, index));
verify(mock).someMethod(listContainsNull());
verify(mock).someMethod(listDoesNotContain(wrongObject));
verify(mock).someMethod(listDoesNotContain(wrongObject, index));
verify(mock).someMethod(listDoesNotContainNull());
verify(mock).someMethod(listOfSize(3));
verify(mock).someMethod(setContains(expectedObject));
- Add the Jitpack repository to your project:
repositories {
maven { url "https://jitpack.io" }
}
- Add a dependency on the library:
testCompile 'com.github.JeroenMols:MockitoCollectionMatchers:0.0.2'
- Add unit tests
- Add more matchers
- Support other collections
- Add CI
- Add code coverage
- Upload to JCenter