From 8a4eee0a6bd097d9c9ed13ac459343dfd35997fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 30 Sep 2014 18:28:56 +0200 Subject: [PATCH] Add unit test for integer range predicate. --- .../sone/utils/IntegerRangePredicateTest.java | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/test/java/net/pterodactylus/sone/utils/IntegerRangePredicateTest.java 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)); + } + +} -- 2.7.4