From: David ‘Bombe’ Roden Date: Tue, 30 Sep 2014 16:28:56 +0000 (+0200) Subject: Add unit test for integer range predicate. X-Git-Tag: 0.9-rc1^2~3^2~82 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8a4eee0a6bd097d9c9ed13ac459343dfd35997fb;p=Sone.git Add unit test for integer range predicate. --- diff --git a/src/test/java/net/pterodactylus/sone/utils/IntegerRangePredicateTest.java b/src/test/java/net/pterodactylus/sone/utils/IntegerRangePredicateTest.java new file mode 100644 index 0000000..b2d078e --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/utils/IntegerRangePredicateTest.java @@ -0,0 +1,55 @@ +package net.pterodactylus.sone.utils; + +import static net.pterodactylus.sone.utils.IntegerRangePredicate.range; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import net.pterodactylus.sone.TestUtil; + +import org.junit.Test; + +/** + * Unit test for {@link IntegerRangePredicate}. + * + * @author David ‘Bombe’ Roden + */ +public class IntegerRangePredicateTest { + + private final IntegerRangePredicate predicate = + new IntegerRangePredicate(-50, 50); + + @Test + public void predicateMatchesNumberWithinBounds() { + assertThat(predicate.apply(17), is(true)); + } + + @Test + public void predicateMatchesLowerBoundary() { + assertThat(predicate.apply(-50), is(true)); + } + + @Test + public void predicateDoesNotMatchOneBelowLowerBoundary() { + assertThat(predicate.apply(-51), is(false)); + } + + @Test + public void predicateMatchesUpperBoundary() { + assertThat(predicate.apply(50), is(true)); + } + + @Test + public void predicateDoesNotMatchesOneAboveUpperBoundary() { + assertThat(predicate.apply(51), is(false)); + } + + @Test + public void staticCreatorMethodCreatesPredicate() { + IntegerRangePredicate predicate = range(-50, 50); + assertThat(TestUtil.getPrivateField(predicate, "lowerBound"), + is(-50)); + assertThat(TestUtil.getPrivateField(predicate, "upperBound"), + is(50)); + } + +}