From 0fb2e4be3ce2066ecc5caf03f5ef4af680520a52 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 7 Apr 2020 10:20:19 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=94=A5=20Remove=20integer=20range=20predic?= =?utf8?q?ate?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../sone/utils/IntegerRangePredicate.java | 64 ---------------------- .../sone/utils/IntegerRangePredicateTest.java | 53 ------------------ 2 files changed, 117 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sone/utils/IntegerRangePredicate.java delete mode 100644 src/test/java/net/pterodactylus/sone/utils/IntegerRangePredicateTest.java diff --git a/src/main/java/net/pterodactylus/sone/utils/IntegerRangePredicate.java b/src/main/java/net/pterodactylus/sone/utils/IntegerRangePredicate.java deleted file mode 100644 index 3a631cf..0000000 --- a/src/main/java/net/pterodactylus/sone/utils/IntegerRangePredicate.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Sone - IntegerRangePredicate.java - Copyright © 2013–2020 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.utils; - -import com.google.common.base.Predicate; - -/** - * {@link Predicate} that verifies that an {@link Integer} value is not - * {@code null} and is between a lower and an upper bound. Both bounds are - * inclusive. - */ -public class IntegerRangePredicate implements Predicate { - - /** The lower bound. */ - private final int lowerBound; - - /** The upper bound. */ - private final int upperBound; - - /** - * Creates a new integer range predicate. - * - * @param lowerBound - * The lower bound - * @param upperBound - * The upper bound - */ - public IntegerRangePredicate(int lowerBound, int upperBound) { - this.lowerBound = lowerBound; - this.upperBound = upperBound; - } - - // - // PREDICATE METHODS - // - - /** - * {@inheritDoc} - */ - @Override - public boolean apply(Integer value) { - return (value != null) && (value >= lowerBound) && (value <= upperBound); - } - - public static IntegerRangePredicate range(int lowerBound, int upperBound) { - return new IntegerRangePredicate(lowerBound, upperBound); - } - -} diff --git a/src/test/java/net/pterodactylus/sone/utils/IntegerRangePredicateTest.java b/src/test/java/net/pterodactylus/sone/utils/IntegerRangePredicateTest.java deleted file mode 100644 index 2bea3f7..0000000 --- a/src/test/java/net/pterodactylus/sone/utils/IntegerRangePredicateTest.java +++ /dev/null @@ -1,53 +0,0 @@ -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.test.TestUtil; - -import org.junit.Test; - -/** - * Unit test for {@link IntegerRangePredicate}. - */ -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