From c7fc724f235f4a0f8611dfdedb412b78e3d923fe Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 21 Oct 2024 10:03:04 -0400 Subject: [PATCH] Only use static imports for JUnit --- .../collections4/CollectionUtilsTest.java | 6 +- .../collections4/IterableUtilsTest.java | 10 +-- .../collections4/IteratorUtilsTest.java | 14 +-- .../collections4/PredicateUtilsTest.java | 86 +++++++++---------- .../functors/AllPredicateTest.java | 5 +- .../functors/ComparatorPredicateTest.java | 14 ++- .../functors/EqualPredicateTest.java | 13 ++- .../functors/NullPredicateTest.java | 5 +- .../collections4/map/LazySortedMapTest.java | 43 ++++------ 9 files changed, 90 insertions(+), 106 deletions(-) diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java index a8c578697..6dc10d321 100644 --- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections4; -import static org.apache.commons.collections4.functors.EqualPredicate.equalPredicate; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -54,6 +53,7 @@ import org.apache.commons.collections4.collection.SynchronizedCollection; import org.apache.commons.collections4.collection.TransformedCollection; import org.apache.commons.collections4.collection.UnmodifiableCollection; import org.apache.commons.collections4.functors.DefaultEquator; +import org.apache.commons.collections4.functors.EqualPredicate; import org.apache.commons.collections4.functors.InstanceofPredicate; import org.apache.commons.collections4.functors.UniquePredicate; import org.apache.commons.collections4.queue.CircularFifoQueue; @@ -250,10 +250,10 @@ public class CollectionUtilsTest extends MockTestCase { @Test @Deprecated public void find() { - Predicate testPredicate = equalPredicate((Number) 4); + Predicate testPredicate = EqualPredicate.equalPredicate((Number) 4); Integer test = CollectionUtils.find(collectionA, testPredicate); assertEquals(4, (int) test); - testPredicate = equalPredicate((Number) 45); + testPredicate = EqualPredicate.equalPredicate((Number) 45); test = CollectionUtils.find(collectionA, testPredicate); assertNull(test); assertNull(CollectionUtils.find(null, testPredicate)); diff --git a/src/test/java/org/apache/commons/collections4/IterableUtilsTest.java b/src/test/java/org/apache/commons/collections4/IterableUtilsTest.java index b2b394bbe..7a3c79304 100644 --- a/src/test/java/org/apache/commons/collections4/IterableUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/IterableUtilsTest.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections4; -import static org.apache.commons.collections4.functors.EqualPredicate.equalPredicate; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -40,6 +39,7 @@ import java.util.List; import java.util.Set; import org.apache.commons.collections4.bag.HashBag; +import org.apache.commons.collections4.functors.EqualPredicate; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -302,10 +302,10 @@ public class IterableUtilsTest { @Test public void testFind() { - Predicate testPredicate = equalPredicate(4); + Predicate testPredicate = EqualPredicate.equalPredicate(4); Integer test = IterableUtils.find(iterableA, testPredicate); assertEquals(4, (int) test); - testPredicate = equalPredicate(45); + testPredicate = EqualPredicate.equalPredicate(45); test = IterableUtils.find(iterableA, testPredicate); assertNull(test); assertNull(IterableUtils.find(null, testPredicate)); @@ -457,10 +457,10 @@ public class IterableUtilsTest { @Test public void testIndexOf() { - Predicate testPredicate = equalPredicate((Number) 4); + Predicate testPredicate = EqualPredicate.equalPredicate((Number) 4); int index = IterableUtils.indexOf(iterableA, testPredicate); assertEquals(6, index); - testPredicate = equalPredicate((Number) 45); + testPredicate = EqualPredicate.equalPredicate((Number) 45); index = IterableUtils.indexOf(iterableA, testPredicate); assertEquals(-1, index); assertEquals(-1, IterableUtils.indexOf(null, testPredicate)); diff --git a/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java b/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java index ae9a80c2a..167b3e5e3 100644 --- a/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java @@ -16,8 +16,6 @@ */ package org.apache.commons.collections4; -import static org.apache.commons.collections4.functors.EqualPredicate.equalPredicate; -import static org.apache.commons.collections4.functors.TruePredicate.INSTANCE; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; @@ -46,6 +44,8 @@ import java.util.NoSuchElementException; import java.util.Set; import java.util.Vector; +import org.apache.commons.collections4.functors.EqualPredicate; +import org.apache.commons.collections4.functors.TruePredicate; import org.apache.commons.collections4.iterators.ArrayIterator; import org.apache.commons.collections4.iterators.EmptyIterator; import org.apache.commons.collections4.iterators.EmptyListIterator; @@ -725,7 +725,7 @@ public class IteratorUtilsTest { public void testFilteredListIterator() { final List arrayList = new ArrayList(); arrayList.add("test"); - final Predicate predicate = INSTANCE; + final Predicate predicate = TruePredicate.INSTANCE; assertTrue(IteratorUtils.filteredListIterator(arrayList.listIterator(), predicate) instanceof ListIterator, "create instance fail"); assertAll( @@ -736,10 +736,10 @@ public class IteratorUtilsTest { @Test public void testFind() { - Predicate testPredicate = equalPredicate((Number) 4); + Predicate testPredicate = EqualPredicate.equalPredicate((Number) 4); Integer test = IteratorUtils.find(iterableA.iterator(), testPredicate); assertEquals(4, (int) test); - testPredicate = equalPredicate((Number) 45); + testPredicate = EqualPredicate.equalPredicate((Number) 45); test = IteratorUtils.find(iterableA.iterator(), testPredicate); assertNull(test); assertNull(IteratorUtils.find(null, testPredicate)); @@ -861,10 +861,10 @@ public class IteratorUtilsTest { @Test public void testIndexOf() { - Predicate testPredicate = equalPredicate((Number) 4); + Predicate testPredicate = EqualPredicate.equalPredicate((Number) 4); int index = IteratorUtils.indexOf(iterableA.iterator(), testPredicate); assertEquals(6, index); - testPredicate = equalPredicate((Number) 45); + testPredicate = EqualPredicate.equalPredicate((Number) 45); index = IteratorUtils.indexOf(iterableA.iterator(), testPredicate); assertEquals(-1, index); assertEquals(-1, IteratorUtils.indexOf(null, testPredicate)); diff --git a/src/test/java/org/apache/commons/collections4/PredicateUtilsTest.java b/src/test/java/org/apache/commons/collections4/PredicateUtilsTest.java index eab191325..ba0c03935 100644 --- a/src/test/java/org/apache/commons/collections4/PredicateUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/PredicateUtilsTest.java @@ -16,8 +16,6 @@ */ package org.apache.commons.collections4; -import static org.apache.commons.collections4.functors.NullPredicate.nullPredicate; -import static org.apache.commons.collections4.functors.TruePredicate.truePredicate; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; @@ -51,16 +49,16 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @Override protected Predicate generatePredicate() { - return truePredicate(); //Just return something to satisfy super class. + return TruePredicate.truePredicate(); //Just return something to satisfy super class. } @Test @SuppressWarnings("unchecked") public void testAllPredicate() { assertPredicateTrue(AllPredicate.allPredicate(), null); - assertTrue(AllPredicate.allPredicate(truePredicate(), truePredicate(), truePredicate()).test(null)); - assertFalse(AllPredicate.allPredicate(truePredicate(), FalsePredicate.falsePredicate(), truePredicate()).test(null)); - assertFalse(AllPredicate.allPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), truePredicate()).test(null)); + assertTrue(AllPredicate.allPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()).test(null)); + assertFalse(AllPredicate.allPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).test(null)); + assertFalse(AllPredicate.allPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).test(null)); assertFalse(AllPredicate.allPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); final Collection> coll = new ArrayList<>(); coll.add(TruePredicate.truePredicate()); @@ -128,9 +126,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @Test public void testAndPredicate() { - assertTrue(PredicateUtils.andPredicate(truePredicate(), truePredicate()).evaluate(null)); - assertFalse(PredicateUtils.andPredicate(truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); - assertFalse(PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); + assertTrue(PredicateUtils.andPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); + assertFalse(PredicateUtils.andPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); + assertFalse(PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertFalse(PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); } @@ -144,9 +142,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest { public void testAnyPredicate() { assertPredicateFalse(PredicateUtils.anyPredicate(), null); - assertTrue(PredicateUtils.anyPredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null)); - assertTrue(PredicateUtils.anyPredicate(truePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); - assertTrue(PredicateUtils.anyPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); + assertTrue(PredicateUtils.anyPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); + assertTrue(PredicateUtils.anyPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); + assertTrue(PredicateUtils.anyPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertFalse(PredicateUtils.anyPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); final Collection> coll = new ArrayList<>(); coll.add(TruePredicate.truePredicate()); @@ -230,9 +228,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @Test public void testEitherPredicate() { - assertFalse(PredicateUtils.eitherPredicate(truePredicate(), truePredicate()).evaluate(null)); - assertTrue(PredicateUtils.eitherPredicate(truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); - assertTrue(PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); + assertFalse(PredicateUtils.eitherPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); + assertTrue(PredicateUtils.eitherPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); + assertTrue(PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertFalse(PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); } @@ -263,7 +261,7 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @Test public void testIdentityPredicate() { - assertSame(nullPredicate(), PredicateUtils.identityPredicate(null)); + assertSame(NullPredicate.nullPredicate(), PredicateUtils.identityPredicate(null)); assertNotNull(PredicateUtils.identityPredicate(6)); assertFalse(PredicateUtils.identityPredicate(6).evaluate(null)); assertFalse(PredicateUtils.identityPredicate(6).evaluate(cObject)); @@ -343,9 +341,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @Test public void testNeitherPredicate() { - assertFalse(PredicateUtils.neitherPredicate(truePredicate(), truePredicate()).evaluate(null)); - assertFalse(PredicateUtils.neitherPredicate(truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); - assertFalse(PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); + assertFalse(PredicateUtils.neitherPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); + assertFalse(PredicateUtils.neitherPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); + assertFalse(PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertTrue(PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); } @@ -358,9 +356,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @SuppressWarnings("unchecked") public void testNonePredicate() { assertPredicateTrue(PredicateUtils.nonePredicate(), null); - assertFalse(PredicateUtils.nonePredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null)); - assertFalse(PredicateUtils.nonePredicate(truePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); - assertFalse(PredicateUtils.nonePredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); + assertFalse(PredicateUtils.nonePredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); + assertFalse(PredicateUtils.nonePredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); + assertFalse(PredicateUtils.nonePredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertTrue(PredicateUtils.nonePredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); final Collection> coll = new ArrayList<>(); coll.add(TruePredicate.truePredicate()); @@ -430,10 +428,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @Test public void testNotPredicate() { assertNotNull(PredicateUtils.notPredicate(TruePredicate.truePredicate())); - assertFalse(PredicateUtils.notPredicate(truePredicate()).evaluate(null)); - assertFalse(PredicateUtils.notPredicate(truePredicate()).evaluate(cObject)); - assertFalse(PredicateUtils.notPredicate(truePredicate()).evaluate(cString)); - assertFalse(PredicateUtils.notPredicate(truePredicate()).evaluate(cInteger)); + assertFalse(PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(null)); + assertFalse(PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cObject)); + assertFalse(PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cString)); + assertFalse(PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cInteger)); } @Test @@ -443,7 +441,7 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @Test public void testNullIsExceptionPredicate() { - assertTrue(PredicateUtils.nullIsExceptionPredicate(truePredicate()).evaluate(new Object())); + assertTrue(PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(new Object())); assertThrows(FunctorException.class, () -> PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(null)); } @@ -454,8 +452,8 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @Test public void testNullIsFalsePredicate() { - assertFalse(PredicateUtils.nullIsFalsePredicate(truePredicate()).evaluate(null)); - assertTrue(PredicateUtils.nullIsFalsePredicate(truePredicate()).evaluate(new Object())); + assertFalse(PredicateUtils.nullIsFalsePredicate(TruePredicate.truePredicate()).evaluate(null)); + assertTrue(PredicateUtils.nullIsFalsePredicate(TruePredicate.truePredicate()).evaluate(new Object())); assertFalse(PredicateUtils.nullIsFalsePredicate(FalsePredicate.falsePredicate()).evaluate(new Object())); } @@ -466,8 +464,8 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @Test public void testNullIsTruePredicate() { - assertTrue(PredicateUtils.nullIsTruePredicate(truePredicate()).evaluate(null)); - assertTrue(PredicateUtils.nullIsTruePredicate(truePredicate()).evaluate(new Object())); + assertTrue(PredicateUtils.nullIsTruePredicate(TruePredicate.truePredicate()).evaluate(null)); + assertTrue(PredicateUtils.nullIsTruePredicate(TruePredicate.truePredicate()).evaluate(new Object())); assertFalse(PredicateUtils.nullIsTruePredicate(FalsePredicate.falsePredicate()).evaluate(new Object())); } @@ -480,11 +478,11 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @SuppressWarnings("unchecked") public void testOnePredicate() { assertPredicateFalse(PredicateUtils.onePredicate((Predicate[]) new Predicate[] {}), null); - assertFalse(PredicateUtils.onePredicate(truePredicate(), truePredicate(), truePredicate()).evaluate(null)); - assertFalse(PredicateUtils.onePredicate(truePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); - assertTrue(PredicateUtils.onePredicate(truePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); - assertTrue(PredicateUtils.onePredicate(FalsePredicate.falsePredicate(), truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); - assertTrue(PredicateUtils.onePredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); + assertFalse(PredicateUtils.onePredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); + assertFalse(PredicateUtils.onePredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); + assertTrue(PredicateUtils.onePredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); + assertTrue(PredicateUtils.onePredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); + assertTrue(PredicateUtils.onePredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertFalse(PredicateUtils.onePredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); final Collection> coll = new ArrayList<>(); coll.add(TruePredicate.truePredicate()); @@ -550,9 +548,9 @@ public class PredicateUtilsTest extends AbstractPredicateTest { @Test public void testOrPredicate() { - assertTrue(PredicateUtils.orPredicate(truePredicate(), truePredicate()).evaluate(null)); - assertTrue(PredicateUtils.orPredicate(truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); - assertTrue(PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), truePredicate()).evaluate(null)); + assertTrue(PredicateUtils.orPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); + assertTrue(PredicateUtils.orPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); + assertTrue(PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertFalse(PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); } @@ -587,7 +585,7 @@ public class PredicateUtilsTest extends AbstractPredicateTest { public void testTransformedPredicate() { assertTrue(PredicateUtils.transformedPredicate( TransformerUtils.nopTransformer(), - truePredicate()).evaluate(new Object())); + TruePredicate.truePredicate()).evaluate(new Object())); final Map map = new HashMap<>(); map.put(Boolean.TRUE, "Hello"); @@ -603,10 +601,10 @@ public class PredicateUtilsTest extends AbstractPredicateTest { public void testTruePredicate() { assertNotNull(TruePredicate.truePredicate()); assertSame(TruePredicate.truePredicate(), TruePredicate.truePredicate()); - assertTrue(truePredicate().evaluate(null)); - assertTrue(truePredicate().evaluate(cObject)); - assertTrue(truePredicate().evaluate(cString)); - assertTrue(truePredicate().evaluate(cInteger)); + assertTrue(TruePredicate.truePredicate().evaluate(null)); + assertTrue(TruePredicate.truePredicate().evaluate(cObject)); + assertTrue(TruePredicate.truePredicate().evaluate(cString)); + assertTrue(TruePredicate.truePredicate().evaluate(cInteger)); } @Test diff --git a/src/test/java/org/apache/commons/collections4/functors/AllPredicateTest.java b/src/test/java/org/apache/commons/collections4/functors/AllPredicateTest.java index 3025123cc..703ec1360 100644 --- a/src/test/java/org/apache/commons/collections4/functors/AllPredicateTest.java +++ b/src/test/java/org/apache/commons/collections4/functors/AllPredicateTest.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections4.functors; -import static org.apache.commons.collections4.functors.AllPredicate.allPredicate; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -93,7 +92,7 @@ public class AllPredicateTest extends AbstractAnyAllOnePredicateTest { // use the constructor directly, as getInstance() returns the original predicate when passed // an array of size one. final Predicate predicate = createMockPredicate(false); - assertFalse(allPredicate(predicate).test(getTestValue()), "single false predicate evaluated to true"); + assertFalse(AllPredicate.allPredicate(predicate).test(getTestValue()), "single false predicate evaluated to true"); } /** @@ -105,7 +104,7 @@ public class AllPredicateTest extends AbstractAnyAllOnePredicateTest { // use the constructor directly, as getInstance() returns the original predicate when passed // an array of size one. final Predicate predicate = createMockPredicate(true); - assertTrue(allPredicate(predicate).test(getTestValue()), "single true predicate evaluated to false"); + assertTrue(AllPredicate.allPredicate(predicate).test(getTestValue()), "single true predicate evaluated to false"); } /** diff --git a/src/test/java/org/apache/commons/collections4/functors/ComparatorPredicateTest.java b/src/test/java/org/apache/commons/collections4/functors/ComparatorPredicateTest.java index 8a30f23b8..72ad209d8 100644 --- a/src/test/java/org/apache/commons/collections4/functors/ComparatorPredicateTest.java +++ b/src/test/java/org/apache/commons/collections4/functors/ComparatorPredicateTest.java @@ -16,8 +16,6 @@ */ package org.apache.commons.collections4.functors; -import static org.apache.commons.collections4.functors.ComparatorPredicate.comparatorPredicate; - import java.util.Comparator; import org.apache.commons.collections4.Predicate; @@ -34,13 +32,13 @@ public class ComparatorPredicateTest extends AbstractPredicateTest { @Override protected Predicate generatePredicate() { - return comparatorPredicate(Integer.valueOf(10), new TestComparator<>()); + return ComparatorPredicate.comparatorPredicate(Integer.valueOf(10), new TestComparator<>()); } @Test public void testCompareEquals() { final Integer value = Integer.valueOf(10); - final Predicate p = comparatorPredicate(value, new TestComparator<>()); + final Predicate p = ComparatorPredicate.comparatorPredicate(value, new TestComparator<>()); assertPredicateFalse(p, Integer.valueOf(value.intValue() - 1)); assertPredicateTrue(p, Integer.valueOf(value.intValue())); assertPredicateFalse(p, Integer.valueOf(value.intValue() + 1)); @@ -49,7 +47,7 @@ public class ComparatorPredicateTest extends AbstractPredicateTest { @Test public void testCompareGreater() { final Integer value = Integer.valueOf(10); - final Predicate p = comparatorPredicate(value, new TestComparator<>(), Criterion.GREATER); + final Predicate p = ComparatorPredicate.comparatorPredicate(value, new TestComparator<>(), Criterion.GREATER); assertPredicateTrue(p, Integer.valueOf(value.intValue() - 1)); assertPredicateFalse(p, Integer.valueOf(value.intValue())); assertPredicateFalse(p, Integer.valueOf(value.intValue() + 1)); @@ -58,7 +56,7 @@ public class ComparatorPredicateTest extends AbstractPredicateTest { @Test public void testCompareGreaterOrEqual() { final Integer value = Integer.valueOf(10); - final Predicate p = comparatorPredicate(value, new TestComparator<>(), Criterion.GREATER_OR_EQUAL); + final Predicate p = ComparatorPredicate.comparatorPredicate(value, new TestComparator<>(), Criterion.GREATER_OR_EQUAL); assertPredicateTrue(p, Integer.valueOf(value.intValue() - 1)); assertPredicateTrue(p, Integer.valueOf(value.intValue())); assertPredicateFalse(p, Integer.valueOf(value.intValue() + 1)); @@ -67,7 +65,7 @@ public class ComparatorPredicateTest extends AbstractPredicateTest { @Test public void testCompareLess() { final Integer value = Integer.valueOf(10); - final Predicate p = comparatorPredicate(value, new TestComparator<>(), Criterion.LESS); + final Predicate p = ComparatorPredicate.comparatorPredicate(value, new TestComparator<>(), Criterion.LESS); assertPredicateFalse(p, Integer.valueOf(value.intValue() - 1)); assertPredicateFalse(p, Integer.valueOf(value.intValue())); assertPredicateTrue(p, Integer.valueOf(value.intValue() + 1)); @@ -76,7 +74,7 @@ public class ComparatorPredicateTest extends AbstractPredicateTest { @Test public void testCompareLessOrEqual() { final Integer value = Integer.valueOf(10); - final Predicate p = comparatorPredicate(value, new TestComparator<>(), Criterion.LESS_OR_EQUAL); + final Predicate p = ComparatorPredicate.comparatorPredicate(value, new TestComparator<>(), Criterion.LESS_OR_EQUAL); assertPredicateFalse(p, Integer.valueOf(value.intValue() - 1)); assertPredicateTrue(p, Integer.valueOf(value.intValue())); assertPredicateTrue(p, Integer.valueOf(value.intValue() + 1)); diff --git a/src/test/java/org/apache/commons/collections4/functors/EqualPredicateTest.java b/src/test/java/org/apache/commons/collections4/functors/EqualPredicateTest.java index be2c49b3b..990d7e37b 100644 --- a/src/test/java/org/apache/commons/collections4/functors/EqualPredicateTest.java +++ b/src/test/java/org/apache/commons/collections4/functors/EqualPredicateTest.java @@ -16,8 +16,6 @@ */ package org.apache.commons.collections4.functors; -import static org.apache.commons.collections4.functors.EqualPredicate.equalPredicate; -import static org.apache.commons.collections4.functors.NullPredicate.nullPredicate; import static org.junit.jupiter.api.Assertions.assertSame; import org.apache.commons.collections4.Predicate; @@ -36,31 +34,32 @@ public class EqualPredicateTest extends AbstractPredicateTest { return b; } } + private static final EqualsTestObject FALSE_OBJECT = new EqualsTestObject(false); private static final EqualsTestObject TRUE_OBJECT = new EqualsTestObject(true); @Override protected Predicate generatePredicate() { - return equalPredicate(null); + return EqualPredicate.equalPredicate(null); } @Test public void testNullArgumentEqualsNullPredicate() throws Exception { - assertSame(nullPredicate(), equalPredicate(null)); + assertSame(NullPredicate.nullPredicate(), EqualPredicate.equalPredicate(null)); } @Test public void testObjectFactoryUsesEqualsForTest() throws Exception { - final Predicate predicate = equalPredicate(FALSE_OBJECT); + final Predicate predicate = EqualPredicate.equalPredicate(FALSE_OBJECT); assertPredicateFalse(predicate, FALSE_OBJECT); - assertPredicateTrue(equalPredicate(TRUE_OBJECT), TRUE_OBJECT); + assertPredicateTrue(EqualPredicate.equalPredicate(TRUE_OBJECT), TRUE_OBJECT); } @SuppressWarnings("boxing") @Test public void testPredicateTypeCanBeSuperClassOfObject() throws Exception { - final Predicate predicate = equalPredicate((Number) 4); + final Predicate predicate = EqualPredicate.equalPredicate((Number) 4); assertPredicateTrue(predicate, 4); } } diff --git a/src/test/java/org/apache/commons/collections4/functors/NullPredicateTest.java b/src/test/java/org/apache/commons/collections4/functors/NullPredicateTest.java index 8c90e7f0a..998435f22 100644 --- a/src/test/java/org/apache/commons/collections4/functors/NullPredicateTest.java +++ b/src/test/java/org/apache/commons/collections4/functors/NullPredicateTest.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections4.functors; -import static org.apache.commons.collections4.functors.NullPredicate.nullPredicate; import static org.junit.jupiter.api.Assertions.assertSame; import org.apache.commons.collections4.Predicate; @@ -25,7 +24,7 @@ import org.junit.jupiter.api.Test; public class NullPredicateTest extends AbstractPredicateTest { @Override protected Predicate generatePredicate() { - return nullPredicate(); + return NullPredicate.nullPredicate(); } @Test @@ -37,6 +36,6 @@ public class NullPredicateTest extends AbstractPredicateTest { @Test public void testNullPredicate() { assertSame(NullPredicate.nullPredicate(), NullPredicate.nullPredicate()); - assertPredicateTrue(nullPredicate(), null); + assertPredicateTrue(NullPredicate.nullPredicate(), null); } } diff --git a/src/test/java/org/apache/commons/collections4/map/LazySortedMapTest.java b/src/test/java/org/apache/commons/collections4/map/LazySortedMapTest.java index f718a4c85..c20001437 100644 --- a/src/test/java/org/apache/commons/collections4/map/LazySortedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LazySortedMapTest.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections4.map; -import static org.apache.commons.collections4.map.LazySortedMap.lazySortedMap; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; @@ -37,8 +36,7 @@ import org.apache.commons.collections4.TransformerUtils; import org.junit.jupiter.api.Test; /** - * Extension of {@link LazyMapTest} for exercising the - * {@link LazySortedMap} implementation. + * Extension of {@link LazyMapTest} for exercising the {@link LazySortedMap} implementation. * * @param the key type. * @param the value type. @@ -80,19 +78,19 @@ public class LazySortedMapTest extends AbstractSortedMapTest { @Override public SortedMap makeObject() { - return lazySortedMap(new TreeMap<>(), FactoryUtils.nullFactory()); + return LazySortedMap.lazySortedMap(new TreeMap<>(), FactoryUtils.nullFactory()); } @Override @Test public void testMapGet() { - Map map = lazySortedMap(new TreeMap<>(), oneFactory); + Map map = LazySortedMap.lazySortedMap(new TreeMap<>(), oneFactory); assertEquals(0, map.size()); final Number i1 = map.get(5); assertEquals(1, i1); assertEquals(1, map.size()); - map = lazySortedMap(new TreeMap<>(), FactoryUtils.nullFactory()); + map = LazySortedMap.lazySortedMap(new TreeMap<>(), FactoryUtils.nullFactory()); final Number o = map.get(5); assertNull(o); assertEquals(1, map.size()); @@ -101,18 +99,15 @@ public class LazySortedMapTest extends AbstractSortedMapTest { @Test public void testReverseSortOrder() { - final SortedMap map = lazySortedMap(new ConcurrentSkipListMap<>(reverseStringComparator), oneFactory); + final SortedMap map = LazySortedMap.lazySortedMap(new ConcurrentSkipListMap<>(reverseStringComparator), oneFactory); map.put("A", 5); map.get("B"); // Entry with value "One" created map.put("C", 8); assertEquals("A", map.lastKey(), "Last key should be A"); assertEquals("C", map.firstKey(), "First key should be C"); - assertEquals("B", map.tailMap("B").firstKey(), - "First key in tail map should be B"); - assertEquals("B", map.headMap("A").lastKey(), - "Last key in head map should be B"); - assertEquals("B", map.subMap("C", "A").lastKey(), - "Last key in submap should be B"); + assertEquals("B", map.tailMap("B").firstKey(), "First key in tail map should be B"); + assertEquals("B", map.headMap("A").lastKey(), "Last key in head map should be B"); + assertEquals("B", map.subMap("C", "A").lastKey(), "Last key in submap should be B"); final Comparator c = map.comparator(); assertSame(c, reverseStringComparator, "natural order, so comparator should be null"); @@ -120,18 +115,15 @@ public class LazySortedMapTest extends AbstractSortedMapTest { @Test public void testSortOrder() { - final SortedMap map = lazySortedMap(new TreeMap<>(), oneFactory); - map.put("A", 5); + final SortedMap map = LazySortedMap.lazySortedMap(new TreeMap<>(), oneFactory); + map.put("A", 5); map.get("B"); // Entry with value "One" created map.put("C", 8); assertEquals("A", map.firstKey(), "First key should be A"); assertEquals("C", map.lastKey(), "Last key should be C"); - assertEquals("B", map.tailMap("B").firstKey(), - "First key in tail map should be B"); - assertEquals("B", map.headMap("C").lastKey(), - "Last key in head map should be B"); - assertEquals("B", map.subMap("A", "C").lastKey(), - "Last key in submap should be B"); + assertEquals("B", map.tailMap("B").firstKey(), "First key in tail map should be B"); + assertEquals("B", map.headMap("C").lastKey(), "Last key in head map should be B"); + assertEquals("B", map.subMap("A", "C").lastKey(), "Last key in submap should be B"); final Comparator c = map.comparator(); assertNull(c, "natural order, so comparator should be null"); @@ -140,14 +132,13 @@ public class LazySortedMapTest extends AbstractSortedMapTest { @Test public void testTransformerDecorate() { final Transformer transformer = TransformerUtils.asTransformer(oneFactory); - final SortedMap map = lazySortedMap(new TreeMap<>(), transformer); + final SortedMap map = LazySortedMap.lazySortedMap(new TreeMap<>(), transformer); assertInstanceOf(LazySortedMap.class, map); assertAll( - () -> assertThrows(NullPointerException.class, () -> lazySortedMap(new TreeMap<>(), (Transformer) null), + () -> assertThrows(NullPointerException.class, () -> LazySortedMap.lazySortedMap(new TreeMap<>(), (Transformer) null), "Expecting NullPointerException for null transformer"), - () -> assertThrows(NullPointerException.class, () -> lazySortedMap((SortedMap) null, transformer), - "Expecting NullPointerException for null map") - ); + () -> assertThrows(NullPointerException.class, () -> LazySortedMap.lazySortedMap((SortedMap) null, transformer), + "Expecting NullPointerException for null map")); } // public void testCreate() throws Exception {