Add unit test for integer range predicate.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 30 Sep 2014 16:28:56 +0000 (18:28 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 30 Sep 2014 16:28:56 +0000 (18:28 +0200)
src/test/java/net/pterodactylus/sone/utils/IntegerRangePredicateTest.java [new file with mode: 0644]

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 (file)
index 0000000..b2d078e
--- /dev/null
@@ -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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+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.<Integer>getPrivateField(predicate, "lowerBound"),
+                               is(-50));
+               assertThat(TestUtil.<Integer>getPrivateField(predicate, "upperBound"),
+                               is(50));
+       }
+
+}