Last active
June 12, 2019 19:21
-
-
Save jbleduigou/bf8556768ee49774ae779820407ae456 to your computer and use it in GitHub Desktop.
MatcherV3
This file contains 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
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 BeerWithAlcoholByVolume extends TypeSafeMatcher<Beer> { | |
private final Double alcoholByVolume; | |
BeerWithAlcoholByVolume(Double alcoholByVolume) { | |
this.alcoholByVolume = alcoholByVolume; | |
} | |
@Override | |
protected boolean matchesSafely(Beer beer) { | |
return Objects.equals(beer.getAlcoholByVolume(), alcoholByVolume); | |
} | |
@Override | |
public void describeTo(Description description) { | |
description.appendText("beer with alcoholByVolume ").appendValue(alcoholByVolume); | |
} | |
@Override | |
protected void describeMismatchSafely(Beer item, Description mismatchDescription) { | |
mismatchDescription.appendText("alcoholByVolume was "); | |
mismatchDescription.appendValue(item.getAlcoholByVolume()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment