Skip to content

Instantly share code, notes, and snippets.

@zEvg
Created March 27, 2012 13:46
Show Gist options
  • Save zEvg/2216015 to your computer and use it in GitHub Desktop.
Save zEvg/2216015 to your computer and use it in GitHub Desktop.
inRange() hamcrest matcher
package ;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.junit.internal.matchers.TypeSafeMatcher;
public class InRange extends TypeSafeMatcher<Integer> {
private int lowerEdge = 0;
private int higherEdge = 0;
public InRange(int lowerEdge, int higherEdge) {
this.lowerEdge = lowerEdge;
this.higherEdge = higherEdge;
}
@Override
public boolean matchesSafely(Integer item) {
return item >= lowerEdge && item < higherEdge;
}
@Override
public void describeTo(Description description) {
description.appendText("not in range");
}
@Factory
public static <T> Matcher<Integer> inRange(int lowerEdge, int higherEdge) {
return new InRange(lowerEdge, higherEdge);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment