Skip to content

Instantly share code, notes, and snippets.

@jbleduigou
Last active June 12, 2019 19:19
Show Gist options
  • Save jbleduigou/c44b26801ac270f1381c72cf87460667 to your computer and use it in GitHub Desktop.
Save jbleduigou/c44b26801ac270f1381c72cf87460667 to your computer and use it in GitHub Desktop.
MatcherV2
package com.github.jbleduigou.beer.matchers;
import com.github.jbleduigou.beer.model.Beer;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import java.util.Objects;
class BeerWithName extends TypeSafeMatcher<Beer> {
private final String name;
BeerWithName(String name) {
this.name = name;
}
@Override
protected boolean matchesSafely(Beer beer) {
return Objects.equals(beer.getName(), name);
}
@Override
public void describeTo(Description description) {
description.appendText("beer with name ").appendValue(name);
}
@Override
protected void describeMismatchSafely(Beer item, Description mismatchDescription) {
mismatchDescription.appendText("name was ");
mismatchDescription.appendValue(item.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment