Skip to content

Instantly share code, notes, and snippets.

@upkarlidder
Created December 27, 2016 23:15
Show Gist options
  • Save upkarlidder/a2c7c2e17c62e0aff1248432dee2a2ee to your computer and use it in GitHub Desktop.
Save upkarlidder/a2c7c2e17c62e0aff1248432dee2a2ee to your computer and use it in GitHub Desktop.
public static Matcher<List<Book>> containsTitle(final String title){
return new BaseMatcher<List<Book>>() {
@Override
public boolean matches(Object item) {
List<Book> books = (List<Book>) item;
List<Book> booksFiltered = books.stream()
.filter(b -> b.getTitle().equalsIgnoreCase(title))
.collect(Collectors.toList());
return !booksFiltered.isEmpty();
}
@Override
public void describeTo(Description description) {
description.appendText("The books list does not contain ").appendText(title);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment