Created
March 27, 2012 13:46
-
-
Save zEvg/2216015 to your computer and use it in GitHub Desktop.
inRange() hamcrest matcher
This file contains hidden or 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 ; | |
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