From 71aec3377df3efa7964008d9b8a49a46265de5c3 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Wed, 21 Apr 2021 07:08:44 +0200 Subject: [PATCH 1/2] [COLLECTIONS-793] Simplify Assertion. --- .../collections4/AbstractObjectTest.java | 6 +- .../commons/collections4/ArrayStackTest.java | 2 +- .../collections4/CollectionUtilsTest.java | 12 +- .../collections4/EnumerationUtilsTest.java | 2 +- .../bidimap/AbstractOrderedBidiMapTest.java | 20 +- .../collection/AbstractCollectionTest.java | 8 +- .../collection/CompositeCollectionTest.java | 18 +- .../iterators/AbstractIteratorTest.java | 4 +- .../iterators/AbstractListIteratorTest.java | 14 +- .../iterators/AbstractMapIteratorTest.java | 22 +- .../AbstractOrderedMapIteratorTest.java | 14 +- .../iterators/ArrayIterator2Test.java | 6 +- .../iterators/ArrayIteratorTest.java | 12 +- .../iterators/ArrayListIteratorTest.java | 11 +- .../iterators/CollatingIteratorTest.java | 10 +- .../iterators/FilterIteratorTest.java | 12 +- .../iterators/FilterListIteratorTest.java | 6 +- .../iterators/IteratorChainTest.java | 11 +- .../iterators/LazyIteratorChainTest.java | 11 +- .../iterators/ListIteratorWrapper2Test.java | 8 +- .../iterators/ListIteratorWrapperTest.java | 8 +- .../iterators/LoopingIteratorTest.java | 2 +- .../iterators/ObjectArrayIteratorTest.java | 6 +- .../ObjectArrayListIteratorTest.java | 11 +- .../iterators/ObjectGraphIteratorTest.java | 56 ++--- .../iterators/ReverseListIteratorTest.java | 32 +-- .../iterators/SingletonIterator2Test.java | 16 +- .../iterators/SingletonIteratorTest.java | 18 +- .../iterators/SingletonListIteratorTest.java | 32 ++- .../iterators/UniqueFilterIteratorTest.java | 5 +- .../iterators/UnmodifiableIteratorTest.java | 2 +- .../UnmodifiableMapIteratorTest.java | 2 +- .../UnmodifiableOrderedMapIteratorTest.java | 2 +- .../iterators/ZippingIteratorTest.java | 10 +- .../keyvalue/AbstractMapEntryTest.java | 28 +-- .../keyvalue/DefaultKeyValueTest.java | 30 +-- .../collections4/keyvalue/MultiKeyTest.java | 43 ++-- .../collections4/list/AbstractListTest.java | 38 ++- .../list/CursorableLinkedListTest.java | 190 +++++++-------- .../collections4/list/GrowthListTest.java | 6 +- .../collections4/list/PredicatedListTest.java | 10 +- .../list/TransformedListTest.java | 16 +- .../collections4/list/TreeListTest.java | 6 +- .../collections4/map/AbstractMapTest.java | 122 ++++------ .../map/AbstractOrderedMapTest.java | 20 +- .../collections4/map/DefaultedMapTest.java | 24 +- .../collections4/map/Flat3MapTest.java | 96 ++++---- .../commons/collections4/map/LRUMapTest.java | 48 ++-- .../commons/collections4/map/LazyMapTest.java | 2 +- .../collections4/map/LazySortedMapTest.java | 8 +- .../collections4/map/LinkedMapTest.java | 2 +- .../collections4/map/ListOrderedMap2Test.java | 2 +- .../collections4/map/ListOrderedMapTest.java | 2 +- .../collections4/map/MultiKeyMapTest.java | 216 +++++++++--------- .../collections4/map/MultiValueMapTest.java | 76 +++--- .../collections4/map/PredicatedMapTest.java | 10 +- .../map/PredicatedSortedMapTest.java | 16 +- .../map/ReferenceIdentityMapTest.java | 44 ++-- .../collections4/map/ReferenceMapTest.java | 14 +- .../collections4/map/SingletonMapTest.java | 6 +- .../collections4/map/StaticBucketMapTest.java | 10 +- .../collections4/map/TransformedMapTest.java | 14 +- .../map/TransformedSortedMapTest.java | 10 +- .../multimap/AbstractMultiValuedMapTest.java | 66 +++--- .../TransformedMultiValuedMapTest.java | 38 +-- .../multiset/AbstractMultiSetTest.java | 100 ++++---- .../multiset/PredicatedMultiSetTest.java | 7 +- .../properties/EmptyPropertiesTest.java | 13 +- .../queue/CircularFifoQueueTest.java | 30 +-- .../queue/TransformedQueueTest.java | 16 +- .../collections4/set/AbstractSetTest.java | 4 +- .../collections4/set/CompositeSetTest.java | 4 +- .../set/PredicatedNavigableSetTest.java | 14 +- .../collections4/set/PredicatedSetTest.java | 12 +- .../set/PredicatedSortedSetTest.java | 14 +- .../set/TransformedNavigableSetTest.java | 8 +- .../collections4/set/TransformedSetTest.java | 16 +- .../set/TransformedSortedSetTest.java | 8 +- .../set/UnmodifiableSortedSetTest.java | 2 +- .../splitmap/TransformedSplitMapTest.java | 2 +- 80 files changed, 907 insertions(+), 967 deletions(-) diff --git a/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java b/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java index 0c3ac4484..ba7f02d47 100644 --- a/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java +++ b/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java @@ -104,7 +104,7 @@ public abstract class AbstractObjectTest extends BulkTest { public void testEqualsNull() { final Object obj = makeObject(); - assertEquals(false, obj.equals(null)); // make sure this doesn't throw NPE either + assertFalse(obj.equals(null)); // make sure this doesn't throw NPE either } public void testObjectHashCodeEqualsSelfHashCode() { @@ -124,9 +124,7 @@ public abstract class AbstractObjectTest extends BulkTest { assertEquals( "[2] When two objects are equal, their hashCodes should be also.", obj1.hashCode(), obj2.hashCode()); - assertTrue( - "When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true", - obj2.equals(obj1)); + assertEquals("When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true", obj2, obj1); } } diff --git a/src/test/java/org/apache/commons/collections4/ArrayStackTest.java b/src/test/java/org/apache/commons/collections4/ArrayStackTest.java index d69d5e2b9..e96940ab5 100644 --- a/src/test/java/org/apache/commons/collections4/ArrayStackTest.java +++ b/src/test/java/org/apache/commons/collections4/ArrayStackTest.java @@ -66,7 +66,7 @@ public class ArrayStackTest extends AbstractArrayListTest { final ArrayStack stack = makeObject(); stack.push((E) "First Item"); - assertTrue("Stack is not empty", !stack.empty()); + assertFalse("Stack is not empty", stack.empty()); assertEquals("Stack size is one", 1, stack.size()); assertEquals("Top item is 'First Item'", "First Item", (String) stack.peek()); diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java index 98bfd370c..9f5e2010b 100644 --- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java @@ -311,12 +311,12 @@ public class CollectionUtilsTest extends MockTestCase { public void collect() { final Transformer transformer = TransformerUtils.constantTransformer(2L); Collection collection = CollectionUtils.collect(iterableA, transformer); - assertTrue(collection.size() == collectionA.size()); + assertEquals(collection.size(), collectionA.size()); assertCollectResult(collection); ArrayList list; list = CollectionUtils.collect(collectionA, transformer, new ArrayList()); - assertTrue(list.size() == collectionA.size()); + assertEquals(list.size(), collectionA.size()); assertCollectResult(list); Iterator iterator = null; @@ -324,12 +324,12 @@ public class CollectionUtilsTest extends MockTestCase { iterator = iterableA.iterator(); list = CollectionUtils.collect(iterator, transformer, list); - assertTrue(collection.size() == collectionA.size()); + assertEquals(collection.size(), collectionA.size()); assertCollectResult(collection); iterator = collectionA.iterator(); collection = CollectionUtils.collect(iterator, transformer); - assertTrue(collection.size() == collectionA.size()); + assertEquals(collection.size(), collectionA.size()); assertTrue(collection.contains(2L) && !collection.contains(1)); collection = CollectionUtils.collect((Iterator) null, (Transformer) null); assertTrue(collection.isEmpty()); @@ -2140,9 +2140,9 @@ public class CollectionUtilsTest extends MockTestCase { @Test public void testSizeIsEmpty_Map() { final Map map = new HashMap<>(); - assertEquals(true, CollectionUtils.sizeIsEmpty(map)); + assertTrue(CollectionUtils.sizeIsEmpty(map)); map.put("1", "a"); - assertEquals(false, CollectionUtils.sizeIsEmpty(map)); + assertFalse(CollectionUtils.sizeIsEmpty(map)); } // ----------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java b/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java index 687e54366..48975f09e 100644 --- a/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java @@ -57,7 +57,7 @@ public class EnumerationUtilsTest { } catch (final IndexOutOfBoundsException e) { // expected } - assertTrue(!en.hasMoreElements()); + assertFalse(en.hasMoreElements()); } @Test diff --git a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java index e4206cbb5..f662401eb 100644 --- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java +++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java @@ -75,13 +75,13 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe public void testNextKey() { resetEmpty(); OrderedBidiMap bidi = (OrderedBidiMap) map; - assertEquals(null, bidi.nextKey(getOtherKeys()[0])); + assertNull(bidi.nextKey(getOtherKeys()[0])); if (!isAllowNullKey()) { try { - assertEquals(null, bidi.nextKey(null)); // this is allowed too + assertNull(bidi.nextKey(null)); // this is allowed too } catch (final NullPointerException ex) {} } else { - assertEquals(null, bidi.nextKey(null)); + assertNull(bidi.nextKey(null)); } resetFull(); @@ -93,7 +93,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe assertEquals(confirmedObject, bidi.nextKey(confirmedLast)); confirmedLast = confirmedObject; } - assertEquals(null, bidi.nextKey(confirmedLast)); + assertNull(bidi.nextKey(confirmedLast)); if (!isAllowNullKey()) { try { @@ -101,20 +101,20 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe fail(); } catch (final NullPointerException ex) {} } else { - assertEquals(null, bidi.nextKey(null)); + assertNull(bidi.nextKey(null)); } } public void testPreviousKey() { resetEmpty(); OrderedBidiMap bidi = getMap(); - assertEquals(null, bidi.previousKey(getOtherKeys()[0])); + assertNull(bidi.previousKey(getOtherKeys()[0])); if (!isAllowNullKey()) { try { - assertEquals(null, bidi.previousKey(null)); // this is allowed too + assertNull(bidi.previousKey(null)); // this is allowed too } catch (final NullPointerException ex) {} } else { - assertEquals(null, bidi.previousKey(null)); + assertNull(bidi.previousKey(null)); } resetFull(); @@ -128,7 +128,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe assertEquals(confirmedObject, bidi.previousKey(confirmedLast)); confirmedLast = confirmedObject; } - assertEquals(null, bidi.previousKey(confirmedLast)); + assertNull(bidi.previousKey(confirmedLast)); if (!isAllowNullKey()) { try { @@ -136,7 +136,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe fail(); } catch (final NullPointerException ex) {} } else { - assertEquals(null, bidi.previousKey(null)); + assertNull(bidi.previousKey(null)); } } diff --git a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java index dfd809691..50983309f 100644 --- a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java @@ -851,7 +851,7 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { resetEmpty(); final E[] elements = getFullElements(); for (final E element : elements) { - assertTrue("Shouldn't remove nonexistent element", !getCollection().remove(element)); + assertFalse("Shouldn't remove nonexistent element", getCollection().remove(element)); verify(); } @@ -895,12 +895,10 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { } resetEmpty(); - assertTrue("Empty collection removeAll should return false for empty input", - !getCollection().removeAll(Collections.EMPTY_SET)); + assertFalse("Empty collection removeAll should return false for empty input", getCollection().removeAll(Collections.EMPTY_SET)); verify(); - assertTrue("Empty collection removeAll should return false for nonempty input", - !getCollection().removeAll(new ArrayList<>(getCollection()))); + assertFalse("Empty collection removeAll should return false for nonempty input", getCollection().removeAll(new ArrayList<>(getCollection()))); verify(); resetFull(); diff --git a/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java index a0e8a06e8..2309f36e9 100644 --- a/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java @@ -334,9 +334,9 @@ public class CompositeCollectionTest extends AbstractCollectionTest { final Collection removing = new ArrayList<>(one); c.addComposited(one, two); c.removeAll(removing); - assertTrue(!c.contains("1")); - assertTrue(!one.contains("1")); - assertTrue(!two.contains("1")); + assertFalse(c.contains("1")); + assertFalse(one.contains("1")); + assertFalse(two.contains("1")); c.removeAll(null); assertFalse(c.contains("1")); assertFalse(one.contains("1")); @@ -356,13 +356,13 @@ public class CompositeCollectionTest extends AbstractCollectionTest { final Predicate predicate = e -> e == "1"; c.addComposited(one, two); c.removeIf(predicate); - assertTrue(!c.contains("1")); - assertTrue(!one.contains("1")); - assertTrue(!two.contains("1")); + assertFalse(c.contains("1")); + assertFalse(one.contains("1")); + assertFalse(two.contains("1")); c.removeIf(null); - assertTrue(!c.contains("1")); - assertTrue(!one.contains("1")); - assertTrue(!two.contains("1")); + assertFalse(c.contains("1")); + assertFalse(one.contains("1")); + assertFalse(two.contains("1")); } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/apache/commons/collections4/iterators/AbstractIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/AbstractIteratorTest.java index e6c41c556..94963de1c 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/AbstractIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/AbstractIteratorTest.java @@ -105,7 +105,7 @@ public abstract class AbstractIteratorTest extends AbstractObjectTest { final Iterator it = makeEmptyIterator(); // hasNext() should return false - assertEquals("hasNext() should return false for empty iterators", false, it.hasNext()); + assertFalse("hasNext() should return false for empty iterators", it.hasNext()); // next() should throw a NoSuchElementException try { @@ -129,7 +129,7 @@ public abstract class AbstractIteratorTest extends AbstractObjectTest { final Iterator it = makeObject(); // hasNext() must be true (ensure makeFullIterator is correct!) - assertEquals("hasNext() should return true for at least one element", true, it.hasNext()); + assertTrue("hasNext() should return true for at least one element", it.hasNext()); // next() must not throw exception (ensure makeFullIterator is correct!) try { diff --git a/src/test/java/org/apache/commons/collections4/iterators/AbstractListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/AbstractListIteratorTest.java index 19dbae10f..5c1608b93 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/AbstractListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/AbstractListIteratorTest.java @@ -95,9 +95,9 @@ public abstract class AbstractListIteratorTest extends AbstractIteratorTest it = makeEmptyIterator(); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); assertEquals(0, it.nextIndex()); - assertEquals(false, it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals(-1, it.previousIndex()); // next() should throw a NoSuchElementException @@ -126,8 +126,8 @@ public abstract class AbstractListIteratorTest extends AbstractIteratorTest extends AbstractIteratorTest extends AbstractIteratorTest extends AbstractIteratorTest } final MapIterator it = makeEmptyIterator(); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); // next() should throw a NoSuchElementException try { @@ -161,9 +161,9 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest final MapIterator it = makeObject(); final Map map = getMap(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); final Set set = new HashSet<>(); while (it.hasNext()) { // getKey @@ -193,7 +193,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest final MapIterator it = makeObject(); final Map map = getMap(); final Map confirmed = getConfirmedMap(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); final K key = it.next(); final V value = it.getValue(); @@ -209,11 +209,11 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest assertSame("Key must not change after setValue", key, it.getKey()); assertSame("Value must be changed after setValue", newValue, it.getValue()); assertSame("setValue must return old value", value, old); - assertEquals("Map must contain key", true, map.containsKey(key)); + assertTrue("Map must contain key", map.containsKey(key)); // test against confirmed, as map may contain value twice assertEquals("Map must not contain old value", confirmed.containsValue(old), map.containsValue(old)); - assertEquals("Map must contain new value", true, map.containsValue(newValue)); + assertTrue("Map must contain new value", map.containsValue(newValue)); verify(); it.setValue(newValue); // same value - should be OK @@ -234,7 +234,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest final MapIterator it = makeObject(); final Map map = getMap(); final Map confirmed = getConfirmedMap(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); final K key = it.next(); if (!supportsRemove()) { @@ -248,7 +248,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest it.remove(); confirmed.remove(key); - assertEquals(false, map.containsKey(key)); + assertFalse(map.containsKey(key)); verify(); try { @@ -266,7 +266,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest final MapIterator it = makeObject(); final Map confirmed = getConfirmedMap(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); final K key = it.next(); it.setValue(newValue); @@ -288,7 +288,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest final MapIterator it = makeObject(); final Map confirmed = getConfirmedMap(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); final K key = it.next(); it.remove(); @@ -309,7 +309,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest final MapIterator it = makeObject(); final Map confirmed = getConfirmedMap(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); final K key = it.next(); it.remove(); diff --git a/src/test/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorTest.java index 9037e6c4c..80d6a57da 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorTest.java @@ -65,7 +65,7 @@ public abstract class AbstractOrderedMapIteratorTest extends AbstractMapIt super.testEmptyMapIterator(); final OrderedMapIterator it = makeEmptyIterator(); - assertEquals(false, it.hasPrevious()); + assertFalse(it.hasPrevious()); try { it.previous(); fail(); @@ -86,8 +86,8 @@ public abstract class AbstractOrderedMapIteratorTest extends AbstractMapIt final OrderedMapIterator it = makeObject(); final Map map = getMap(); - assertEquals(true, it.hasNext()); - assertEquals(false, it.hasPrevious()); + assertTrue(it.hasNext()); + assertFalse(it.hasPrevious()); final Set set = new HashSet<>(); while (it.hasNext()) { // getKey @@ -103,7 +103,7 @@ public abstract class AbstractOrderedMapIteratorTest extends AbstractMapIt } assertTrue("Value must be in map", map.containsValue(value)); - assertEquals(true, it.hasPrevious()); + assertTrue(it.hasPrevious()); verify(); } @@ -121,7 +121,7 @@ public abstract class AbstractOrderedMapIteratorTest extends AbstractMapIt } assertTrue("Value must be in map", map.containsValue(value)); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); verify(); } @@ -141,8 +141,8 @@ public abstract class AbstractOrderedMapIteratorTest extends AbstractMapIt assertEquals("keySet() not consistent", new ArrayList<>(map.keySet()), new ArrayList<>(map.keySet())); final Iterator it2 = map.keySet().iterator(); - assertEquals(true, it.hasNext()); - assertEquals(true, it2.hasNext()); + assertTrue(it.hasNext()); + assertTrue(it2.hasNext()); final List list = new ArrayList<>(); while (it.hasNext()) { final K key = it.next(); diff --git a/src/test/java/org/apache/commons/collections4/iterators/ArrayIterator2Test.java b/src/test/java/org/apache/commons/collections4/iterators/ArrayIterator2Test.java index e7acf4947..d1ae4898a 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ArrayIterator2Test.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ArrayIterator2Test.java @@ -67,14 +67,12 @@ public class ArrayIterator2Test extends AbstractIteratorTest { assertEquals("Iteration value is correct", testValue, iterValue); } - assertTrue("Iterator should now be empty", !iter.hasNext()); + assertFalse("Iterator should now be empty", iter.hasNext()); try { iter.next(); } catch (final Exception e) { - assertTrue( - "NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/ArrayIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ArrayIteratorTest.java index 74d51f18d..24b7a3d00 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ArrayIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ArrayIteratorTest.java @@ -19,6 +19,8 @@ package org.apache.commons.collections4.iterators; import java.util.Iterator; import java.util.NoSuchElementException; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * Tests the ArrayIterator to ensure that the next() method will actually * perform the iteration rather than the hasNext() method. @@ -56,15 +58,9 @@ public class ArrayIteratorTest extends AbstractIteratorTest { assertEquals("Iteration value is correct", testValue, iterValue); } - assertTrue("Iterator should now be empty", !iter.hasNext()); + assertFalse("Iterator should now be empty", iter.hasNext()); - try { - iter.next(); - } catch (final Exception e) { - assertTrue( - "NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); - } + assertThrows(NoSuchElementException.class, iter::next, "NoSuchElementException must be thrown"); } public void testNullArray() { diff --git a/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java index 0cf8bf32c..1c86b6591 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java @@ -16,10 +16,11 @@ */ package org.apache.commons.collections4.iterators; -import java.util.Arrays; import java.util.ListIterator; import java.util.NoSuchElementException; +import static org.junit.Assert.assertArrayEquals; + /** * Test the ArrayListIterator class. * @@ -71,14 +72,12 @@ public class ArrayListIteratorTest extends ArrayIteratorTest { assertEquals("Iteration value is correct", testValue, iterValue); } - assertTrue("Iterator should now be empty", !iter.hasPrevious()); + assertFalse("Iterator should now be empty", iter.hasPrevious()); try { iter.previous(); } catch (final Exception e) { - assertTrue( - "NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } } @@ -101,7 +100,7 @@ public class ArrayListIteratorTest extends ArrayIteratorTest { x++; } - assertTrue("The two arrays should have the same value, i.e. {0,1,2}", Arrays.equals(testData, result)); + assertArrayEquals("The two arrays should have the same value, i.e. {0,1,2}", testData, result); // a call to set() before a call to next() or previous() should throw an IllegalStateException iter = makeArrayListIterator(testArray); diff --git a/src/test/java/org/apache/commons/collections4/iterators/CollatingIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/CollatingIteratorTest.java index 52689f522..00c14df8d 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/CollatingIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/CollatingIteratorTest.java @@ -102,7 +102,7 @@ public class CollatingIteratorTest extends AbstractIteratorTest { assertEquals(even, iter.next()); assertEquals(0, iter.getIteratorIndex()); } - assertTrue(!iter.hasNext()); + assertFalse(iter.hasNext()); } public void testIterateEvenOdd() { @@ -112,7 +112,7 @@ public class CollatingIteratorTest extends AbstractIteratorTest { assertEquals(Integer.valueOf(i), iter.next()); assertEquals(i % 2, iter.getIteratorIndex()); } - assertTrue(!iter.hasNext()); + assertFalse(iter.hasNext()); } public void testIterateOddEven() { @@ -122,7 +122,7 @@ public class CollatingIteratorTest extends AbstractIteratorTest { assertEquals(Integer.valueOf(i), iter.next()); assertEquals(i % 2 == 0 ? 1 : 0, iter.getIteratorIndex()); } - assertTrue(!iter.hasNext()); + assertFalse(iter.hasNext()); } public void testIterateEvenEven() { @@ -137,7 +137,7 @@ public class CollatingIteratorTest extends AbstractIteratorTest { assertEquals(even, iter.next()); assertEquals(1, iter.getIteratorIndex()); } - assertTrue(!iter.hasNext()); + assertFalse(iter.hasNext()); } public void testIterateFibEvenOdd() { @@ -203,7 +203,7 @@ public class CollatingIteratorTest extends AbstractIteratorTest { assertEquals(Integer.valueOf(21), iter.next()); // fib 21 assertEquals(0, iter.getIteratorIndex()); - assertTrue(!iter.hasNext()); + assertFalse(iter.hasNext()); } public void testRemoveFromSingle() { diff --git a/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java index 461f9f245..cae41e384 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/FilterIteratorTest.java @@ -121,11 +121,11 @@ public class FilterIteratorTest extends AbstractIteratorTest { final FilterIterator filterIterator = new FilterIterator<>(iter1); filterIterator.setPredicate(truePredicate()); // this iterator has elements - assertEquals(true, filterIterator.hasNext()); + assertTrue(filterIterator.hasNext()); // this iterator has no elements filterIterator.setIterator(iter2); - assertEquals(false, filterIterator.hasNext()); + assertFalse(filterIterator.hasNext()); } /** @@ -138,15 +138,15 @@ public class FilterIteratorTest extends AbstractIteratorTest { final FilterIterator filterIterator = new FilterIterator<>(iter); filterIterator.setPredicate(truePredicate()); // this predicate matches - assertEquals(true, filterIterator.hasNext()); + assertTrue(filterIterator.hasNext()); // this predicate doesn't match filterIterator.setPredicate(NotNullPredicate.notNullPredicate()); - assertEquals(false, filterIterator.hasNext()); + assertFalse(filterIterator.hasNext()); } private void verifyNoMoreElements() { - assertTrue(!iterator.hasNext()); + assertFalse(iterator.hasNext()); try { iterator.next(); fail("NoSuchElementException expected"); @@ -179,7 +179,7 @@ public class FilterIteratorTest extends AbstractIteratorTest { if (iterator.hasNext()) { final Object last = iterator.next(); iterator.remove(); - assertTrue("Base of FilterIterator still contains removed element.", !list.contains(last)); + assertFalse("Base of FilterIterator still contains removed element.", list.contains(last)); } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/FilterListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/FilterListIteratorTest.java index ac4e36717..7ca03fd6c 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/FilterListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/FilterListIteratorTest.java @@ -136,7 +136,7 @@ public class FilterListIteratorTest { assertEquals(Integer.valueOf(3), filtered.previous()); assertEquals(Integer.valueOf(0), filtered.previous()); - assertTrue(!filtered.hasPrevious()); + assertFalse(filtered.hasPrevious()); assertEquals(Integer.valueOf(0), filtered.next()); assertEquals(Integer.valueOf(3), filtered.next()); @@ -146,7 +146,7 @@ public class FilterListIteratorTest { assertEquals(Integer.valueOf(15), filtered.next()); assertEquals(Integer.valueOf(18), filtered.next()); - assertTrue(!filtered.hasNext()); + assertFalse(filtered.hasNext()); assertEquals(Integer.valueOf(18), filtered.previous()); assertEquals(Integer.valueOf(15), filtered.previous()); @@ -276,7 +276,7 @@ public class FilterListIteratorTest { filtered.next(); } assertTrue(filtered.hasPrevious()); - assertTrue(!filtered.hasNext()); + assertFalse(filtered.hasNext()); assertEquals(expected.previous(), filtered.previous()); } diff --git a/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java b/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java index 9c45e33d0..ac50b72ef 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java @@ -79,13 +79,12 @@ public class IteratorChainTest extends AbstractIteratorTest { assertEquals( "Iteration value is correct", testValue, iterValue ); } - assertTrue("Iterator should now be empty", !iter.hasNext()); + assertFalse("Iterator should now be empty", iter.hasNext()); try { iter.next(); } catch (final Exception e) { - assertTrue("NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } } @@ -135,7 +134,7 @@ public class IteratorChainTest extends AbstractIteratorTest { } assertTrue("List is empty", list1.isEmpty()); - assertTrue("List is empty", list2.size() == 1); + assertEquals("List is empty", 1, list2.size()); assertTrue("List is empty", list3.isEmpty()); } @@ -154,12 +153,12 @@ public class IteratorChainTest extends AbstractIteratorTest { assertEquals("B", chain.next()); assertTrue("should have next", chain.hasNext()); assertEquals("C", chain.next()); - assertTrue("should not have next", !chain.hasNext()); + assertFalse("should not have next", chain.hasNext()); } public void testEmptyChain() { final IteratorChain chain = new IteratorChain<>(); - assertEquals(false, chain.hasNext()); + assertFalse(chain.hasNext()); try { chain.next(); fail(); diff --git a/src/test/java/org/apache/commons/collections4/iterators/LazyIteratorChainTest.java b/src/test/java/org/apache/commons/collections4/iterators/LazyIteratorChainTest.java index 33b9398a6..34e015ce3 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/LazyIteratorChainTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/LazyIteratorChainTest.java @@ -93,13 +93,12 @@ public class LazyIteratorChainTest extends AbstractIteratorTest { assertEquals( "Iteration value is correct", testValue, iterValue ); } - assertTrue("Iterator should now be empty", !iter.hasNext()); + assertFalse("Iterator should now be empty", iter.hasNext()); try { iter.next(); } catch (final Exception e) { - assertTrue("NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } } @@ -149,7 +148,7 @@ public class LazyIteratorChainTest extends AbstractIteratorTest { } assertTrue("List is empty", list1.isEmpty()); - assertTrue("List is empty", list2.size() == 1); + assertEquals("List is empty", 1, list2.size()); assertTrue("List is empty", list3.isEmpty()); } @@ -177,12 +176,12 @@ public class LazyIteratorChainTest extends AbstractIteratorTest { assertEquals("B", chain.next()); assertTrue("should have next", chain.hasNext()); assertEquals("C", chain.next()); - assertTrue("should not have next", !chain.hasNext()); + assertFalse("should not have next", chain.hasNext()); } public void testEmptyChain() { final LazyIteratorChain chain = makeEmptyIterator(); - assertEquals(false, chain.hasNext()); + assertFalse(chain.hasNext()); try { chain.next(); fail(); diff --git a/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapper2Test.java b/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapper2Test.java index 255dbbcbe..0f4904827 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapper2Test.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapper2Test.java @@ -70,13 +70,12 @@ public class ListIteratorWrapper2Test extends AbstractIteratorTest { assertEquals("Iteration value is correct", testValue, iterValue); } - assertTrue("Iterator should now be empty", !iter.hasNext()); + assertFalse("Iterator should now be empty", iter.hasNext()); try { iter.next(); } catch (final Exception e) { - assertTrue("NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } // now, read it backwards @@ -90,8 +89,7 @@ public class ListIteratorWrapper2Test extends AbstractIteratorTest { try { iter.previous(); } catch (final Exception e) { - assertTrue("NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } // now, read it forwards again diff --git a/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapperTest.java b/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapperTest.java index fd7e14cba..6d36eebb9 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapperTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapperTest.java @@ -71,13 +71,12 @@ public class ListIteratorWrapperTest extends AbstractIteratorTest { assertEquals("Iteration value is correct", testValue, iterValue); } - assertTrue("Iterator should now be empty", !iter.hasNext()); + assertFalse("Iterator should now be empty", iter.hasNext()); try { iter.next(); } catch (final Exception e) { - assertTrue("NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } // now, read it backwards @@ -91,8 +90,7 @@ public class ListIteratorWrapperTest extends AbstractIteratorTest { try { iter.previous(); } catch (final Exception e) { - assertTrue("NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } // now, read it forwards again diff --git a/src/test/java/org/apache/commons/collections4/iterators/LoopingIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/LoopingIteratorTest.java index d3df80cc8..c0169d970 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/LoopingIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/LoopingIteratorTest.java @@ -51,7 +51,7 @@ public class LoopingIteratorTest { public void testLooping0() throws Exception { final List list = new ArrayList<>(); final LoopingIterator loop = new LoopingIterator<>(list); - assertTrue(!loop.hasNext(), "hasNext should return false"); + assertFalse(loop.hasNext(), "hasNext should return false"); try { loop.next(); diff --git a/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayIteratorTest.java index f17d3d1ca..cea9f2774 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayIteratorTest.java @@ -73,14 +73,12 @@ public class ObjectArrayIteratorTest extends AbstractIteratorTest { assertEquals("Iteration value is correct", testValue, iterValue); } - assertTrue("Iterator should now be empty", !iter.hasNext()); + assertFalse("Iterator should now be empty", iter.hasNext()); try { iter.next(); } catch (final Exception e) { - assertTrue( - "NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java index 7d9975d5f..937735124 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java @@ -16,10 +16,11 @@ */ package org.apache.commons.collections4.iterators; -import java.util.Arrays; import java.util.ListIterator; import java.util.NoSuchElementException; +import static org.junit.Assert.assertArrayEquals; + /** * Tests the ObjectArrayListIterator class. * @@ -68,14 +69,12 @@ public class ObjectArrayListIteratorTest extends ObjectArrayIteratorTest { assertEquals("Iteration value is correct", testValue, iterValue); } - assertTrue("Iterator should now be empty", !iter.hasPrevious()); + assertFalse("Iterator should now be empty", iter.hasPrevious()); try { iter.previous(); } catch (final Exception e) { - assertTrue( - "NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } } @@ -98,7 +97,7 @@ public class ObjectArrayListIteratorTest extends ObjectArrayIteratorTest { x++; } - assertTrue("The two arrays should have the same value, i.e. {0,1,2}", Arrays.equals(testData, result)); + assertArrayEquals("The two arrays should have the same value, i.e. {0,1,2}", testData, result); // a call to set() before a call to next() or previous() should throw an IllegalStateException iter = makeArrayListIterator((E[]) testArray); diff --git a/src/test/java/org/apache/commons/collections4/iterators/ObjectGraphIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ObjectGraphIteratorTest.java index 48d7ed619..302a3c8cc 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ObjectGraphIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ObjectGraphIteratorTest.java @@ -72,7 +72,7 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { public void testIteratorConstructor_null1() { final Iterator it = new ObjectGraphIterator<>(null); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); try { it.next(); fail(); @@ -107,7 +107,7 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { final List> iteratorList = new ArrayList<>(); final Iterator it = new ObjectGraphIterator<>(iteratorList.iterator()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); try { it.next(); fail(); @@ -128,10 +128,10 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { final Iterator it = new ObjectGraphIterator<>(iteratorList.iterator()); for (int i = 0; i < 6; i++) { - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(testArray[i], it.next()); } - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); try { it.next(); fail(); @@ -168,10 +168,10 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { final Iterator it = new ObjectGraphIterator<>(iteratorList.iterator()); for (int i = 0; i < 6; i++) { - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(testArray[i], it.next()); } - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); try { it.next(); fail(); @@ -190,7 +190,7 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { assertEquals(testArray[i], it.next()); it.remove(); } - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); assertEquals(0, list1.size()); assertEquals(0, list2.size()); assertEquals(0, list3.size()); @@ -204,10 +204,10 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { final Iterator it = new ObjectGraphIterator<>(iteratorList.iterator(), null); for (int i = 0; i < 6; i++) { - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(testArray[i], it.next()); } - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); } public void testIteration_IteratorOfIteratorsWithEmptyIterators() { @@ -222,16 +222,16 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { final Iterator it = new ObjectGraphIterator<>(iteratorList.iterator(), null); for (int i = 0; i < 6; i++) { - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(testArray[i], it.next()); } - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); } public void testIteration_RootNull() { final Iterator it = new ObjectGraphIterator<>(null, null); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); try { it.next(); fail(); @@ -248,9 +248,9 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { final Forest forest = new Forest(); final Iterator it = new ObjectGraphIterator<>(forest, null); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(forest, it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); try { it.next(); fail(); @@ -263,9 +263,9 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { final Leaf l1 = forest.addTree().addBranch().addLeaf(); final Iterator it = new ObjectGraphIterator<>(forest, new LeafFinder()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l1, it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); try { it.next(); fail(); @@ -291,17 +291,17 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { final Iterator it = new ObjectGraphIterator<>(forest, new LeafFinder()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l1, it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l2, it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l3, it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l4, it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l5, it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); try { it.next(); fail(); @@ -327,17 +327,17 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest { final Iterator it = new ObjectGraphIterator<>(forest, new LeafFinder()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l1, it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l2, it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l3, it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l4, it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertSame(l5, it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); try { it.next(); fail(); diff --git a/src/test/java/org/apache/commons/collections4/iterators/ReverseListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ReverseListIteratorTest.java index 64baf53da..e4faf1cef 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ReverseListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ReverseListIteratorTest.java @@ -53,9 +53,9 @@ public class ReverseListIteratorTest extends AbstractListIteratorTest { public void testEmptyListIteratorIsIndeedEmpty() { final ListIterator it = makeEmptyIterator(); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); assertEquals(-1, it.nextIndex()); // reversed index - assertEquals(false, it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals(0, it.previousIndex()); // reversed index // next() should throw a NoSuchElementException @@ -82,8 +82,8 @@ public class ReverseListIteratorTest extends AbstractListIteratorTest { } // check state at end - assertEquals(false, it.hasNext()); - assertEquals(true, it.hasPrevious()); + assertFalse(it.hasNext()); + assertTrue(it.hasPrevious()); // this had to be commented out, as there is a bug in the JDK before JDK1.5 // where calling previous at the start of an iterator would push the cursor @@ -104,8 +104,8 @@ public class ReverseListIteratorTest extends AbstractListIteratorTest { } // check state at start - assertEquals(true, it.hasNext()); - assertEquals(false, it.hasPrevious()); + assertTrue(it.hasNext()); + assertFalse(it.hasPrevious()); try { it.previous(); fail("NoSuchElementException must be thrown from previous at start of ListIterator"); @@ -115,29 +115,29 @@ public class ReverseListIteratorTest extends AbstractListIteratorTest { public void testReverse() { final ListIterator it = makeObject(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(3, it.nextIndex()); - assertEquals(false, it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals(4, it.previousIndex()); assertEquals("Four", it.next()); assertEquals(2, it.nextIndex()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(3, it.previousIndex()); - assertEquals(true, it.hasPrevious()); + assertTrue(it.hasPrevious()); assertEquals("Three", it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(1, it.nextIndex()); - assertEquals(true, it.hasPrevious()); + assertTrue(it.hasPrevious()); assertEquals(2, it.previousIndex()); assertEquals("Two", it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(0, it.nextIndex()); - assertEquals(true, it.hasPrevious()); + assertTrue(it.hasPrevious()); assertEquals(1, it.previousIndex()); assertEquals("One", it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); assertEquals(-1, it.nextIndex()); - assertEquals(true, it.hasPrevious()); + assertTrue(it.hasPrevious()); assertEquals(0, it.previousIndex()); assertEquals("One", it.previous()); assertEquals("Two", it.previous()); diff --git a/src/test/java/org/apache/commons/collections4/iterators/SingletonIterator2Test.java b/src/test/java/org/apache/commons/collections4/iterators/SingletonIterator2Test.java index 3b8bb5dbc..9e4c20e65 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/SingletonIterator2Test.java +++ b/src/test/java/org/apache/commons/collections4/iterators/SingletonIterator2Test.java @@ -67,34 +67,32 @@ public class SingletonIterator2Test extends AbstractIteratorTest { final E iterValue = iter.next(); assertEquals("Iteration value is correct", testValue, iterValue); - assertTrue("Iterator should now be empty", !iter.hasNext()); + assertFalse("Iterator should now be empty", iter.hasNext()); try { iter.next(); } catch (final Exception e) { - assertTrue( - "NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } } public void testReset() { final ResettableIterator it = makeObject(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(testValue, it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); it.reset(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(testValue, it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); it.reset(); it.reset(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/SingletonIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/SingletonIteratorTest.java index 512708d4a..0b57386e7 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/SingletonIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/SingletonIteratorTest.java @@ -70,14 +70,12 @@ public class SingletonIteratorTest extends AbstractIteratorTest { final E iterValue = iter.next(); assertEquals("Iteration value is correct", testValue, iterValue); - assertTrue("Iterator should now be empty", !iter.hasNext()); + assertFalse("Iterator should now be empty", iter.hasNext()); try { iter.next(); } catch (final Exception e) { - assertTrue( - "NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } } @@ -88,26 +86,26 @@ public class SingletonIteratorTest extends AbstractIteratorTest { assertEquals("xyzzy", iter.next()); iter.remove(); iter.reset(); - assertTrue(! iter.hasNext()); + assertFalse(iter.hasNext()); } public void testReset() { final ResettableIterator it = makeObject(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(testValue, it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); it.reset(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals(testValue, it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); it.reset(); it.reset(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/SingletonListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/SingletonListIteratorTest.java index e96980f49..45af94f8c 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/SingletonListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/SingletonListIteratorTest.java @@ -70,14 +70,14 @@ public class SingletonListIteratorTest extends AbstractListIteratorTest { public void testIterator() { final ListIterator iter = makeObject(); assertTrue( "Iterator should have next item", iter.hasNext() ); - assertTrue( "Iterator should have no previous item", !iter.hasPrevious() ); + assertFalse("Iterator should have no previous item", iter.hasPrevious()); assertEquals( "Iteration next index", 0, iter.nextIndex() ); assertEquals( "Iteration previous index", -1, iter.previousIndex() ); Object iterValue = iter.next(); assertEquals( "Iteration value is correct", testValue, iterValue ); - assertTrue( "Iterator should have no next item", !iter.hasNext() ); + assertFalse("Iterator should have no next item", iter.hasNext()); assertTrue( "Iterator should have previous item", iter.hasPrevious() ); assertEquals( "Iteration next index", 1, iter.nextIndex() ); assertEquals( "Iteration previous index", 0, iter.previousIndex() ); @@ -86,14 +86,14 @@ public class SingletonListIteratorTest extends AbstractListIteratorTest { assertEquals( "Iteration value is correct", testValue, iterValue ); assertTrue( "Iterator should have next item", iter.hasNext() ); - assertTrue( "Iterator should have no previous item", !iter.hasPrevious() ); + assertFalse("Iterator should have no previous item", iter.hasPrevious()); assertEquals( "Iteration next index", 0, iter.nextIndex() ); assertEquals( "Iteration previous index", -1, iter.previousIndex() ); iterValue = iter.next(); assertEquals( "Iteration value is correct", testValue, iterValue ); - assertTrue( "Iterator should have no next item", !iter.hasNext() ); + assertFalse("Iterator should have no next item", iter.hasNext()); assertTrue( "Iterator should have previous item", iter.hasPrevious() ); assertEquals( "Iteration next index", 1, iter.nextIndex() ); assertEquals( "Iteration previous index", 0, iter.previousIndex() ); @@ -101,39 +101,37 @@ public class SingletonListIteratorTest extends AbstractListIteratorTest { try { iter.next(); } catch (final Exception e) { - assertTrue("NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } iter.previous(); try { iter.previous(); } catch (final Exception e) { - assertTrue("NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } } public void testReset() { final ResettableListIterator it = makeObject(); - assertEquals(true, it.hasNext()); - assertEquals(false, it.hasPrevious()); + assertTrue(it.hasNext()); + assertFalse(it.hasPrevious()); assertEquals(testValue, it.next()); - assertEquals(false, it.hasNext()); - assertEquals(true, it.hasPrevious()); + assertFalse(it.hasNext()); + assertTrue(it.hasPrevious()); it.reset(); - assertEquals(true, it.hasNext()); - assertEquals(false, it.hasPrevious()); + assertTrue(it.hasNext()); + assertFalse(it.hasPrevious()); assertEquals(testValue, it.next()); - assertEquals(false, it.hasNext()); - assertEquals(true, it.hasPrevious()); + assertFalse(it.hasNext()); + assertTrue(it.hasPrevious()); it.reset(); it.reset(); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/UniqueFilterIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/UniqueFilterIteratorTest.java index bf8078bde..6044c9c0e 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/UniqueFilterIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/UniqueFilterIteratorTest.java @@ -73,13 +73,12 @@ public class UniqueFilterIteratorTest extends AbstractIteratorTest { assertEquals( "Iteration value is correct", testValue, iterValue ); } - assertTrue("Iterator should now be empty", ! iter.hasNext() ); + assertFalse("Iterator should now be empty", iter.hasNext()); try { iter.next(); } catch (final Exception e) { - assertTrue("NoSuchElementException must be thrown", - e.getClass().equals(new NoSuchElementException().getClass())); + assertEquals("NoSuchElementException must be thrown", e.getClass(), new NoSuchElementException().getClass()); } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/UnmodifiableIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/UnmodifiableIteratorTest.java index ff8cfaa7f..36057063f 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/UnmodifiableIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/UnmodifiableIteratorTest.java @@ -71,7 +71,7 @@ public class UnmodifiableIteratorTest extends AbstractIteratorTest { assertSame(it, UnmodifiableIterator.unmodifiableIterator(it)); it = testList.iterator(); - assertTrue(it != UnmodifiableIterator.unmodifiableIterator(it)); + assertNotSame(it, UnmodifiableIterator.unmodifiableIterator(it)); try { UnmodifiableIterator.unmodifiableIterator(null); diff --git a/src/test/java/org/apache/commons/collections4/iterators/UnmodifiableMapIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/UnmodifiableMapIteratorTest.java index 420e93108..2fa9f46d6 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/UnmodifiableMapIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/UnmodifiableMapIteratorTest.java @@ -83,7 +83,7 @@ public class UnmodifiableMapIteratorTest extends AbstractMapIteratorTest extends AbstractOrderedMap assertSame(it, UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(it)); it = getMap().mapIterator(); - assertTrue(it != UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(it)); + assertNotSame(it, UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(it)); try { UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(null); diff --git a/src/test/java/org/apache/commons/collections4/iterators/ZippingIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ZippingIteratorTest.java index f4caa8c48..2a26ee420 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ZippingIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ZippingIteratorTest.java @@ -84,7 +84,7 @@ public class ZippingIteratorTest extends AbstractIteratorTest { assertTrue(iter.hasNext()); assertEquals(even, iter.next()); } - assertTrue(!iter.hasNext()); + assertFalse(iter.hasNext()); } public void testIterateEvenOdd() { @@ -93,7 +93,7 @@ public class ZippingIteratorTest extends AbstractIteratorTest { assertTrue(iter.hasNext()); assertEquals(Integer.valueOf(i), iter.next()); } - assertTrue(!iter.hasNext()); + assertFalse(iter.hasNext()); } public void testIterateOddEven() { @@ -108,7 +108,7 @@ public class ZippingIteratorTest extends AbstractIteratorTest { j++; } } - assertTrue(!iter.hasNext()); + assertFalse(iter.hasNext()); } public void testIterateEvenEven() { @@ -119,7 +119,7 @@ public class ZippingIteratorTest extends AbstractIteratorTest { assertTrue(iter.hasNext()); assertEquals(even, iter.next()); } - assertTrue(!iter.hasNext()); + assertFalse(iter.hasNext()); } public void testIterateFibEvenOdd() { @@ -154,7 +154,7 @@ public class ZippingIteratorTest extends AbstractIteratorTest { assertEquals(Integer.valueOf(18), iter.next()); // even 18 assertEquals(Integer.valueOf(19), iter.next()); // odd 19 - assertTrue(!iter.hasNext()); + assertFalse(iter.hasNext()); } public void testRemoveFromSingle() { diff --git a/src/test/java/org/apache/commons/collections4/keyvalue/AbstractMapEntryTest.java b/src/test/java/org/apache/commons/collections4/keyvalue/AbstractMapEntryTest.java index 3189dca5d..f5be77074 100644 --- a/src/test/java/org/apache/commons/collections4/keyvalue/AbstractMapEntryTest.java +++ b/src/test/java/org/apache/commons/collections4/keyvalue/AbstractMapEntryTest.java @@ -74,17 +74,17 @@ public abstract class AbstractMapEntryTest { public void testAccessorsAndMutators() { Map.Entry entry = makeMapEntry((K) key, (V) value); - assertTrue(entry.getKey() == key); + assertSame(key, entry.getKey()); entry.setValue((V) value); - assertTrue(entry.getValue() == value); + assertSame(value, entry.getValue()); // check that null doesn't do anything funny entry = makeMapEntry(null, null); - assertTrue(entry.getKey() == null); + assertNull(entry.getKey()); entry.setValue(null); - assertTrue(entry.getValue() == null); + assertNull(entry.getValue()); } /** @@ -127,30 +127,30 @@ public abstract class AbstractMapEntryTest { Map.Entry e1 = makeMapEntry((K) key, (V) value); Map.Entry e2 = makeKnownMapEntry((K) key, (V) value); - assertTrue(e1.equals(e1)); - assertTrue(e2.equals(e1)); - assertTrue(e1.equals(e2)); - assertTrue(e1.hashCode() == e2.hashCode()); + assertEquals(e1, e1); + assertEquals(e2, e1); + assertEquals(e1, e2); + assertEquals(e1.hashCode(), e2.hashCode()); // 2. test with nulls e1 = makeMapEntry(); e2 = makeKnownMapEntry(); - assertTrue(e1.equals(e1)); - assertTrue(e2.equals(e1)); - assertTrue(e1.equals(e2)); - assertTrue(e1.hashCode() == e2.hashCode()); + assertEquals(e1, e1); + assertEquals(e2, e1); + assertEquals(e1, e2); + assertEquals(e1.hashCode(), e2.hashCode()); } @SuppressWarnings("unchecked") @Test public void testToString() { Map.Entry entry = makeMapEntry((K) key, (V) value); - assertTrue(entry.toString().equals(entry.getKey() + "=" + entry.getValue())); + assertEquals(entry.toString(), entry.getKey() + "=" + entry.getValue()); // test with nulls entry = makeMapEntry(); - assertTrue(entry.toString().equals(entry.getKey() + "=" + entry.getValue())); + assertEquals(entry.toString(), entry.getKey() + "=" + entry.getValue()); } } diff --git a/src/test/java/org/apache/commons/collections4/keyvalue/DefaultKeyValueTest.java b/src/test/java/org/apache/commons/collections4/keyvalue/DefaultKeyValueTest.java index e55698936..63572508e 100644 --- a/src/test/java/org/apache/commons/collections4/keyvalue/DefaultKeyValueTest.java +++ b/src/test/java/org/apache/commons/collections4/keyvalue/DefaultKeyValueTest.java @@ -57,17 +57,17 @@ public class DefaultKeyValueTest { final DefaultKeyValue kv = makeDefaultKeyValue(); kv.setKey((K) key); - assertTrue(kv.getKey() == key); + assertSame(key, kv.getKey()); kv.setValue((V) value); - assertTrue(kv.getValue() == value); + assertSame(value, kv.getValue()); // check that null doesn't do anything funny kv.setKey(null); - assertTrue(kv.getKey() == null); + assertNull(kv.getKey()); kv.setValue(null); - assertTrue(kv.getValue() == null); + assertNull(kv.getValue()); } @@ -135,7 +135,7 @@ public class DefaultKeyValueTest { // test that the KVP is independent of the Map.Entry entry.setValue(null); - assertTrue(kv.getValue() == value); + assertSame(value, kv.getValue()); } @@ -146,28 +146,28 @@ public class DefaultKeyValueTest { DefaultKeyValue kv = makeDefaultKeyValue((K) key, (V) value); DefaultKeyValue kv2 = makeDefaultKeyValue((K) key, (V) value); - assertTrue(kv.equals(kv)); - assertTrue(kv.equals(kv2)); - assertTrue(kv.hashCode() == kv2.hashCode()); + assertEquals(kv, kv); + assertEquals(kv, kv2); + assertEquals(kv.hashCode(), kv2.hashCode()); // 2. test with nulls kv = makeDefaultKeyValue(null, null); kv2 = makeDefaultKeyValue(null, null); - assertTrue(kv.equals(kv)); - assertTrue(kv.equals(kv2)); - assertTrue(kv.hashCode() == kv2.hashCode()); + assertEquals(kv, kv); + assertEquals(kv, kv2); + assertEquals(kv.hashCode(), kv2.hashCode()); } @SuppressWarnings("unchecked") @Test public void testToString() { DefaultKeyValue kv = makeDefaultKeyValue((K) key, (V) value); - assertTrue(kv.toString().equals(kv.getKey() + "=" + kv.getValue())); + assertEquals(kv.toString(), kv.getKey() + "=" + kv.getValue()); // test with nulls kv = makeDefaultKeyValue(null, null); - assertTrue(kv.toString().equals(kv.getKey() + "=" + kv.getValue())); + assertEquals(kv.toString(), kv.getKey() + "=" + kv.getValue()); } @SuppressWarnings("unchecked") @@ -179,8 +179,8 @@ public class DefaultKeyValueTest { map.put(kv.getKey(), kv.getValue()); final Map.Entry entry = map.entrySet().iterator().next(); - assertTrue(entry.equals(kv.toMapEntry())); - assertTrue(entry.hashCode() == kv.hashCode()); + assertEquals(entry, kv.toMapEntry()); + assertEquals(entry.hashCode(), kv.hashCode()); } } diff --git a/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java b/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java index 4d68af964..3fa7af0df 100644 --- a/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java +++ b/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -90,19 +89,19 @@ public class MultiKeyTest { public void testConstructors() throws Exception { MultiKey mk; mk = new MultiKey<>(ONE, TWO); - assertTrue(Arrays.equals(new Object[] { ONE, TWO }, mk.getKeys())); + assertArrayEquals(new Object[]{ONE, TWO}, mk.getKeys()); mk = new MultiKey<>(ONE, TWO, THREE); - assertTrue(Arrays.equals(new Object[] { ONE, TWO, THREE }, mk.getKeys())); + assertArrayEquals(new Object[]{ONE, TWO, THREE}, mk.getKeys()); mk = new MultiKey<>(ONE, TWO, THREE, FOUR); - assertTrue(Arrays.equals(new Object[] { ONE, TWO, THREE, FOUR }, mk.getKeys())); + assertArrayEquals(new Object[]{ONE, TWO, THREE, FOUR}, mk.getKeys()); mk = new MultiKey<>(ONE, TWO, THREE, FOUR, FIVE); - assertTrue(Arrays.equals(new Object[] { ONE, TWO, THREE, FOUR, FIVE }, mk.getKeys())); + assertArrayEquals(new Object[]{ONE, TWO, THREE, FOUR, FIVE}, mk.getKeys()); mk = new MultiKey<>(new Integer[] { THREE, FOUR, ONE, TWO }, false); - assertTrue(Arrays.equals(new Object[] { THREE, FOUR, ONE, TWO }, mk.getKeys())); + assertArrayEquals(new Object[]{THREE, FOUR, ONE, TWO}, mk.getKeys()); } @Test @@ -110,27 +109,27 @@ public class MultiKeyTest { MultiKey mk; Integer[] keys = new Integer[] { THREE, FOUR, ONE, TWO }; mk = new MultiKey<>(keys); - assertTrue(Arrays.equals(new Object[] { THREE, FOUR, ONE, TWO }, mk.getKeys())); + assertArrayEquals(new Object[]{THREE, FOUR, ONE, TWO}, mk.getKeys()); keys[3] = FIVE; // no effect - assertTrue(Arrays.equals(new Object[] { THREE, FOUR, ONE, TWO }, mk.getKeys())); + assertArrayEquals(new Object[]{THREE, FOUR, ONE, TWO}, mk.getKeys()); keys = new Integer[] {}; mk = new MultiKey<>(keys); - assertTrue(Arrays.equals(new Object[] {}, mk.getKeys())); + assertArrayEquals(new Object[]{}, mk.getKeys()); keys = new Integer[] { THREE, FOUR, ONE, TWO }; mk = new MultiKey<>(keys, true); - assertTrue(Arrays.equals(new Object[] { THREE, FOUR, ONE, TWO }, mk.getKeys())); + assertArrayEquals(new Object[]{THREE, FOUR, ONE, TWO}, mk.getKeys()); keys[3] = FIVE; // no effect - assertTrue(Arrays.equals(new Object[] { THREE, FOUR, ONE, TWO }, mk.getKeys())); + assertArrayEquals(new Object[]{THREE, FOUR, ONE, TWO}, mk.getKeys()); keys = new Integer[] { THREE, FOUR, ONE, TWO }; mk = new MultiKey<>(keys, false); - assertTrue(Arrays.equals(new Object[] { THREE, FOUR, ONE, TWO }, mk.getKeys())); + assertArrayEquals(new Object[]{THREE, FOUR, ONE, TWO}, mk.getKeys()); // change key - don't do this! // the hashcode of the MultiKey is now broken keys[3] = FIVE; - assertTrue(Arrays.equals(new Object[] { THREE, FOUR, ONE, FIVE }, mk.getKeys())); + assertArrayEquals(new Object[]{THREE, FOUR, ONE, FIVE}, mk.getKeys()); } @Test @@ -158,9 +157,9 @@ public class MultiKeyTest { assertEquals(mk1, mk1); assertEquals(mk1, mk2); - assertFalse(mk1.equals(mk3)); - assertFalse(mk1.equals("")); - assertFalse(mk1.equals(null)); + assertNotEquals(mk1, mk3); + assertNotEquals("", mk1); + assertNotEquals(null, mk1); } @Test @@ -229,8 +228,8 @@ public class MultiKeyTest { final Integer[] keys = new Integer[] { ONE, TWO }; final MultiKey mk = new MultiKey<>(keys, true); final Object[] array = mk.getKeys(); - assertTrue(array != keys); - assertTrue(Arrays.equals(array, keys)); + assertNotSame(array, keys); + assertArrayEquals(array, keys); assertSame(ONE, array[0]); assertSame(TWO, array[1]); assertEquals(2, array.length); @@ -241,8 +240,8 @@ public class MultiKeyTest { final Integer[] keys = new Integer[] { ONE, TWO }; final MultiKey mk = new MultiKey<>(keys, false); final Object[] array = mk.getKeys(); - assertTrue(array != keys); // still not equal - assertTrue(Arrays.equals(array, keys)); + assertNotSame(array, keys); // still not equal + assertArrayEquals(array, keys); assertSame(ONE, array[0]); assertSame(TWO, array[1]); assertEquals(2, array.length); @@ -263,8 +262,8 @@ public class MultiKeyTest { final MultiKey mk2 = new MultiKey<>(ONE, TWO); final MultiKey mk3 = new MultiKey<>(ONE, "TWO"); - assertTrue(mk1.hashCode() == mk1.hashCode()); - assertTrue(mk1.hashCode() == mk2.hashCode()); + assertEquals(mk1.hashCode(), mk1.hashCode()); + assertEquals(mk1.hashCode(), mk2.hashCode()); assertTrue(mk1.hashCode() != mk3.hashCode()); final int total = (0 ^ ONE.hashCode()) ^ TWO.hashCode(); diff --git a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java index 0ac4a7b63..1fad15fd7 100644 --- a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java @@ -282,32 +282,32 @@ public abstract class AbstractListTest extends AbstractCollectionTest { public void testListEquals() { resetEmpty(); List list = getCollection(); - assertEquals("Empty lists should be equal", true, list.equals(getConfirmed())); + assertTrue("Empty lists should be equal", list.equals(getConfirmed())); verify(); - assertEquals("Empty list should equal self", true, list.equals(list)); + assertTrue("Empty list should equal self", list.equals(list)); verify(); List list2 = Arrays.asList(getFullElements()); - assertEquals("Empty list shouldn't equal full", false, list.equals(list2)); + assertFalse("Empty list shouldn't equal full", list.equals(list2)); verify(); list2 = Arrays.asList(getOtherElements()); - assertEquals("Empty list shouldn't equal other", false, list.equals(list2)); + assertFalse("Empty list shouldn't equal other", list.equals(list2)); verify(); resetFull(); list = getCollection(); - assertEquals("Full lists should be equal", true, list.equals(getConfirmed())); + assertTrue("Full lists should be equal", list.equals(getConfirmed())); verify(); - assertEquals("Full list should equal self", true, list.equals(list)); + assertTrue("Full list should equal self", list.equals(list)); verify(); list2 = makeObject(); - assertEquals("Full list shouldn't equal empty", false, list.equals(list2)); + assertFalse("Full list shouldn't equal empty", list.equals(list2)); verify(); list2 = Arrays.asList(getOtherElements()); - assertEquals("Full list shouldn't equal other", false, list.equals(list2)); + assertFalse("Full list shouldn't equal other", list.equals(list2)); verify(); list2 = Arrays.asList(getFullElements()); @@ -320,15 +320,13 @@ public abstract class AbstractListTest extends AbstractCollectionTest { } if (list2.size() > 1) { Collections.reverse(list2); - assertEquals( - "Full list shouldn't equal full list with same elements but different order", - false, list.equals(list2)); + assertFalse("Full list shouldn't equal full list with same elements but different order", list.equals(list2)); verify(); } resetFull(); list = getCollection(); - assertEquals("List shouldn't equal String", false, list.equals("")); + assertFalse("List shouldn't equal String", list.equals("")); verify(); final List listForC = Arrays.asList(getFullElements()); @@ -344,7 +342,7 @@ public abstract class AbstractListTest extends AbstractCollectionTest { } }; - assertEquals("List shouldn't equal nonlist with same elements in same order", false, list.equals(c)); + assertFalse("List shouldn't equal nonlist with same elements in same order", list.equals(c)); verify(); } @@ -807,7 +805,7 @@ public abstract class AbstractListTest extends AbstractCollectionTest { final E two3 = it.next(); // do next after remove assertEquals(two, two3); assertEquals(getCollection().size() > 2, it.hasNext()); - assertEquals(true, it.hasPrevious()); + assertTrue(it.hasPrevious()); } /** @@ -838,7 +836,7 @@ public abstract class AbstractListTest extends AbstractCollectionTest { assertEquals(two, getCollection().get(1)); final E zero3 = it.previous(); // do previous after remove assertEquals(zero, zero3); - assertEquals(false, it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals(getCollection().size() > 2, it.hasNext()); } @@ -868,7 +866,7 @@ public abstract class AbstractListTest extends AbstractCollectionTest { final E three2 = it.next(); // do next after remove assertEquals(three, three2); assertEquals(getCollection().size() > 3, it.hasNext()); - assertEquals(true, it.hasPrevious()); + assertTrue(it.hasPrevious()); } /** @@ -895,8 +893,8 @@ public abstract class AbstractListTest extends AbstractCollectionTest { assertEquals(one, getCollection().get(1)); final E one2 = it.previous(); // do previous after remove assertEquals(one, one2); - assertEquals(true, it.hasNext()); - assertEquals(true, it.hasPrevious()); + assertTrue(it.hasNext()); + assertTrue(it.hasPrevious()); } /** @@ -920,7 +918,7 @@ public abstract class AbstractListTest extends AbstractCollectionTest { i++; } - assertTrue("Iterator shouldn't have next", !iter.hasNext()); + assertFalse("Iterator shouldn't have next", iter.hasNext()); assertEquals("nextIndex should be size", max, iter.nextIndex()); assertEquals("previousIndex should be size - 1", max - 1, iter.previousIndex()); @@ -954,7 +952,7 @@ public abstract class AbstractListTest extends AbstractCollectionTest { i--; } - assertTrue("Iterator shouldn't have previous", !iter.hasPrevious()); + assertFalse("Iterator shouldn't have previous", iter.hasPrevious()); final int nextIndex = iter.nextIndex(); assertEquals("nextIndex should be 0", 0, nextIndex); final int prevIndex = iter.previousIndex(); diff --git a/src/test/java/org/apache/commons/collections4/list/CursorableLinkedListTest.java b/src/test/java/org/apache/commons/collections4/list/CursorableLinkedListTest.java index 42de6c7a4..f9a17ee48 100644 --- a/src/test/java/org/apache/commons/collections4/list/CursorableLinkedListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/CursorableLinkedListTest.java @@ -95,7 +95,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { list.add((E) "element"); assertEquals(1, list.size()); - assertTrue(!list.isEmpty()); + assertFalse(list.isEmpty()); list.clear(); assertEquals(0, list.size()); @@ -104,7 +104,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { list.add((E) "element1"); list.add((E) "element2"); assertEquals(2, list.size()); - assertTrue(!list.isEmpty()); + assertFalse(list.isEmpty()); list.clear(); assertEquals(0, list.size()); @@ -114,7 +114,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { list.add((E) Integer.valueOf(i)); } assertEquals(1000, list.size()); - assertTrue(!list.isEmpty()); + assertFalse(list.isEmpty()); list.clear(); assertEquals(0, list.size()); @@ -123,7 +123,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { @SuppressWarnings("unchecked") public void testContains() { - assertTrue(!list.contains("A")); + assertFalse(list.contains("A")); assertTrue(list.add((E) "A")); assertTrue(list.contains("A")); assertTrue(list.add((E) "B")); @@ -133,7 +133,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertTrue(list.remove("a")); assertTrue(list.contains("A")); assertTrue(list.remove("A")); - assertTrue(!list.contains("A")); + assertFalse(list.contains("A")); } @SuppressWarnings("unchecked") @@ -142,14 +142,14 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { final java.util.List list2 = new java.util.LinkedList<>(); assertTrue(list.containsAll(list2)); list2.add((E) "A"); - assertTrue(!list.containsAll(list2)); + assertFalse(list.containsAll(list2)); list.add((E) "B"); list.add((E) "A"); assertTrue(list.containsAll(list2)); list2.add((E) "B"); assertTrue(list.containsAll(list2)); list2.add((E) "C"); - assertTrue(!list.containsAll(list2)); + assertFalse(list.containsAll(list2)); list.add((E) "C"); assertTrue(list.containsAll(list2)); list2.add((E) "C"); @@ -166,13 +166,13 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { list.add((E) "5"); final CursorableLinkedList.Cursor it = list.cursor(); assertTrue(it.hasNext()); - assertTrue(!it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals("1", it.next()); assertTrue(it.hasNext()); assertTrue(it.hasPrevious()); assertEquals("1", it.previous()); assertTrue(it.hasNext()); - assertTrue(!it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals("1", it.next()); assertTrue(it.hasNext()); assertTrue(it.hasPrevious()); @@ -192,7 +192,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertTrue(it.hasNext()); assertTrue(it.hasPrevious()); assertEquals("5", it.next()); - assertTrue(!it.hasNext()); + assertFalse(it.hasNext()); assertTrue(it.hasPrevious()); assertEquals("5", it.previous()); assertTrue(it.hasNext()); @@ -208,7 +208,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertTrue(it.hasPrevious()); assertEquals("1", it.previous()); assertTrue(it.hasNext()); - assertTrue(!it.hasPrevious()); + assertFalse(it.hasPrevious()); it.close(); } @@ -262,7 +262,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals("1", it.previous()); it.remove(); assertEquals("[3, 4, 5]", list.toString()); - assertTrue(!it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals("3", it.next()); it.remove(); assertEquals("[4, 5]", list.toString()); @@ -469,10 +469,10 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals("B", list.remove(1)); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(1, c1.nextIndex); - assertEquals(true, c1.currentRemovedByAnother); - assertEquals(null, c1.current); + assertTrue(c1.currentRemovedByAnother); + assertNull(c1.current); assertEquals("C", c1.next.value); assertEquals("[A, C]", list.toString()); @@ -495,9 +495,9 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals("B", list.remove(1)); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(1, c1.nextIndex); - assertEquals(false, c1.currentRemovedByAnother); + assertFalse(c1.currentRemovedByAnother); assertEquals("A", c1.current.value); assertEquals("C", c1.next.value); @@ -522,10 +522,10 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals("B", list.remove(1)); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(1, c1.nextIndex); - assertEquals(true, c1.currentRemovedByAnother); - assertEquals(null, c1.current); + assertTrue(c1.currentRemovedByAnother); + assertNull(c1.current); assertEquals("C", c1.next.value); assertEquals("[A, C]", list.toString()); @@ -551,8 +551,8 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals("B", list.remove(1)); - assertEquals(false, c1.nextIndexValid); - assertEquals(false, c1.currentRemovedByAnother); + assertFalse(c1.nextIndexValid); + assertFalse(c1.currentRemovedByAnother); assertEquals("C", c1.current.value); assertEquals("D", c1.next.value); @@ -578,10 +578,10 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { c1.remove(); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(1, c1.nextIndex); - assertEquals(false, c1.currentRemovedByAnother); - assertEquals(null, c1.current); + assertFalse(c1.currentRemovedByAnother); + assertNull(c1.current); assertEquals("C", c1.next.value); assertEquals("[A, C]", list.toString()); @@ -603,10 +603,10 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { c1.remove(); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(1, c1.nextIndex); - assertEquals(false, c1.currentRemovedByAnother); - assertEquals(null, c1.current); + assertFalse(c1.currentRemovedByAnother); + assertNull(c1.current); assertEquals("C", c1.next.value); assertEquals("[A, C]", list.toString()); @@ -629,7 +629,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { list.add(1, (E) "Z"); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(1, c1.nextIndex); assertEquals("B", c1.current.value); assertEquals("Z", c1.next.value); @@ -654,7 +654,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { list.add(1, (E) "Z"); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(1, c1.nextIndex); assertEquals("A", c1.current.value); assertEquals("Z", c1.next.value); @@ -680,7 +680,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { list.add(1, (E) "Z"); - assertEquals(false, c1.nextIndexValid); + assertFalse(c1.nextIndexValid); assertEquals("B", c1.current.value); assertEquals("C", c1.next.value); @@ -706,9 +706,9 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { c1.add((E) "Z"); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(2, c1.nextIndex); - assertEquals(null, c1.current); + assertNull(c1.current); assertEquals("B", c1.next.value); assertEquals("[A, Z, B, C]", list.toString()); @@ -730,10 +730,10 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { c1.add((E) "Z"); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(3, c1.nextIndex); - assertEquals(false, c1.currentRemovedByAnother); - assertEquals(null, c1.current); + assertFalse(c1.currentRemovedByAnother); + assertNull(c1.current); assertEquals("C", c1.next.value); assertEquals("[A, B, Z, C]", list.toString()); @@ -755,9 +755,9 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { list.remove(1); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(1, c1.nextIndex); - assertEquals(null, c1.current); + assertNull(c1.current); assertEquals("C", c1.next.value); assertEquals("[A, C]", list.toString()); @@ -780,7 +780,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { c1.set((E) "Z"); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(1, c1.nextIndex); assertEquals("Z", c1.current.value); assertEquals("Z", c1.next.value); @@ -806,7 +806,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { c1.set((E) "Z"); - assertEquals(true, c1.nextIndexValid); + assertTrue(c1.nextIndexValid); assertEquals(2, c1.nextIndex); assertEquals("Z", c1.current.value); assertEquals("C", c1.next.value); @@ -822,66 +822,66 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { @SuppressWarnings("unchecked") public void testEqualsAndHashCode() { - assertTrue(list.equals(list)); + assertEquals(list, list); assertEquals(list.hashCode(), list.hashCode()); list.add((E) "A"); - assertTrue(list.equals(list)); + assertEquals(list, list); assertEquals(list.hashCode(), list.hashCode()); final CursorableLinkedList list2 = new CursorableLinkedList<>(); - assertTrue(!list.equals(list2)); - assertTrue(!list2.equals(list)); + assertFalse(list.equals(list2)); + assertFalse(list2.equals(list)); final java.util.List list3 = new java.util.LinkedList<>(); - assertTrue(!list.equals(list3)); - assertTrue(!list3.equals(list)); - assertTrue(list2.equals(list3)); - assertTrue(list3.equals(list2)); + assertFalse(list.equals(list3)); + assertFalse(list3.equals(list)); + assertEquals(list2, list3); + assertEquals(list3, list2); assertEquals(list2.hashCode(), list3.hashCode()); list2.add((E) "A"); - assertTrue(list.equals(list2)); - assertTrue(list2.equals(list)); - assertTrue(!list2.equals(list3)); - assertTrue(!list3.equals(list2)); + assertEquals(list, list2); + assertEquals(list2, list); + assertFalse(list2.equals(list3)); + assertFalse(list3.equals(list2)); list3.add((E) "A"); - assertTrue(list2.equals(list3)); - assertTrue(list3.equals(list2)); + assertEquals(list2, list3); + assertEquals(list3, list2); assertEquals(list2.hashCode(), list3.hashCode()); list.add((E) "B"); - assertTrue(list.equals(list)); - assertTrue(!list.equals(list2)); - assertTrue(!list2.equals(list)); - assertTrue(!list.equals(list3)); - assertTrue(!list3.equals(list)); + assertEquals(list, list); + assertFalse(list.equals(list2)); + assertFalse(list2.equals(list)); + assertFalse(list.equals(list3)); + assertFalse(list3.equals(list)); list2.add((E) "B"); list3.add((E) "B"); - assertTrue(list.equals(list)); - assertTrue(list.equals(list2)); - assertTrue(list2.equals(list)); - assertTrue(list2.equals(list3)); - assertTrue(list3.equals(list2)); + assertEquals(list, list); + assertEquals(list, list2); + assertEquals(list2, list); + assertEquals(list2, list3); + assertEquals(list3, list2); assertEquals(list2.hashCode(), list3.hashCode()); list.add((E) "C"); list2.add((E) "C"); list3.add((E) "C"); - assertTrue(list.equals(list)); - assertTrue(list.equals(list2)); - assertTrue(list2.equals(list)); - assertTrue(list2.equals(list3)); - assertTrue(list3.equals(list2)); + assertEquals(list, list); + assertEquals(list, list2); + assertEquals(list2, list); + assertEquals(list2, list3); + assertEquals(list3, list2); assertEquals(list.hashCode(), list2.hashCode()); assertEquals(list2.hashCode(), list3.hashCode()); list.add((E) "D"); list2.addFirst((E) "D"); - assertTrue(list.equals(list)); - assertTrue(!list.equals(list2)); - assertTrue(!list2.equals(list)); + assertEquals(list, list); + assertFalse(list.equals(list2)); + assertFalse(list2.equals(list)); } @SuppressWarnings("unchecked") @@ -939,11 +939,11 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { public void testIsEmpty() { assertTrue(list.isEmpty()); list.add((E) "element"); - assertTrue(!list.isEmpty()); + assertFalse(list.isEmpty()); list.remove("element"); assertTrue(list.isEmpty()); list.add((E) "element"); - assertTrue(!list.isEmpty()); + assertFalse(list.isEmpty()); list.clear(); assertTrue(list.isEmpty()); } @@ -966,7 +966,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals("4", it.next()); assertTrue(it.hasNext()); assertEquals("5", it.next()); - assertTrue(!it.hasNext()); + assertFalse(it.hasNext()); it = list.iterator(); assertTrue(it.hasNext()); @@ -989,7 +989,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals("5", it.next()); it.remove(); assertEquals("[]", list.toString()); - assertTrue(!it.hasNext()); + assertFalse(it.hasNext()); } @SuppressWarnings("unchecked") @@ -1001,7 +1001,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { list.add((E) "5"); final ListIterator it = list.listIterator(); assertTrue(it.hasNext()); - assertTrue(!it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals(-1, it.previousIndex()); assertEquals(0, it.nextIndex()); assertEquals("1", it.next()); @@ -1011,7 +1011,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals(1, it.nextIndex()); assertEquals("1", it.previous()); assertTrue(it.hasNext()); - assertTrue(!it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals(-1, it.previousIndex()); assertEquals(0, it.nextIndex()); assertEquals("1", it.next()); @@ -1045,7 +1045,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals(3, it.previousIndex()); assertEquals(4, it.nextIndex()); assertEquals("5", it.next()); - assertTrue(!it.hasNext()); + assertFalse(it.hasNext()); assertTrue(it.hasPrevious()); assertEquals(4, it.previousIndex()); assertEquals(5, it.nextIndex()); @@ -1071,7 +1071,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals(1, it.nextIndex()); assertEquals("1", it.previous()); assertTrue(it.hasNext()); - assertTrue(!it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals(-1, it.previousIndex()); assertEquals(0, it.nextIndex()); } @@ -1125,7 +1125,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertEquals("1", it.previous()); it.remove(); assertEquals("[3, 4, 5]", list.toString()); - assertTrue(!it.hasPrevious()); + assertFalse(it.hasPrevious()); assertEquals("3", it.next()); it.remove(); assertEquals("[4, 5]", list.toString()); @@ -1179,7 +1179,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertTrue(list.removeAll(set)); assertEquals("[1, 3, 5]", list.toString()); - assertTrue(!list.removeAll(set)); + assertFalse(list.removeAll(set)); } @SuppressWarnings("unchecked") @@ -1215,12 +1215,12 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { list.add((E) "4"); list.add((E) "5"); assertEquals("[1, 1, 2, 3, 4, 5, 2, 3, 4, 5]", list.toString()); - assertTrue(!list.remove("6")); + assertFalse(list.remove("6")); assertTrue(list.remove("5")); assertEquals("[1, 1, 2, 3, 4, 2, 3, 4, 5]", list.toString()); assertTrue(list.remove("5")); assertEquals("[1, 1, 2, 3, 4, 2, 3, 4]", list.toString()); - assertTrue(!list.remove("5")); + assertFalse(list.remove("5")); assertTrue(list.remove("1")); assertEquals("[1, 2, 3, 4, 2, 3, 4]", list.toString()); assertTrue(list.remove("1")); @@ -1261,7 +1261,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { assertTrue(list.retainAll(set)); assertEquals("[2, 2, 4, 4]", list.toString()); - assertTrue(!list.retainAll(set)); + assertFalse(list.retainAll(set)); } @SuppressWarnings("unchecked") @@ -1409,7 +1409,7 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { final String[] elts4 = new String[3]; final String[] elts4b = list.toArray(elts4); - assertTrue(elts4 != elts4b); + assertNotSame(elts4, elts4b); assertEquals("1", elts4b[0]); assertEquals("2", elts4b[1]); assertEquals("3", elts4b[2]); @@ -1436,9 +1436,9 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { final java.io.ObjectInputStream in = new java.io.ObjectInputStream(bufin); final Object list2 = in.readObject(); - assertTrue(list != list2); - assertTrue(list2.equals(list)); - assertTrue(list.equals(list2)); + assertNotSame(list, list2); + assertEquals(list2, list); + assertEquals(list, list2); } @SuppressWarnings("unchecked") @@ -1458,9 +1458,9 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { final java.io.ObjectInputStream in = new java.io.ObjectInputStream(bufin); final Object list2 = in.readObject(); - assertTrue(list != list2); - assertTrue(list2.equals(list)); - assertTrue(list.equals(list2)); + assertNotSame(list, list2); + assertEquals(list2, list); + assertEquals(list, list2); } @SuppressWarnings("unchecked") @@ -1481,9 +1481,9 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { final java.io.ObjectInputStream in = new java.io.ObjectInputStream(bufin); final Object list2 = in.readObject(); - assertTrue(list != list2); - assertTrue(list2.equals(list)); - assertTrue(list.equals(list2)); + assertNotSame(list, list2); + assertEquals(list2, list); + assertEquals(list, list2); } /** diff --git a/src/test/java/org/apache/commons/collections4/list/GrowthListTest.java b/src/test/java/org/apache/commons/collections4/list/GrowthListTest.java index d001b524d..46e0f8f54 100644 --- a/src/test/java/org/apache/commons/collections4/list/GrowthListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/GrowthListTest.java @@ -63,7 +63,7 @@ public class GrowthListTest extends AbstractListTest { assertEquals(0, grower.size()); grower.add(1, one); assertEquals(2, grower.size()); - assertEquals(null, grower.get(0)); + assertNull(grower.get(0)); assertEquals(one, grower.get(1)); } @@ -77,7 +77,7 @@ public class GrowthListTest extends AbstractListTest { assertEquals(0, grower.size()); grower.addAll(1, coll); assertEquals(3, grower.size()); - assertEquals(null, grower.get(0)); + assertNull(grower.get(0)); assertEquals(one, grower.get(1)); assertEquals(two, grower.get(2)); } @@ -88,7 +88,7 @@ public class GrowthListTest extends AbstractListTest { assertEquals(0, grower.size()); grower.set(1, one); assertEquals(2, grower.size()); - assertEquals(null, grower.get(0)); + assertNull(grower.get(0)); assertEquals(one, grower.get(1)); } diff --git a/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java b/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java index 88e60ebb1..b2fb5b75c 100644 --- a/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java @@ -72,7 +72,7 @@ public class PredicatedListTest extends AbstractListTest { } catch (final IllegalArgumentException e) { // expected } - assertTrue("Collection shouldn't contain illegal element", !list.contains(i)); + assertFalse("Collection shouldn't contain illegal element", list.contains(i)); } @SuppressWarnings("unchecked") @@ -89,10 +89,10 @@ public class PredicatedListTest extends AbstractListTest { } catch (final IllegalArgumentException e) { // expected } - assertTrue("List shouldn't contain illegal element", !list.contains("one")); - assertTrue("List shouldn't contain illegal element", !list.contains("two")); - assertTrue("List shouldn't contain illegal element", !list.contains(Integer.valueOf(3))); - assertTrue("List shouldn't contain illegal element", !list.contains("four")); + assertFalse("List shouldn't contain illegal element", list.contains("one")); + assertFalse("List shouldn't contain illegal element", list.contains("two")); + assertFalse("List shouldn't contain illegal element", list.contains(Integer.valueOf(3))); + assertFalse("List shouldn't contain illegal element", list.contains("four")); } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/apache/commons/collections4/list/TransformedListTest.java b/src/test/java/org/apache/commons/collections4/list/TransformedListTest.java index 2a104f7f2..92da3d80a 100644 --- a/src/test/java/org/apache/commons/collections4/list/TransformedListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/TransformedListTest.java @@ -67,12 +67,12 @@ public class TransformedListTest extends AbstractListTest { for (int i = 0; i < els.length; i++) { list.add(els[i]); assertEquals(i + 1, list.size()); - assertEquals(true, list.contains(Integer.valueOf((String) els[i]))); - assertEquals(false, list.contains(els[i])); + assertTrue(list.contains(Integer.valueOf((String) els[i]))); + assertFalse(list.contains(els[i])); } - assertEquals(false, list.remove(els[0])); - assertEquals(true, list.remove(Integer.valueOf((String) els[0]))); + assertFalse(list.remove(els[0])); + assertTrue(list.remove(Integer.valueOf((String) els[0]))); list.clear(); for (int i = 0; i < els.length; i++) { @@ -116,12 +116,12 @@ public class TransformedListTest extends AbstractListTest { final List list = TransformedList.transformedList(originalList, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, list.size()); for (final Object el : els) { - assertEquals(true, list.contains(Integer.valueOf((String) el))); - assertEquals(false, list.contains(el)); + assertTrue(list.contains(Integer.valueOf((String) el))); + assertFalse(list.contains(el)); } - assertEquals(false, list.remove(els[0])); - assertEquals(true, list.remove(Integer.valueOf((String) els[0]))); + assertFalse(list.remove(els[0])); + assertTrue(list.remove(Integer.valueOf((String) els[0]))); } public void testSubList() { diff --git a/src/test/java/org/apache/commons/collections4/list/TreeListTest.java b/src/test/java/org/apache/commons/collections4/list/TreeListTest.java index c5304356f..078f37a3e 100644 --- a/src/test/java/org/apache/commons/collections4/list/TreeListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/TreeListTest.java @@ -117,7 +117,7 @@ public class TreeListTest extends AbstractListTest { l.add((E) "andres"); l.add((E) "harald"); l.add(0, null); - assertEquals(null, l.get(0)); + assertNull(l.get(0)); assertEquals("hugo", l.get(1)); assertEquals("erna", l.get(2)); assertEquals("daniel", l.get(3)); @@ -135,7 +135,7 @@ public class TreeListTest extends AbstractListTest { l.add((E) "harald"); l.add(0, null); int i = 0; - assertEquals(null, l.get(i++)); + assertNull(l.get(i++)); assertEquals("hugo", l.get(i++)); assertEquals("erna", l.get(i++)); assertEquals("daniel", l.get(i++)); @@ -241,7 +241,7 @@ public class TreeListTest extends AbstractListTest { assertEquals(Integer.valueOf(4), li.next()); assertEquals(Integer.valueOf(4), li.previous()); assertEquals(Integer.valueOf(4), li.next()); - assertEquals(false, li.hasNext()); + assertFalse(li.hasNext()); } public void testBugCollections447() { diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java index 7bcaa3238..69af4e7cd 100644 --- a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java @@ -413,7 +413,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { "isAllowNullValue is not overridden to return false.", values[i] == null || !isAllowNullValue()); - assertTrue("Unknown reason for NullPointer.", false); + fail("Unknown reason for NullPointer."); } } assertEquals("size must reflect number of mappings added.", @@ -532,26 +532,22 @@ public abstract class AbstractMapTest extends AbstractObjectTest { */ public void testMakeMap() { final Map em = makeObject(); - assertTrue("failure in test: makeEmptyMap must return a non-null map.", - em != null); + assertNotNull("failure in test: makeEmptyMap must return a non-null map.", em); final Map em2 = makeObject(); - assertTrue("failure in test: makeEmptyMap must return a non-null map.", - em != null); + assertNotNull("failure in test: makeEmptyMap must return a non-null map.", em); - assertTrue("failure in test: makeEmptyMap must return a new map " + - "with each invocation.", em != em2); + assertNotSame("failure in test: makeEmptyMap must return a new map " + + "with each invocation.", em, em2); final Map fm = makeFullMap(); - assertTrue("failure in test: makeFullMap must return a non-null map.", - fm != null); + assertNotNull("failure in test: makeFullMap must return a non-null map.", fm); final Map fm2 = makeFullMap(); - assertTrue("failure in test: makeFullMap must return a non-null map.", - fm != null); + assertNotNull("failure in test: makeFullMap must return a non-null map.", fm); - assertTrue("failure in test: makeFullMap must return a new map " + - "with each invocation.", fm != fm2); + assertNotSame("failure in test: makeFullMap must return a new map " + + "with each invocation.", fm, fm2); } /** @@ -559,13 +555,11 @@ public abstract class AbstractMapTest extends AbstractObjectTest { */ public void testMapIsEmpty() { resetEmpty(); - assertEquals("Map.isEmpty() should return true with an empty map", - true, getMap().isEmpty()); + assertTrue("Map.isEmpty() should return true with an empty map", getMap().isEmpty()); verify(); resetFull(); - assertEquals("Map.isEmpty() should return false with a non-empty map", - false, getMap().isEmpty()); + assertFalse("Map.isEmpty() should return false with a non-empty map", getMap().isEmpty()); verify(); } @@ -623,8 +617,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { resetEmpty(); for (final Object key : keys) { - assertTrue("Map must not contain key when map is empty", - !getMap().containsKey(key)); + assertFalse("Map must not contain key when map is empty", getMap().containsKey(key)); } verify(); @@ -646,8 +639,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { resetEmpty(); for (final Object value : values) { - assertTrue("Empty map must not contain value", - !getMap().containsValue(value)); + assertFalse("Empty map must not contain value", getMap().containsValue(value)); } verify(); @@ -665,11 +657,11 @@ public abstract class AbstractMapTest extends AbstractObjectTest { */ public void testMapEquals() { resetEmpty(); - assertTrue("Empty maps unequal.", getMap().equals(confirmed)); + assertEquals("Empty maps unequal.", getMap(), confirmed); verify(); resetFull(); - assertTrue("Full maps unequal.", getMap().equals(confirmed)); + assertEquals("Full maps unequal.", getMap(), confirmed); verify(); resetFull(); @@ -678,12 +670,11 @@ public abstract class AbstractMapTest extends AbstractObjectTest { final Iterator iter = confirmed.keySet().iterator(); iter.next(); iter.remove(); - assertTrue("Different maps equal.", !getMap().equals(confirmed)); + assertFalse("Different maps equal.", getMap().equals(confirmed)); resetFull(); - assertTrue("equals(null) returned true.", !getMap().equals(null)); - assertTrue("equals(new Object()) returned true.", - !getMap().equals(new Object())); + assertFalse("equals(null) returned true.", getMap().equals(null)); + assertFalse("equals(new Object()) returned true.", getMap().equals(new Object())); verify(); } @@ -697,8 +688,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { final Object[] values = getSampleValues(); for (final Object key : keys) { - assertTrue("Empty map.get() should return null.", - getMap().get(key) == null); + assertNull("Empty map.get() should return null.", getMap().get(key)); } verify(); @@ -714,12 +704,10 @@ public abstract class AbstractMapTest extends AbstractObjectTest { */ public void testMapHashCode() { resetEmpty(); - assertTrue("Empty maps have different hashCodes.", - getMap().hashCode() == confirmed.hashCode()); + assertEquals("Empty maps have different hashCodes.", getMap().hashCode(), confirmed.hashCode()); resetFull(); - assertTrue("Equal maps have different hashCodes.", - getMap().hashCode() == confirmed.hashCode()); + assertEquals("Equal maps have different hashCodes.", getMap().hashCode(), confirmed.hashCode()); } /** @@ -733,13 +721,11 @@ public abstract class AbstractMapTest extends AbstractObjectTest { */ public void testMapToString() { resetEmpty(); - assertTrue("Empty map toString() should not return null", - getMap().toString() != null); + assertNotNull("Empty map toString() should not return null", getMap().toString()); verify(); resetFull(); - assertTrue("Empty map toString() should not return null", - getMap().toString() != null); + assertNotNull("Empty map toString() should not return null", getMap().toString()); verify(); } @@ -801,7 +787,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { final Object o = getMap().put(keys[i], values[i]); getConfirmed().put(keys[i], values[i]); verify(); - assertTrue("First map.put should return null", o == null); + assertNull("First map.put should return null", o); assertTrue("Map should contain key after put", getMap().containsKey(keys[i])); assertTrue("Map should contain value after put", @@ -821,8 +807,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { // if duplicates are allowed, we're not guaranteed that the value // no longer exists, so don't try checking that. if (!isAllowDuplicateValues()) { - assertTrue("Map should not contain old value after put when changed", - !getMap().containsValue(values[i])); + assertFalse("Map should not contain old value after put when changed", getMap().containsValue(values[i])); } } } else { @@ -860,8 +845,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { // if duplicates are allowed, we're not guaranteed that the value // no longer exists, so don't try checking that. if (!isAllowDuplicateValues()) { - assertTrue("Map should not contain old value after put when changed", - !getMap().containsValue(values[i])); + assertFalse("Map should not contain old value after put when changed", getMap().containsValue(values[i])); } } } else { @@ -990,7 +974,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { final Object[] values = getSampleValues(); for (final Object key : keys) { final Object o = getMap().remove(key); - assertTrue("First map.remove should return null", o == null); + assertNull("First map.remove should return null", o); } verify(); @@ -1106,7 +1090,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { resetFull(); final Set> entrySet = getMap().entrySet(); final Map.Entry entry = entrySet.iterator().next(); - assertEquals(true, entrySet.contains(entry)); + assertTrue(entrySet.contains(entry)); } public void testEntrySetContains2() { @@ -1114,7 +1098,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { final Set> entrySet = getMap().entrySet(); final Map.Entry entry = entrySet.iterator().next(); final Map.Entry test = cloneMapEntry(entry); - assertEquals(true, entrySet.contains(test)); + assertTrue(entrySet.contains(test)); } @SuppressWarnings("unchecked") @@ -1125,7 +1109,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { final HashMap temp = new HashMap<>(); temp.put(entry.getKey(), (V) "A VERY DIFFERENT VALUE"); final Map.Entry test = temp.entrySet().iterator().next(); - assertEquals(false, entrySet.contains(test)); + assertFalse(entrySet.contains(test)); } public void testEntrySetRemove1() { @@ -1138,8 +1122,8 @@ public abstract class AbstractMapTest extends AbstractObjectTest { final Map.Entry entry = entrySet.iterator().next(); final K key = entry.getKey(); - assertEquals(true, entrySet.remove(entry)); - assertEquals(false, getMap().containsKey(key)); + assertTrue(entrySet.remove(entry)); + assertFalse(getMap().containsKey(key)); assertEquals(size - 1, getMap().size()); } @@ -1154,8 +1138,8 @@ public abstract class AbstractMapTest extends AbstractObjectTest { final K key = entry.getKey(); final Map.Entry test = cloneMapEntry(entry); - assertEquals(true, entrySet.remove(test)); - assertEquals(false, getMap().containsKey(key)); + assertTrue(entrySet.remove(test)); + assertFalse(getMap().containsKey(key)); assertEquals(size - 1, getMap().size()); } @@ -1173,8 +1157,8 @@ public abstract class AbstractMapTest extends AbstractObjectTest { temp.put(entry.getKey(), (V) "A VERY DIFFERENT VALUE"); final Map.Entry test = temp.entrySet().iterator().next(); - assertEquals(false, entrySet.remove(test)); - assertEquals(true, getMap().containsKey(key)); + assertFalse(entrySet.remove(test)); + assertTrue(getMap().containsKey(key)); assertEquals(size, getMap().size()); } @@ -1210,9 +1194,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { j++; } assertTrue("values().remove(obj) is broken", j < 10000); - assertTrue( - "Value should have been removed from the underlying map.", - !getMap().containsValue(sampleValue)); + assertFalse("Value should have been removed from the underlying map.", getMap().containsValue(sampleValue)); } } } @@ -1316,9 +1298,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { // if key.remove is unsupported, just skip this test return; } - assertTrue( - "Key should have been removed from the underlying map.", - !getMap().containsKey(sampleKey)); + assertFalse("Key should have been removed from the underlying map.", getMap().containsKey(sampleKey)); } } @@ -1403,9 +1383,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { // if entrySet removal is unsupported, just skip this test return; } - assertTrue( - "Entry should have been removed from the underlying map.", - !getMap().containsKey(sampleKeys[i])); + assertFalse("Entry should have been removed from the underlying map.", getMap().containsKey(sampleKeys[i])); } } @@ -1614,8 +1592,8 @@ public abstract class AbstractMapTest extends AbstractObjectTest { int count = 0; while (it.hasNext()) { final Map.Entry entry = it.next(); - assertEquals(true, AbstractMapTest.this.getMap().containsKey(entry.getKey())); - assertEquals(true, AbstractMapTest.this.getMap().containsValue(entry.getValue())); + assertTrue(AbstractMapTest.this.getMap().containsKey(entry.getKey())); + assertTrue(AbstractMapTest.this.getMap().containsValue(entry.getValue())); if (!isGetStructuralModify()) { assertEquals(AbstractMapTest.this.getMap().get(entry.getKey()), entry.getValue()); } @@ -1654,24 +1632,24 @@ public abstract class AbstractMapTest extends AbstractObjectTest { entry1.setValue(newValue1); entryConfirmed1.setValue(newValue1); assertEquals(newValue1, entry1.getValue()); - assertEquals(true, AbstractMapTest.this.getMap().containsKey(entry1.getKey())); - assertEquals(true, AbstractMapTest.this.getMap().containsValue(newValue1)); + assertTrue(AbstractMapTest.this.getMap().containsKey(entry1.getKey())); + assertTrue(AbstractMapTest.this.getMap().containsValue(newValue1)); assertEquals(newValue1, AbstractMapTest.this.getMap().get(entry1.getKey())); verify(); entry1.setValue(newValue1); entryConfirmed1.setValue(newValue1); assertEquals(newValue1, entry1.getValue()); - assertEquals(true, AbstractMapTest.this.getMap().containsKey(entry1.getKey())); - assertEquals(true, AbstractMapTest.this.getMap().containsValue(newValue1)); + assertTrue(AbstractMapTest.this.getMap().containsKey(entry1.getKey())); + assertTrue(AbstractMapTest.this.getMap().containsValue(newValue1)); assertEquals(newValue1, AbstractMapTest.this.getMap().get(entry1.getKey())); verify(); entry2.setValue(newValue2); entryConfirmed2.setValue(newValue2); assertEquals(newValue2, entry2.getValue()); - assertEquals(true, AbstractMapTest.this.getMap().containsKey(entry2.getKey())); - assertEquals(true, AbstractMapTest.this.getMap().containsValue(newValue2)); + assertTrue(AbstractMapTest.this.getMap().containsKey(entry2.getKey())); + assertTrue(AbstractMapTest.this.getMap().containsValue(newValue2)); assertEquals(newValue2, AbstractMapTest.this.getMap().get(entry2.getKey())); verify(); } @@ -1699,8 +1677,8 @@ public abstract class AbstractMapTest extends AbstractObjectTest { return; } resetFull(); - assertEquals(false, getCollection().remove(null)); - assertEquals(false, getCollection().remove(new Object())); + assertFalse(getCollection().remove(null)); + assertFalse(getCollection().remove(new Object())); } @Override @@ -1956,7 +1934,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { // concurrent modification exceptions. // Because of this we have assertEquals(map, confirmed), and not the other way around. assertEquals("Map should still equal HashMap", map, confirmed); - assertTrue("Map should still equal HashMap", getMap().equals(getConfirmed())); + assertEquals("Map should still equal HashMap", getMap(), getConfirmed()); } public void verifyEntrySet() { diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java index c34f9826c..17ff23683 100644 --- a/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java @@ -116,13 +116,13 @@ public abstract class AbstractOrderedMapTest extends AbstractIterableMapTe public void testNextKey() { resetEmpty(); OrderedMap ordered = getMap(); - assertEquals(null, ordered.nextKey(getOtherKeys()[0])); + assertNull(ordered.nextKey(getOtherKeys()[0])); if (!isAllowNullKey()) { try { - assertEquals(null, ordered.nextKey(null)); // this is allowed too + assertNull(ordered.nextKey(null)); // this is allowed too } catch (final NullPointerException ex) {} } else { - assertEquals(null, ordered.nextKey(null)); + assertNull(ordered.nextKey(null)); } resetFull(); @@ -134,7 +134,7 @@ public abstract class AbstractOrderedMapTest extends AbstractIterableMapTe assertEquals(confirmedObject, ordered.nextKey(confirmedLast)); confirmedLast = confirmedObject; } - assertEquals(null, ordered.nextKey(confirmedLast)); + assertNull(ordered.nextKey(confirmedLast)); if (!isAllowNullKey()) { try { @@ -142,20 +142,20 @@ public abstract class AbstractOrderedMapTest extends AbstractIterableMapTe fail(); } catch (final NullPointerException ex) {} } else { - assertEquals(null, ordered.nextKey(null)); + assertNull(ordered.nextKey(null)); } } public void testPreviousKey() { resetEmpty(); OrderedMap ordered = getMap(); - assertEquals(null, ordered.previousKey(getOtherKeys()[0])); + assertNull(ordered.previousKey(getOtherKeys()[0])); if (!isAllowNullKey()) { try { - assertEquals(null, ordered.previousKey(null)); // this is allowed too + assertNull(ordered.previousKey(null)); // this is allowed too } catch (final NullPointerException ex) {} } else { - assertEquals(null, ordered.previousKey(null)); + assertNull(ordered.previousKey(null)); } resetFull(); @@ -169,7 +169,7 @@ public abstract class AbstractOrderedMapTest extends AbstractIterableMapTe assertEquals(confirmedObject, ordered.previousKey(confirmedLast)); confirmedLast = confirmedObject; } - assertEquals(null, ordered.previousKey(confirmedLast)); + assertNull(ordered.previousKey(confirmedLast)); if (!isAllowNullKey()) { try { @@ -178,7 +178,7 @@ public abstract class AbstractOrderedMapTest extends AbstractIterableMapTe } catch (final NullPointerException ex) {} } else { if (!isAllowNullKey()) { - assertEquals(null, ordered.previousKey(null)); + assertNull(ordered.previousKey(null)); } } } diff --git a/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java b/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java index b2bba12c4..eb909c08d 100644 --- a/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java @@ -52,14 +52,14 @@ public class DefaultedMapTest extends AbstractIterableMapTest { final Map map = new DefaultedMap<>((V) "NULL"); assertEquals(0, map.size()); - assertEquals(false, map.containsKey("NotInMap")); + assertFalse(map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); map.put((K) "Key", (V) "Value"); assertEquals(1, map.size()); - assertEquals(true, map.containsKey("Key")); + assertTrue(map.containsKey("Key")); assertEquals("Value", map.get("Key")); - assertEquals(false, map.containsKey("NotInMap")); + assertFalse(map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); } @@ -70,15 +70,15 @@ public class DefaultedMapTest extends AbstractIterableMapTest { assertEquals(0, map.size()); assertEquals(0, base.size()); - assertEquals(false, map.containsKey("NotInMap")); + assertFalse(map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); map.put((K) "Key", (V) "Value"); assertEquals(1, map.size()); assertEquals(1, base.size()); - assertEquals(true, map.containsKey("Key")); + assertTrue(map.containsKey("Key")); assertEquals("Value", map.get("Key")); - assertEquals(false, map.containsKey("NotInMap")); + assertFalse(map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); } @@ -89,15 +89,15 @@ public class DefaultedMapTest extends AbstractIterableMapTest { assertEquals(0, map.size()); assertEquals(0, base.size()); - assertEquals(false, map.containsKey("NotInMap")); + assertFalse(map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); map.put((K) "Key", (V) "Value"); assertEquals(1, map.size()); assertEquals(1, base.size()); - assertEquals(true, map.containsKey("Key")); + assertTrue(map.containsKey("Key")); assertEquals("Value", map.get("Key")); - assertEquals(false, map.containsKey("NotInMap")); + assertFalse(map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); } @@ -113,16 +113,16 @@ public class DefaultedMapTest extends AbstractIterableMapTest { assertEquals(0, map.size()); assertEquals(0, base.size()); - assertEquals(false, map.containsKey("NotInMap")); + assertFalse(map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); assertEquals("NULL_OBJECT", map.get(Integer.valueOf(0))); map.put((K) "Key", (V) "Value"); assertEquals(1, map.size()); assertEquals(1, base.size()); - assertEquals(true, map.containsKey("Key")); + assertTrue(map.containsKey("Key")); assertEquals("Value", map.get("Key")); - assertEquals(false, map.containsKey("NotInMap")); + assertFalse(map.containsKey("NotInMap")); assertEquals("NULL", map.get("NotInMap")); assertEquals("NULL_OBJECT", map.get(Integer.valueOf(0))); } diff --git a/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java b/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java index 1f540322d..781f20dc3 100644 --- a/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java @@ -66,7 +66,7 @@ public class Flat3MapTest extends AbstractIterableMapTest { final Flat3Map map2 = makeObject(); map2.put((K) "a", (V) "testB"); map2.put((K) "b", (V) "testA"); - assertEquals(false, map1.equals(map2)); + assertFalse(map1.equals(map2)); } @SuppressWarnings("unchecked") @@ -77,7 +77,7 @@ public class Flat3MapTest extends AbstractIterableMapTest { final Flat3Map map2 = makeObject(); map2.put((K) "a", (V) "testB"); map2.put((K) "c", (V) "testA"); - assertEquals(false, map1.equals(map2)); + assertFalse(map1.equals(map2)); } @SuppressWarnings("unchecked") @@ -87,16 +87,16 @@ public class Flat3MapTest extends AbstractIterableMapTest { map.put((K) ONE, (V) TEN); map.put((K) TWO, (V) TWENTY); assertEquals(2, map.size()); - assertEquals(true, map.containsKey(ONE)); - assertEquals(true, map.containsKey(TWO)); + assertTrue(map.containsKey(ONE)); + assertTrue(map.containsKey(TWO)); assertSame(TEN, map.get(ONE)); assertSame(TWENTY, map.get(TWO)); // clone works (size = 2) final Flat3Map cloned = map.clone(); assertEquals(2, cloned.size()); - assertEquals(true, cloned.containsKey(ONE)); - assertEquals(true, cloned.containsKey(TWO)); + assertTrue(cloned.containsKey(ONE)); + assertTrue(cloned.containsKey(TWO)); assertSame(TEN, cloned.get(ONE)); assertSame(TWENTY, cloned.get(TWO)); @@ -105,8 +105,8 @@ public class Flat3MapTest extends AbstractIterableMapTest { map.put((K) TWENTY, (V) TWO); assertEquals(4, map.size()); assertEquals(2, cloned.size()); - assertEquals(true, cloned.containsKey(ONE)); - assertEquals(true, cloned.containsKey(TWO)); + assertTrue(cloned.containsKey(ONE)); + assertTrue(cloned.containsKey(TWO)); assertSame(TEN, cloned.get(ONE)); assertSame(TWENTY, cloned.get(TWO)); } @@ -124,10 +124,10 @@ public class Flat3MapTest extends AbstractIterableMapTest { final Flat3Map cloned = map.clone(); assertEquals(4, map.size()); assertEquals(4, cloned.size()); - assertEquals(true, cloned.containsKey(ONE)); - assertEquals(true, cloned.containsKey(TWO)); - assertEquals(true, cloned.containsKey(TEN)); - assertEquals(true, cloned.containsKey(TWENTY)); + assertTrue(cloned.containsKey(ONE)); + assertTrue(cloned.containsKey(TWO)); + assertTrue(cloned.containsKey(TEN)); + assertTrue(cloned.containsKey(TWENTY)); assertSame(TEN, cloned.get(ONE)); assertSame(TWENTY, cloned.get(TWO)); assertSame(ONE, cloned.get(TEN)); @@ -137,10 +137,10 @@ public class Flat3MapTest extends AbstractIterableMapTest { map.clear(); assertEquals(0, map.size()); assertEquals(4, cloned.size()); - assertEquals(true, cloned.containsKey(ONE)); - assertEquals(true, cloned.containsKey(TWO)); - assertEquals(true, cloned.containsKey(TEN)); - assertEquals(true, cloned.containsKey(TWENTY)); + assertTrue(cloned.containsKey(ONE)); + assertTrue(cloned.containsKey(TWO)); + assertTrue(cloned.containsKey(TEN)); + assertTrue(cloned.containsKey(TWENTY)); assertSame(TEN, cloned.get(ONE)); assertSame(TWENTY, cloned.get(TWO)); assertSame(ONE, cloned.get(TEN)); @@ -179,8 +179,8 @@ public class Flat3MapTest extends AbstractIterableMapTest { in.close(); assertEquals(2, map.size()); assertEquals(2, ser.size()); - assertEquals(true, ser.containsKey(ONE)); - assertEquals(true, ser.containsKey(TWO)); + assertTrue(ser.containsKey(ONE)); + assertTrue(ser.containsKey(TWO)); assertEquals(TEN, ser.get(ONE)); assertEquals(TWENTY, ser.get(TWO)); } @@ -204,10 +204,10 @@ public class Flat3MapTest extends AbstractIterableMapTest { in.close(); assertEquals(4, map.size()); assertEquals(4, ser.size()); - assertEquals(true, ser.containsKey(ONE)); - assertEquals(true, ser.containsKey(TWO)); - assertEquals(true, ser.containsKey(TEN)); - assertEquals(true, ser.containsKey(TWENTY)); + assertTrue(ser.containsKey(ONE)); + assertTrue(ser.containsKey(TWO)); + assertTrue(ser.containsKey(TEN)); + assertTrue(ser.containsKey(TWENTY)); assertEquals(TEN, ser.get(ONE)); assertEquals(TWENTY, ser.get(TWO)); assertEquals(ONE, ser.get(TEN)); @@ -225,9 +225,9 @@ public class Flat3MapTest extends AbstractIterableMapTest { final Map.Entry entry = it.next(); entry.setValue((V) "NewValue"); assertEquals(3, map.size()); - assertEquals(true, map.containsKey(ONE)); - assertEquals(true, map.containsKey(TWO)); - assertEquals(true, map.containsKey(THREE)); + assertTrue(map.containsKey(ONE)); + assertTrue(map.containsKey(TWO)); + assertTrue(map.containsKey(THREE)); assertEquals("NewValue", map.get(ONE)); assertEquals(TWENTY, map.get(TWO)); assertEquals(THIRTY, map.get(THREE)); @@ -245,9 +245,9 @@ public class Flat3MapTest extends AbstractIterableMapTest { final Map.Entry entry = it.next(); entry.setValue((V) "NewValue"); assertEquals(3, map.size()); - assertEquals(true, map.containsKey(ONE)); - assertEquals(true, map.containsKey(TWO)); - assertEquals(true, map.containsKey(THREE)); + assertTrue(map.containsKey(ONE)); + assertTrue(map.containsKey(TWO)); + assertTrue(map.containsKey(THREE)); assertEquals(TEN, map.get(ONE)); assertEquals("NewValue", map.get(TWO)); assertEquals(THIRTY, map.get(THREE)); @@ -266,9 +266,9 @@ public class Flat3MapTest extends AbstractIterableMapTest { final Map.Entry entry = it.next(); entry.setValue((V) "NewValue"); assertEquals(3, map.size()); - assertEquals(true, map.containsKey(ONE)); - assertEquals(true, map.containsKey(TWO)); - assertEquals(true, map.containsKey(THREE)); + assertTrue(map.containsKey(ONE)); + assertTrue(map.containsKey(TWO)); + assertTrue(map.containsKey(THREE)); assertEquals(TEN, map.get(ONE)); assertEquals(TWENTY, map.get(TWO)); assertEquals("NewValue", map.get(THREE)); @@ -285,9 +285,9 @@ public class Flat3MapTest extends AbstractIterableMapTest { it.next(); it.setValue((V) "NewValue"); assertEquals(3, map.size()); - assertEquals(true, map.containsKey(ONE)); - assertEquals(true, map.containsKey(TWO)); - assertEquals(true, map.containsKey(THREE)); + assertTrue(map.containsKey(ONE)); + assertTrue(map.containsKey(TWO)); + assertTrue(map.containsKey(THREE)); assertEquals("NewValue", map.get(ONE)); assertEquals(TWENTY, map.get(TWO)); assertEquals(THIRTY, map.get(THREE)); @@ -305,9 +305,9 @@ public class Flat3MapTest extends AbstractIterableMapTest { it.next(); it.setValue((V) "NewValue"); assertEquals(3, map.size()); - assertEquals(true, map.containsKey(ONE)); - assertEquals(true, map.containsKey(TWO)); - assertEquals(true, map.containsKey(THREE)); + assertTrue(map.containsKey(ONE)); + assertTrue(map.containsKey(TWO)); + assertTrue(map.containsKey(THREE)); assertEquals(TEN, map.get(ONE)); assertEquals("NewValue", map.get(TWO)); assertEquals(THIRTY, map.get(THREE)); @@ -326,9 +326,9 @@ public class Flat3MapTest extends AbstractIterableMapTest { it.next(); it.setValue((V) "NewValue"); assertEquals(3, map.size()); - assertEquals(true, map.containsKey(ONE)); - assertEquals(true, map.containsKey(TWO)); - assertEquals(true, map.containsKey(THREE)); + assertTrue(map.containsKey(ONE)); + assertTrue(map.containsKey(TWO)); + assertTrue(map.containsKey(THREE)); assertEquals(TEN, map.get(ONE)); assertEquals(TWENTY, map.get(TWO)); assertEquals("NewValue", map.get(THREE)); @@ -354,7 +354,7 @@ public class Flat3MapTest extends AbstractIterableMapTest { assertEquals(2, map.size()); assertEquals("one", map.get("A")); assertEquals("two", map.get("B")); - assertEquals(null, map.get("C")); + assertNull(map.get("C")); } @Override @@ -719,7 +719,7 @@ public class Flat3MapTest extends AbstractIterableMapTest { m.put(TWO, TWO); m.put(null, THREE); final boolean contains = m.containsKey(null); - assertEquals(true, contains); + assertTrue(contains); } public void testContainsKey2() { @@ -728,7 +728,7 @@ public class Flat3MapTest extends AbstractIterableMapTest { m.put(ONE, ONE); m.put(null, TWO); final boolean contains = m.containsKey(null); - assertEquals(true, contains); + assertTrue(contains); } public void testContainsKey3() { @@ -736,7 +736,7 @@ public class Flat3MapTest extends AbstractIterableMapTest { m.put(null, ONE); final boolean contains = m.containsKey(null); - assertEquals(true, contains); + assertTrue(contains); } public void testContainsValue1() { @@ -746,7 +746,7 @@ public class Flat3MapTest extends AbstractIterableMapTest { m.put(TWO, TWO); m.put(THREE, null); final boolean contains = m.containsValue(null); - assertEquals(true, contains); + assertTrue(contains); } public void testContainsValue2() { @@ -755,7 +755,7 @@ public class Flat3MapTest extends AbstractIterableMapTest { m.put(ONE, ONE); m.put(TWO, null); final boolean contains = m.containsValue(null); - assertEquals(true, contains); + assertTrue(contains); } public void testContainsValue3() { @@ -763,7 +763,7 @@ public class Flat3MapTest extends AbstractIterableMapTest { m.put(ONE, null); final boolean contains = m.containsValue(null); - assertEquals(true, contains); + assertTrue(contains); } public void testPut1() { @@ -793,7 +793,7 @@ public class Flat3MapTest extends AbstractIterableMapTest { m.put(null, THREE); final Object old = m.put(null, ONE); assertEquals(THREE, old); - assertEquals(null, m.get(ONE)); + assertNull(m.get(ONE)); } public void testPut4() { diff --git a/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java b/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java index aebd2fb47..bb918f096 100644 --- a/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java @@ -124,17 +124,17 @@ public class LRUMapTest extends AbstractOrderedMapTest { final LRUMap map = new LRUMap<>(2); assertEquals(0, map.size()); - assertEquals(false, map.isFull()); + assertFalse(map.isFull()); assertEquals(2, map.maxSize()); map.put(keys[0], values[0]); assertEquals(1, map.size()); - assertEquals(false, map.isFull()); + assertFalse(map.isFull()); assertEquals(2, map.maxSize()); map.put(keys[1], values[1]); assertEquals(2, map.size()); - assertEquals(true, map.isFull()); + assertTrue(map.isFull()); assertEquals(2, map.maxSize()); kit = map.keySet().iterator(); assertSame(keys[0], kit.next()); @@ -145,7 +145,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { map.put(keys[2], values[2]); assertEquals(2, map.size()); - assertEquals(true, map.isFull()); + assertTrue(map.isFull()); assertEquals(2, map.maxSize()); kit = map.keySet().iterator(); assertSame(keys[1], kit.next()); @@ -156,7 +156,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { map.put(keys[2], values[0]); assertEquals(2, map.size()); - assertEquals(true, map.isFull()); + assertTrue(map.isFull()); assertEquals(2, map.maxSize()); kit = map.keySet().iterator(); assertSame(keys[1], kit.next()); @@ -167,7 +167,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { map.put(keys[1], values[3]); assertEquals(2, map.size()); - assertEquals(true, map.isFull()); + assertTrue(map.isFull()); assertEquals(2, map.maxSize()); kit = map.keySet().iterator(); assertSame(keys[2], kit.next()); @@ -339,9 +339,9 @@ public class LRUMapTest extends AbstractOrderedMapTest { assertEquals("a", map.value); assertEquals("C", map.entry.getKey()); // entry is reused assertEquals("c", map.entry.getValue()); // entry is reused - assertEquals(false, map.containsKey("A")); - assertEquals(true, map.containsKey("B")); - assertEquals(true, map.containsKey("C")); + assertFalse(map.containsKey("A")); + assertTrue(map.containsKey("B")); + assertTrue(map.containsKey("C")); } static class MockLRUMapSubclass extends LRUMap { @@ -377,9 +377,9 @@ public class LRUMapTest extends AbstractOrderedMapTest { map.put((K) "C", (V) "c"); // should remove oldest, which is A=a, but this is blocked assertEquals(3, map.size()); assertEquals(2, map.maxSize()); - assertEquals(true, map.containsKey("A")); - assertEquals(true, map.containsKey("B")); - assertEquals(true, map.containsKey("C")); + assertTrue(map.containsKey("A")); + assertTrue(map.containsKey("B")); + assertTrue(map.containsKey("C")); } @SuppressWarnings("unchecked") @@ -393,9 +393,9 @@ public class LRUMapTest extends AbstractOrderedMapTest { map.put((K) "C", (V) "c"); // should remove oldest, which is A=a, but this is blocked assertEquals(3, map.size()); assertEquals(2, map.maxSize()); - assertEquals(true, map.containsKey("A")); - assertEquals(true, map.containsKey("B")); - assertEquals(true, map.containsKey("C")); + assertTrue(map.containsKey("A")); + assertTrue(map.containsKey("B")); + assertTrue(map.containsKey("C")); } static class MockLRUMapSubclassBlocksRemove extends LRUMap { @@ -425,9 +425,9 @@ public class LRUMapTest extends AbstractOrderedMapTest { map.put((K) "C", (V) "c"); // should remove oldest, which is A=a but this is blocked - so advance to B=b assertEquals(2, map.size()); assertEquals(2, map.maxSize()); - assertEquals(true, map.containsKey("A")); - assertEquals(false, map.containsKey("B")); - assertEquals(true, map.containsKey("C")); + assertTrue(map.containsKey("A")); + assertFalse(map.containsKey("B")); + assertTrue(map.containsKey("C")); } static class MockLRUMapSubclassFirstBlocksRemove extends LRUMap { @@ -486,7 +486,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { assertEquals(4, map.data.length); assertEquals(3, map.size); - assertEquals(null, map.header.next); + assertNull(map.header.next); assertEquals(one, map.header.after.key); // LRU assertEquals(two, map.header.after.after.key); assertEquals(three, map.header.after.after.after.key); // MRU @@ -498,7 +498,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { assertEquals(4, map.data.length); assertEquals(3, map.size); - assertEquals(null, map.header.next); + assertNull(map.header.next); assertEquals(two, map.header.after.key); // LRU assertEquals(three, map.header.after.after.key); assertEquals(four, map.header.after.after.after.key); // MRU @@ -510,7 +510,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { assertEquals(4, map.data.length); assertEquals(3, map.size); - assertEquals(null, map.header.next); + assertNull(map.header.next); assertEquals(two, map.header.after.key); // LRU assertEquals(four, map.header.after.after.key); assertEquals(three, map.header.after.after.after.key); // MRU @@ -522,7 +522,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { assertEquals(4, map.data.length); assertEquals(3, map.size); - assertEquals(null, map.header.next); + assertNull(map.header.next); assertEquals(four, map.header.after.key); // LRU assertEquals(three, map.header.after.after.key); assertEquals(five, map.header.after.after.after.key); // MRU @@ -535,7 +535,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { assertEquals(4, map.data.length); assertEquals(3, map.size); - assertEquals(null, map.header.next); + assertNull(map.header.next); assertEquals(four, map.header.after.key); // LRU assertEquals(three, map.header.after.after.key); assertEquals(five, map.header.after.after.after.key); // MRU @@ -547,7 +547,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { assertEquals(4, map.data.length); assertEquals(3, map.size); - assertEquals(null, map.header.next); + assertNull(map.header.next); assertEquals(three, map.header.after.key); // LRU assertEquals(five, map.header.after.after.key); assertEquals(six, map.header.after.after.after.key); // MRU diff --git a/src/test/java/org/apache/commons/collections4/map/LazyMapTest.java b/src/test/java/org/apache/commons/collections4/map/LazyMapTest.java index c9833cc1a..700b3d157 100644 --- a/src/test/java/org/apache/commons/collections4/map/LazyMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LazyMapTest.java @@ -65,7 +65,7 @@ public class LazyMapTest extends AbstractIterableMapTest { map = lazyMap(new HashMap(), FactoryUtils.nullFactory()); final Object o = map.get("Five"); - assertEquals(null, o); + assertNull(o); assertEquals(1, map.size()); } 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 f5935b31e..9e95343e7 100644 --- a/src/test/java/org/apache/commons/collections4/map/LazySortedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LazySortedMapTest.java @@ -80,7 +80,7 @@ public class LazySortedMapTest extends AbstractSortedMapTest { map = lazySortedMap(new TreeMap(), FactoryUtils.nullFactory()); final Number o = map.get(5); - assertEquals(null, o); + assertNull(o); assertEquals(1, map.size()); } @@ -100,8 +100,7 @@ public class LazySortedMapTest extends AbstractSortedMapTest { "B", map.subMap("A", "C").lastKey()); final Comparator c = map.comparator(); - assertTrue("natural order, so comparator should be null", - c == null); + assertNull("natural order, so comparator should be null", c); } public void testReverseSortOrder() { @@ -119,8 +118,7 @@ public class LazySortedMapTest extends AbstractSortedMapTest { "B", map.subMap("C", "A").lastKey()); final Comparator c = map.comparator(); - assertTrue("natural order, so comparator should be null", - c == reverseStringComparator); + assertSame("natural order, so comparator should be null", c, reverseStringComparator); } public void testTransformerDecorate() { diff --git a/src/test/java/org/apache/commons/collections4/map/LinkedMapTest.java b/src/test/java/org/apache/commons/collections4/map/LinkedMapTest.java index 5e4cc29df..550586f7f 100644 --- a/src/test/java/org/apache/commons/collections4/map/LinkedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LinkedMapTest.java @@ -219,7 +219,7 @@ public class LinkedMapTest extends AbstractOrderedMapTest { final Object value = lm.get(key); assertEquals(value, lm.remove(i)); list.remove(i); - assertEquals(false, lm.containsKey(key)); + assertFalse(lm.containsKey(key)); } } diff --git a/src/test/java/org/apache/commons/collections4/map/ListOrderedMap2Test.java b/src/test/java/org/apache/commons/collections4/map/ListOrderedMap2Test.java index 4717165f8..d45dc8f61 100644 --- a/src/test/java/org/apache/commons/collections4/map/ListOrderedMap2Test.java +++ b/src/test/java/org/apache/commons/collections4/map/ListOrderedMap2Test.java @@ -149,7 +149,7 @@ public class ListOrderedMap2Test extends AbstractOrderedMapTest { final Object value = lom.get(key); assertEquals(value, lom.remove(i)); list.remove(i); - assertEquals(false, lom.containsKey(key)); + assertFalse(lom.containsKey(key)); } } diff --git a/src/test/java/org/apache/commons/collections4/map/ListOrderedMapTest.java b/src/test/java/org/apache/commons/collections4/map/ListOrderedMapTest.java index 2061ea6b3..a1ff9b455 100644 --- a/src/test/java/org/apache/commons/collections4/map/ListOrderedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/ListOrderedMapTest.java @@ -180,7 +180,7 @@ public class ListOrderedMapTest extends AbstractOrderedMapTest { final Object value = lom.get(key); assertEquals(value, lom.remove(i)); list.remove(i); - assertEquals(false, lom.containsKey(key)); + assertFalse(lom.containsKey(key)); } } diff --git a/src/test/java/org/apache/commons/collections4/map/MultiKeyMapTest.java b/src/test/java/org/apache/commons/collections4/map/MultiKeyMapTest.java index 143136767..9251662a5 100644 --- a/src/test/java/org/apache/commons/collections4/map/MultiKeyMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/MultiKeyMapTest.java @@ -116,18 +116,18 @@ public class MultiKeyMapTest extends AbstractIterableMapTest(null, null), null)); + assertNull(map.put(new MultiKey(null, null), null)); try { map.put(null, (V) new Object()); fail(); @@ -147,39 +147,39 @@ public class MultiKeyMapTest extends AbstractIterableMapTest extends AbstractIterableMapTest key : keys) { switch (key.size()) { case 2: - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1))); - assertEquals(false, multimap.containsKey(null, key.getKey(1))); - assertEquals(false, multimap.containsKey(key.getKey(0), null)); - assertEquals(false, multimap.containsKey(null, null)); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null)); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, null)); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, null, null)); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1))); + assertFalse(multimap.containsKey(null, key.getKey(1))); + assertFalse(multimap.containsKey(key.getKey(0), null)); + assertFalse(multimap.containsKey(null, null)); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), null)); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), null, null)); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), null, null, null)); break; case 3: - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); - assertEquals(false, multimap.containsKey(null, key.getKey(1), key.getKey(2))); - assertEquals(false, multimap.containsKey(key.getKey(0), null, key.getKey(2))); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null)); - assertEquals(false, multimap.containsKey(null, null, null)); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null)); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null, null)); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); + assertFalse(multimap.containsKey(null, key.getKey(1), key.getKey(2))); + assertFalse(multimap.containsKey(key.getKey(0), null, key.getKey(2))); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), null)); + assertFalse(multimap.containsKey(null, null, null)); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null)); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null, null)); break; case 4: - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); - assertEquals(false, multimap.containsKey(null, key.getKey(1), key.getKey(2), key.getKey(3))); - assertEquals(false, multimap.containsKey(key.getKey(0), null, key.getKey(2), key.getKey(3))); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, key.getKey(3))); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null)); - assertEquals(false, multimap.containsKey(null, null, null, null)); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null)); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); + assertFalse(multimap.containsKey(null, key.getKey(1), key.getKey(2), key.getKey(3))); + assertFalse(multimap.containsKey(key.getKey(0), null, key.getKey(2), key.getKey(3))); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), null, key.getKey(3))); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null)); + assertFalse(multimap.containsKey(null, null, null, null)); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null)); break; case 5: - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); - assertEquals(false, multimap.containsKey(null, key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); - assertEquals(false, multimap.containsKey(key.getKey(0), null, key.getKey(2), key.getKey(3), key.getKey(4))); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), null, key.getKey(3), key.getKey(4))); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null, key.getKey(4))); - assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null)); - assertEquals(false, multimap.containsKey(null, null, null, null, null)); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); + assertFalse(multimap.containsKey(null, key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); + assertFalse(multimap.containsKey(key.getKey(0), null, key.getKey(2), key.getKey(3), key.getKey(4))); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), null, key.getKey(3), key.getKey(4))); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), null, key.getKey(4))); + assertFalse(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null)); + assertFalse(multimap.containsKey(null, null, null, null, null)); break; default: fail("Invalid key size"); @@ -248,48 +248,48 @@ public class MultiKeyMapTest extends AbstractIterableMapTest(key.getKey(0), key.getKey(1)))); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1))); + assertTrue(multimap.containsKey(new MultiKey<>(key.getKey(0), key.getKey(1)))); assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), null)); assertEquals(1, multimap.size()); - assertEquals(null, multimap.get(key.getKey(0), key.getKey(1))); - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1))); + assertNull(multimap.get(key.getKey(0), key.getKey(1))); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1))); break; case 3: - assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), value)); + assertNull(multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), value)); assertEquals(1, multimap.size()); assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2))); - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); - assertEquals(true, multimap.containsKey(new MultiKey<>(key.getKey(0), key.getKey(1), key.getKey(2)))); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); + assertTrue(multimap.containsKey(new MultiKey<>(key.getKey(0), key.getKey(1), key.getKey(2)))); assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), null)); assertEquals(1, multimap.size()); - assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2))); - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); + assertNull(multimap.get(key.getKey(0), key.getKey(1), key.getKey(2))); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2))); break; case 4: - assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), value)); + assertNull(multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), value)); assertEquals(1, multimap.size()); assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); - assertEquals(true, multimap.containsKey(new MultiKey<>(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)))); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); + assertTrue(multimap.containsKey(new MultiKey<>(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)))); assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null)); assertEquals(1, multimap.size()); - assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); + assertNull(multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))); break; case 5: - assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4), value)); + assertNull(multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4), value)); assertEquals(1, multimap.size()); assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); - assertEquals(true, multimap.containsKey(new MultiKey<>(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)))); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); + assertTrue(multimap.containsKey(new MultiKey<>(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)))); assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4), null)); assertEquals(1, multimap.size()); - assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); - assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); + assertNull(multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); + assertTrue(multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))); break; default: fail("Invalid key size"); @@ -327,36 +327,36 @@ public class MultiKeyMapTest extends AbstractIterableMapTest extends AbstractIterableMapTest, V> it = multimap.mapIterator(); it.hasNext();) { final MultiKey key = it.next(); - assertEquals(false, I1.equals(key.getKey(0))); + assertFalse(I1.equals(key.getKey(0))); } } @@ -386,7 +386,7 @@ public class MultiKeyMapTest extends AbstractIterableMapTest, V> it = multimap.mapIterator(); it.hasNext();) { final MultiKey key = it.next(); - assertEquals(false, I2.equals(key.getKey(0)) && I3.equals(key.getKey(1))); + assertFalse(I2.equals(key.getKey(0)) && I3.equals(key.getKey(1))); } } @@ -399,7 +399,7 @@ public class MultiKeyMapTest extends AbstractIterableMapTest, V> it = multimap.mapIterator(); it.hasNext();) { final MultiKey key = it.next(); - assertEquals(false, I1.equals(key.getKey(0)) && I1.equals(key.getKey(1)) && I2.equals(key.getKey(2))); + assertFalse(I1.equals(key.getKey(0)) && I1.equals(key.getKey(1)) && I2.equals(key.getKey(2))); } } @@ -412,7 +412,7 @@ public class MultiKeyMapTest extends AbstractIterableMapTest, V> it = multimap.mapIterator(); it.hasNext();) { final MultiKey key = it.next(); - assertEquals(false, I1.equals(key.getKey(0)) && I1.equals(key.getKey(1)) && I2.equals(key.getKey(2)) && key.size() >= 4 && I3.equals(key.getKey(3))); + assertFalse(I1.equals(key.getKey(0)) && I1.equals(key.getKey(1)) && I2.equals(key.getKey(2)) && key.size() >= 4 && I3.equals(key.getKey(3))); } } @@ -433,19 +433,19 @@ public class MultiKeyMapTest extends AbstractIterableMapTest cloned = map.clone(); assertEquals(2, map.size()); - assertEquals(true, cloned.containsKey(I1, I3)); - assertEquals(true, cloned.containsKey(I1, I4)); - assertEquals(false, cloned.containsKey(I1, I2)); + assertTrue(cloned.containsKey(I1, I3)); + assertTrue(cloned.containsKey(I1, I4)); + assertFalse(cloned.containsKey(I1, I2)); cloned.put((K) I1, (K) I5, (V) "1-5"); assertEquals(2, cloned.size()); - assertEquals(true, cloned.containsKey(I1, I4)); - assertEquals(true, cloned.containsKey(I1, I5)); + assertTrue(cloned.containsKey(I1, I4)); + assertTrue(cloned.containsKey(I1, I5)); } @Override diff --git a/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java b/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java index a02b885a3..000b2b5b2 100644 --- a/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java @@ -259,22 +259,22 @@ public class MultiValueMapTest extends AbstractObjectTest { @SuppressWarnings("unchecked") public void testIterator_Key() { final MultiValueMap map = new MultiValueMap<>(); - assertEquals(false, map.iterator("A").hasNext()); + assertFalse(map.iterator("A").hasNext()); map.put((K) "A", "AA"); final Iterator it = map.iterator("A"); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); it.next(); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); } @SuppressWarnings("unchecked") public void testContainsValue_Key() { final MultiValueMap map = new MultiValueMap<>(); - assertEquals(false, map.containsValue("A", "AA")); - assertEquals(false, map.containsValue("B", "BB")); + assertFalse(map.containsValue("A", "AA")); + assertFalse(map.containsValue("B", "BB")); map.put((K) "A", "AA"); - assertEquals(true, map.containsValue("A", "AA")); - assertEquals(false, map.containsValue("A", "AB")); + assertTrue(map.containsValue("A", "AA")); + assertFalse(map.containsValue("A", "AB")); } @SuppressWarnings("unchecked") @@ -294,7 +294,7 @@ public class MultiValueMapTest extends AbstractObjectTest { final MultiValueMap test = MultiValueMap.multiValueMap(new HashMap(), HashSet.class); assertEquals("a", test.put((K) "A", "a")); assertEquals("b", test.put((K) "A", "b")); - assertEquals(null, test.put((K) "A", "a")); + assertNull(test.put((K) "A", "a")); assertEquals(1, test.size()); assertEquals(2, test.size("A")); assertEquals(2, test.totalSize()); @@ -315,10 +315,10 @@ public class MultiValueMapTest extends AbstractObjectTest { assertEquals(4, test.totalSize()); assertEquals(1, test.getCollection("keyA").size()); assertEquals(3, test.getCollection("key").size()); - assertEquals(true, test.containsValue("objectA")); - assertEquals(true, test.containsValue("object0")); - assertEquals(true, test.containsValue("object1")); - assertEquals(true, test.containsValue("object2")); + assertTrue(test.containsValue("objectA")); + assertTrue(test.containsValue("object0")); + assertTrue(test.containsValue("object1")); + assertTrue(test.containsValue("object2")); } @SuppressWarnings("unchecked") @@ -337,10 +337,10 @@ public class MultiValueMapTest extends AbstractObjectTest { assertEquals(1, test.getCollection("keyA").size()); assertEquals(2, test.getCollection("keyX").size()); assertEquals(1, test.getCollection("keyY").size()); - assertEquals(true, test.containsValue("objectA")); - assertEquals(true, test.containsValue("object0")); - assertEquals(true, test.containsValue("object1")); - assertEquals(true, test.containsValue("object2")); + assertTrue(test.containsValue("objectA")); + assertTrue(test.containsValue("object0")); + assertTrue(test.containsValue("object1")); + assertTrue(test.containsValue("object2")); } @SuppressWarnings("unchecked") @@ -348,31 +348,31 @@ public class MultiValueMapTest extends AbstractObjectTest { final MultiValueMap map = new MultiValueMap<>(); Collection coll = (Collection) Arrays.asList("X", "Y", "Z"); - assertEquals(true, map.putAll((K) "A", coll)); + assertTrue(map.putAll((K) "A", coll)); assertEquals(3, map.size("A")); - assertEquals(true, map.containsValue("A", "X")); - assertEquals(true, map.containsValue("A", "Y")); - assertEquals(true, map.containsValue("A", "Z")); + assertTrue(map.containsValue("A", "X")); + assertTrue(map.containsValue("A", "Y")); + assertTrue(map.containsValue("A", "Z")); - assertEquals(false, map.putAll((K) "A", null)); + assertFalse(map.putAll((K) "A", null)); assertEquals(3, map.size("A")); - assertEquals(true, map.containsValue("A", "X")); - assertEquals(true, map.containsValue("A", "Y")); - assertEquals(true, map.containsValue("A", "Z")); + assertTrue(map.containsValue("A", "X")); + assertTrue(map.containsValue("A", "Y")); + assertTrue(map.containsValue("A", "Z")); - assertEquals(false, map.putAll((K) "A", new ArrayList())); + assertFalse(map.putAll((K) "A", new ArrayList())); assertEquals(3, map.size("A")); - assertEquals(true, map.containsValue("A", "X")); - assertEquals(true, map.containsValue("A", "Y")); - assertEquals(true, map.containsValue("A", "Z")); + assertTrue(map.containsValue("A", "X")); + assertTrue(map.containsValue("A", "Y")); + assertTrue(map.containsValue("A", "Z")); coll = (Collection) Arrays.asList("M"); - assertEquals(true, map.putAll((K) "A", coll)); + assertTrue(map.putAll((K) "A", coll)); assertEquals(4, map.size("A")); - assertEquals(true, map.containsValue("A", "X")); - assertEquals(true, map.containsValue("A", "Y")); - assertEquals(true, map.containsValue("A", "Z")); - assertEquals(true, map.containsValue("A", "M")); + assertTrue(map.containsValue("A", "X")); + assertTrue(map.containsValue("A", "Y")); + assertTrue(map.containsValue("A", "Z")); + assertTrue(map.containsValue("A", "M")); } @SuppressWarnings("unchecked") @@ -381,11 +381,11 @@ public class MultiValueMapTest extends AbstractObjectTest { map.put((K) "A", "AA"); map.put((K) "A", "AB"); map.put((K) "A", "AC"); - assertEquals(false, map.removeMapping("C", "CA")); - assertEquals(false, map.removeMapping("A", "AD")); - assertEquals(true, map.removeMapping("A", "AC")); - assertEquals(true, map.removeMapping("A", "AB")); - assertEquals(true, map.removeMapping("A", "AA")); + assertFalse(map.removeMapping("C", "CA")); + assertFalse(map.removeMapping("A", "AD")); + assertTrue(map.removeMapping("A", "AC")); + assertTrue(map.removeMapping("A", "AB")); + assertTrue(map.removeMapping("A", "AA")); assertEquals(new MultiValueMap(), map); } diff --git a/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java b/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java index 287d87dd0..9a046800c 100644 --- a/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java @@ -57,12 +57,10 @@ public class PredicatedMapTest extends AbstractIterableMapTest { @SuppressWarnings("unchecked") public void testEntrySet() { Map map = makeTestMap(); - assertTrue("returned entryset should not be null", - map.entrySet() != null); + assertNotNull("returned entryset should not be null", map.entrySet()); map = decorateMap(new HashMap(), null, null); map.put((K) "oneKey", (V) "oneValue"); - assertTrue("returned entryset should contain one entry", - map.entrySet().size() == 1); + assertEquals("returned entryset should contain one entry", 1, map.entrySet().size()); map = decorateMap(map, null, null); } @@ -83,8 +81,8 @@ public class PredicatedMapTest extends AbstractIterableMapTest { // expected } - assertTrue(!map.containsKey(Integer.valueOf(3))); - assertTrue(!map.containsValue(Integer.valueOf(3))); + assertFalse(map.containsKey(Integer.valueOf(3))); + assertFalse(map.containsValue(Integer.valueOf(3))); final Map map2 = new HashMap<>(); map2.put((K) "A", (V) "a"); diff --git a/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java b/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java index 901362e57..dd2700083 100644 --- a/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java @@ -85,12 +85,10 @@ public class PredicatedSortedMapTest extends AbstractSortedMapTest { @SuppressWarnings("unchecked") public void testEntrySet() { SortedMap map = makeTestMap(); - assertTrue("returned entryset should not be null", - map.entrySet() != null); + assertNotNull("returned entryset should not be null", map.entrySet()); map = decorateMap(new TreeMap(), null, null); map.put((K) "oneKey", (V) "oneValue"); - assertTrue("returned entryset should contain one entry", - map.entrySet().size() == 1); + assertEquals("returned entryset should contain one entry", 1, map.entrySet().size()); map = decorateMap(map, null, null); } @@ -111,8 +109,8 @@ public class PredicatedSortedMapTest extends AbstractSortedMapTest { // expected } - assertTrue(!map.containsKey(Integer.valueOf(3))); - assertTrue(!map.containsValue(Integer.valueOf(3))); + assertFalse(map.containsKey(Integer.valueOf(3))); + assertFalse(map.containsValue(Integer.valueOf(3))); final Map map2 = new HashMap<>(); map2.put((K) "A", (V) "a"); @@ -172,8 +170,7 @@ public class PredicatedSortedMapTest extends AbstractSortedMapTest { "B", map.subMap((K) "A", (K) "C").lastKey()); final Comparator c = map.comparator(); - assertTrue("natural order, so comparator should be null", - c == null); + assertNull("natural order, so comparator should be null", c); } @SuppressWarnings("unchecked") @@ -204,8 +201,7 @@ public class PredicatedSortedMapTest extends AbstractSortedMapTest { "B", map.subMap((K) "C", (K) "A").lastKey()); final Comparator c = map.comparator(); - assertTrue("reverse order, so comparator should be reverseStringComparator", - c == reverseStringComparator); + assertSame("reverse order, so comparator should be reverseStringComparator", c, reverseStringComparator); } @Override diff --git a/src/test/java/org/apache/commons/collections4/map/ReferenceIdentityMapTest.java b/src/test/java/org/apache/commons/collections4/map/ReferenceIdentityMapTest.java index 3389b4c53..d392cb878 100644 --- a/src/test/java/org/apache/commons/collections4/map/ReferenceIdentityMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/ReferenceIdentityMapTest.java @@ -235,28 +235,28 @@ public class ReferenceIdentityMapTest extends AbstractIterableMapTest extends AbstractIterableMapTest entry2 = it.next(); final Map.Entry entry3 = it.next(); - assertEquals(true, entry1.equals(entry2)); - assertEquals(true, entry2.equals(entry1)); - assertEquals(false, entry1.equals(entry3)); + assertTrue(entry1.equals(entry2)); + assertTrue(entry2.equals(entry1)); + assertFalse(entry1.equals(entry3)); } @SuppressWarnings("unchecked") public void testNullHandling() { resetFull(); - assertEquals(null, getMap().get(null)); - assertEquals(false, getMap().containsKey(null)); - assertEquals(false, getMap().containsValue(null)); - assertEquals(null, getMap().remove(null)); - assertEquals(false, getMap().entrySet().contains(null)); - assertEquals(false, getMap().keySet().contains(null)); - assertEquals(false, getMap().values().contains(null)); + assertNull(getMap().get(null)); + assertFalse(getMap().containsKey(null)); + assertFalse(getMap().containsValue(null)); + assertNull(getMap().remove(null)); + assertFalse(getMap().entrySet().contains(null)); + assertFalse(getMap().keySet().contains(null)); + assertFalse(getMap().values().contains(null)); try { getMap().put(null, null); fail(); diff --git a/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java b/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java index 3f67c4ff2..bfaf957e7 100644 --- a/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java @@ -83,13 +83,13 @@ public class ReferenceMapTest extends AbstractIterableMapTest { @SuppressWarnings("unchecked") public void testNullHandling() { resetFull(); - assertEquals(null, map.get(null)); - assertEquals(false, map.containsKey(null)); - assertEquals(false, map.containsValue(null)); - assertEquals(null, map.remove(null)); - assertEquals(false, map.entrySet().contains(null)); - assertEquals(false, map.keySet().contains(null)); - assertEquals(false, map.values().contains(null)); + assertNull(map.get(null)); + assertFalse(map.containsKey(null)); + assertFalse(map.containsValue(null)); + assertNull(map.remove(null)); + assertFalse(map.entrySet().contains(null)); + assertFalse(map.keySet().contains(null)); + assertFalse(map.values().contains(null)); try { map.put(null, null); fail(); diff --git a/src/test/java/org/apache/commons/collections4/map/SingletonMapTest.java b/src/test/java/org/apache/commons/collections4/map/SingletonMapTest.java index 61ba4acf2..81441fae1 100644 --- a/src/test/java/org/apache/commons/collections4/map/SingletonMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/SingletonMapTest.java @@ -98,8 +98,8 @@ public class SingletonMapTest extends AbstractOrderedMapTest { assertEquals(1, map.size()); final SingletonMap cloned = map.clone(); assertEquals(1, cloned.size()); - assertEquals(true, cloned.containsKey(ONE)); - assertEquals(true, cloned.containsValue(TWO)); + assertTrue(cloned.containsKey(ONE)); + assertTrue(cloned.containsValue(TWO)); } public void testKeyValue() { @@ -113,7 +113,7 @@ public class SingletonMapTest extends AbstractOrderedMapTest { public void testBoundedMap() { final SingletonMap map = makeFullMap(); assertEquals(1, map.size()); - assertEquals(true, map.isFull()); + assertTrue(map.isFull()); assertEquals(1, map.maxSize()); assertTrue(map instanceof BoundedMap); } diff --git a/src/test/java/org/apache/commons/collections4/map/StaticBucketMapTest.java b/src/test/java/org/apache/commons/collections4/map/StaticBucketMapTest.java index 26d9208eb..aec45eee7 100644 --- a/src/test/java/org/apache/commons/collections4/map/StaticBucketMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/StaticBucketMapTest.java @@ -68,7 +68,7 @@ public class StaticBucketMapTest extends AbstractIterableMapTest { // loop so we find a string that is in the same bucket as the null for (int i = 'A'; i <= 'Z'; i++) { final String str = String.valueOf((char) i); - assertEquals("String: " + str, null, map.get(str)); + assertNull("String: " + str, map.get(str)); } } @@ -76,11 +76,11 @@ public class StaticBucketMapTest extends AbstractIterableMapTest { public void test_containsKey_nullMatchesIncorrectly() { final StaticBucketMap map = new StaticBucketMap<>(17); map.put(null, (V) "A"); - assertEquals(true, map.containsKey(null)); + assertTrue(map.containsKey(null)); // loop so we find a string that is in the same bucket as the null for (int i = 'A'; i <= 'Z'; i++) { final String str = String.valueOf((char) i); - assertEquals("String: " + str, false, map.containsKey(str)); + assertFalse("String: " + str, map.containsKey(str)); } } @@ -88,11 +88,11 @@ public class StaticBucketMapTest extends AbstractIterableMapTest { public void test_containsValue_nullMatchesIncorrectly() { final StaticBucketMap map = new StaticBucketMap<>(17); map.put((K) "A", null); - assertEquals(true, map.containsValue(null)); + assertTrue(map.containsValue(null)); // loop so we find a string that is in the same bucket as the null for (int i = 'A'; i <= 'Z'; i++) { final String str = String.valueOf((char) i); - assertEquals("String: " + str, false, map.containsValue(str)); + assertFalse("String: " + str, map.containsValue(str)); } } diff --git a/src/test/java/org/apache/commons/collections4/map/TransformedMapTest.java b/src/test/java/org/apache/commons/collections4/map/TransformedMapTest.java index 6e476272b..d8f216006 100644 --- a/src/test/java/org/apache/commons/collections4/map/TransformedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/TransformedMapTest.java @@ -56,13 +56,13 @@ public class TransformedMapTest extends AbstractIterableMapTest { for (int i = 0; i < els.length; i++) { map.put((K) els[i], (V) els[i]); assertEquals(i + 1, map.size()); - assertEquals(true, map.containsKey(Integer.valueOf((String) els[i]))); - assertEquals(false, map.containsKey(els[i])); - assertEquals(true, map.containsValue(els[i])); + assertTrue(map.containsKey(Integer.valueOf((String) els[i]))); + assertFalse(map.containsKey(els[i])); + assertTrue(map.containsValue(els[i])); assertEquals(els[i], map.get(Integer.valueOf((String) els[i]))); } - assertEquals(null, map.remove(els[0])); + assertNull(map.remove(els[0])); assertEquals(els[0], map.remove(Integer.valueOf((String) els[0]))); map = TransformedMap.transformingMap(new HashMap(), null, @@ -72,9 +72,9 @@ public class TransformedMapTest extends AbstractIterableMapTest { for (int i = 0; i < els.length; i++) { map.put((K) els[i], (V) els[i]); assertEquals(i + 1, map.size()); - assertEquals(true, map.containsValue(Integer.valueOf((String) els[i]))); - assertEquals(false, map.containsValue(els[i])); - assertEquals(true, map.containsKey(els[i])); + assertTrue(map.containsValue(Integer.valueOf((String) els[i]))); + assertFalse(map.containsValue(els[i])); + assertTrue(map.containsKey(els[i])); assertEquals(Integer.valueOf((String) els[i]), map.get(els[i])); } diff --git a/src/test/java/org/apache/commons/collections4/map/TransformedSortedMapTest.java b/src/test/java/org/apache/commons/collections4/map/TransformedSortedMapTest.java index 56eaaf9b4..a2ea6f925 100644 --- a/src/test/java/org/apache/commons/collections4/map/TransformedSortedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/TransformedSortedMapTest.java @@ -76,12 +76,12 @@ public class TransformedSortedMapTest extends AbstractSortedMapTest for (int i = 0; i < els.length; i++) { map.put((K) els[i], (V) els[i]); assertEquals(i + 1, map.size()); - assertEquals(true, map.containsKey(Integer.valueOf((String) els[i]))); + assertTrue(map.containsKey(Integer.valueOf((String) els[i]))); try { map.containsKey(els[i]); fail(); } catch (final ClassCastException ex) {} - assertEquals(true, map.containsValue(els[i])); + assertTrue(map.containsValue(els[i])); assertEquals(els[i], map.get(Integer.valueOf((String) els[i]))); } @@ -100,9 +100,9 @@ public class TransformedSortedMapTest extends AbstractSortedMapTest for (int i = 0; i < els.length; i++) { map.put((K) els[i], (V) els[i]); assertEquals(i + 1, map.size()); - assertEquals(true, map.containsValue(Integer.valueOf((String) els[i]))); - assertEquals(false, map.containsValue(els[i])); - assertEquals(true, map.containsKey(els[i])); + assertTrue(map.containsValue(Integer.valueOf((String) els[i]))); + assertFalse(map.containsValue(els[i])); + assertTrue(map.containsKey(els[i])); assertEquals(Integer.valueOf((String) els[i]), map.get(els[i])); } diff --git a/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java index 426327a7f..7307b4205 100644 --- a/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java @@ -531,14 +531,14 @@ public abstract class AbstractMultiValuedMapTest extends AbstractObjectTes @SuppressWarnings("unchecked") public void testContainsValue_Key() { final MultiValuedMap map = makeFullMap(); - assertEquals(true, map.containsMapping("one", "uno")); - assertEquals(false, map.containsMapping("two", "2")); + assertTrue(map.containsMapping("one", "uno")); + assertFalse(map.containsMapping("two", "2")); if (!isAddSupported()) { return; } map.put((K) "A", (V) "AA"); - assertEquals(true, map.containsMapping("A", "AA")); - assertEquals(false, map.containsMapping("A", "AB")); + assertTrue(map.containsMapping("A", "AA")); + assertFalse(map.containsMapping("A", "AB")); } @SuppressWarnings("unchecked") @@ -567,10 +567,10 @@ public abstract class AbstractMultiValuedMapTest extends AbstractObjectTes assertEquals(4, test.size()); assertEquals(1, test.get((K) "keyA").size()); assertEquals(3, test.get((K) "key").size()); - assertEquals(true, test.containsValue("objectA")); - assertEquals(true, test.containsValue("object0")); - assertEquals(true, test.containsValue("object1")); - assertEquals(true, test.containsValue("object2")); + assertTrue(test.containsValue("objectA")); + assertTrue(test.containsValue("object0")); + assertTrue(test.containsValue("object1")); + assertTrue(test.containsValue("object2")); } @SuppressWarnings("unchecked") @@ -600,10 +600,10 @@ public abstract class AbstractMultiValuedMapTest extends AbstractObjectTes assertEquals(1, test.get((K) "keyA").size()); assertEquals(2, test.get((K) "keyX").size()); assertEquals(1, test.get((K) "keyY").size()); - assertEquals(true, test.containsValue("objectA")); - assertEquals(true, test.containsValue("object0")); - assertEquals(true, test.containsValue("object1")); - assertEquals(true, test.containsValue("object2")); + assertTrue(test.containsValue("objectA")); + assertTrue(test.containsValue("object0")); + assertTrue(test.containsValue("object1")); + assertTrue(test.containsValue("object2")); } @SuppressWarnings("unchecked") @@ -614,11 +614,11 @@ public abstract class AbstractMultiValuedMapTest extends AbstractObjectTes final MultiValuedMap map = makeObject(); Collection coll = (Collection) Arrays.asList("X", "Y", "Z"); - assertEquals(true, map.putAll((K) "A", coll)); + assertTrue(map.putAll((K) "A", coll)); assertEquals(3, map.get((K) "A").size()); - assertEquals(true, map.containsMapping("A", "X")); - assertEquals(true, map.containsMapping("A", "Y")); - assertEquals(true, map.containsMapping("A", "Z")); + assertTrue(map.containsMapping("A", "X")); + assertTrue(map.containsMapping("A", "Y")); + assertTrue(map.containsMapping("A", "Z")); try { map.putAll((K) "A", null); @@ -628,23 +628,23 @@ public abstract class AbstractMultiValuedMapTest extends AbstractObjectTes } assertEquals(3, map.get((K) "A").size()); - assertEquals(true, map.containsMapping("A", "X")); - assertEquals(true, map.containsMapping("A", "Y")); - assertEquals(true, map.containsMapping("A", "Z")); + assertTrue(map.containsMapping("A", "X")); + assertTrue(map.containsMapping("A", "Y")); + assertTrue(map.containsMapping("A", "Z")); - assertEquals(false, map.putAll((K) "A", new ArrayList())); + assertFalse(map.putAll((K) "A", new ArrayList())); assertEquals(3, map.get((K) "A").size()); - assertEquals(true, map.containsMapping("A", "X")); - assertEquals(true, map.containsMapping("A", "Y")); - assertEquals(true, map.containsMapping("A", "Z")); + assertTrue(map.containsMapping("A", "X")); + assertTrue(map.containsMapping("A", "Y")); + assertTrue(map.containsMapping("A", "Z")); coll = (Collection) Arrays.asList("M"); - assertEquals(true, map.putAll((K) "A", coll)); + assertTrue(map.putAll((K) "A", coll)); assertEquals(4, map.get((K) "A").size()); - assertEquals(true, map.containsMapping("A", "X")); - assertEquals(true, map.containsMapping("A", "Y")); - assertEquals(true, map.containsMapping("A", "Z")); - assertEquals(true, map.containsMapping("A", "M")); + assertTrue(map.containsMapping("A", "X")); + assertTrue(map.containsMapping("A", "Y")); + assertTrue(map.containsMapping("A", "Z")); + assertTrue(map.containsMapping("A", "M")); } @SuppressWarnings("unchecked") @@ -656,11 +656,11 @@ public abstract class AbstractMultiValuedMapTest extends AbstractObjectTes map.put((K) "A", (V) "AA"); map.put((K) "A", (V) "AB"); map.put((K) "A", (V) "AC"); - assertEquals(false, map.removeMapping("C", "CA")); - assertEquals(false, map.removeMapping("A", "AD")); - assertEquals(true, map.removeMapping("A", "AC")); - assertEquals(true, map.removeMapping("A", "AB")); - assertEquals(true, map.removeMapping("A", "AA")); + assertFalse(map.removeMapping("C", "CA")); + assertFalse(map.removeMapping("A", "AD")); + assertTrue(map.removeMapping("A", "AC")); + assertTrue(map.removeMapping("A", "AB")); + assertTrue(map.removeMapping("A", "AA")); //assertEquals(new MultiValuedHashMap(), map); } diff --git a/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java index d0c4f2973..e47bd2e33 100644 --- a/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java @@ -61,16 +61,16 @@ public class TransformedMultiValuedMapTest extends AbstractMultiValuedMapT for (int i = 0; i < els.length; i++) { map.put((K) els[i], (V) els[i]); assertEquals(i + 1, map.size()); - assertEquals(true, map.containsKey(Integer.valueOf((String) els[i]))); - assertEquals(false, map.containsKey(els[i])); - assertEquals(true, map.containsValue(els[i])); - assertEquals(true, map.get((K) Integer.valueOf((String) els[i])).contains(els[i])); + assertTrue(map.containsKey(Integer.valueOf((String) els[i]))); + assertFalse(map.containsKey(els[i])); + assertTrue(map.containsValue(els[i])); + assertTrue(map.get((K) Integer.valueOf((String) els[i])).contains(els[i])); } final Collection coll = map.remove(els[0]); assertNotNull(coll); assertEquals(0, coll.size()); - assertEquals(true, map.remove(Integer.valueOf((String) els[0])).contains(els[0])); + assertTrue(map.remove(Integer.valueOf((String) els[0])).contains(els[0])); } @SuppressWarnings("unchecked") @@ -84,12 +84,12 @@ public class TransformedMultiValuedMapTest extends AbstractMultiValuedMapT for (int i = 0; i < els.length; i++) { map.put((K) els[i], (V) els[i]); assertEquals(i + 1, map.size()); - assertEquals(true, map.containsValue(Integer.valueOf((String) els[i]))); - assertEquals(false, map.containsValue(els[i])); - assertEquals(true, map.containsKey(els[i])); - assertEquals(true, map.get((K) els[i]).contains(Integer.valueOf((String) els[i]))); + assertTrue(map.containsValue(Integer.valueOf((String) els[i]))); + assertFalse(map.containsValue(els[i])); + assertTrue(map.containsKey(els[i])); + assertTrue(map.get((K) els[i]).contains(Integer.valueOf((String) els[i]))); } - assertEquals(true, map.remove(els[0]).contains(Integer.valueOf((String) els[0]))); + assertTrue(map.remove(els[0]).contains(Integer.valueOf((String) els[0]))); } // ----------------------------------------------------------------------- @@ -106,11 +106,11 @@ public class TransformedMultiValuedMapTest extends AbstractMultiValuedMapT null, (Transformer) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(3, trans.size()); - assertEquals(true, trans.get((K) "A").contains("1")); - assertEquals(true, trans.get((K) "B").contains("2")); - assertEquals(true, trans.get((K) "C").contains("3")); + assertTrue(trans.get((K) "A").contains("1")); + assertTrue(trans.get((K) "B").contains("2")); + assertTrue(trans.get((K) "C").contains("3")); trans.put((K) "D", (V) "4"); - assertEquals(true, trans.get((K) "D").contains(Integer.valueOf(4))); + assertTrue(trans.get((K) "D").contains(Integer.valueOf(4))); } @SuppressWarnings("unchecked") @@ -126,11 +126,11 @@ public class TransformedMultiValuedMapTest extends AbstractMultiValuedMapT null, (Transformer) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(3, trans.size()); - assertEquals(true, trans.get((K) "A").contains(Integer.valueOf(1))); - assertEquals(true, trans.get((K) "B").contains(Integer.valueOf(2))); - assertEquals(true, trans.get((K) "C").contains(Integer.valueOf(3))); + assertTrue(trans.get((K) "A").contains(Integer.valueOf(1))); + assertTrue(trans.get((K) "B").contains(Integer.valueOf(2))); + assertTrue(trans.get((K) "C").contains(Integer.valueOf(3))); trans.put((K) "D", (V) "4"); - assertEquals(true, trans.get((K) "D").contains(Integer.valueOf(4))); + assertTrue(trans.get((K) "D").contains(Integer.valueOf(4))); final MultiValuedMap baseMap = new ArrayListValuedHashMap<>(); final MultiValuedMap transMap = TransformedMultiValuedMap @@ -141,7 +141,7 @@ public class TransformedMultiValuedMapTest extends AbstractMultiValuedMapT assertEquals(0, transMap.size()); transMap.put((K) "D", (V) "4"); assertEquals(1, transMap.size()); - assertEquals(true, transMap.get((K) "D").contains(Integer.valueOf(4))); + assertTrue(transMap.get((K) "D").contains(Integer.valueOf(4))); } // public void testCreate() throws Exception { diff --git a/src/test/java/org/apache/commons/collections4/multiset/AbstractMultiSetTest.java b/src/test/java/org/apache/commons/collections4/multiset/AbstractMultiSetTest.java index dac9f4027..5296bc317 100644 --- a/src/test/java/org/apache/commons/collections4/multiset/AbstractMultiSetTest.java +++ b/src/test/java/org/apache/commons/collections4/multiset/AbstractMultiSetTest.java @@ -147,18 +147,18 @@ public abstract class AbstractMultiSetTest extends AbstractCollectionTest @SuppressWarnings("unchecked") public void testMultiSetEqualsSelf() { final MultiSet multiset = makeObject(); - assertTrue(multiset.equals(multiset)); + assertEquals(multiset, multiset); if (!isAddSupported()) { return; } multiset.add((T) "elt"); - assertTrue(multiset.equals(multiset)); + assertEquals(multiset, multiset); multiset.add((T) "elt"); // again - assertTrue(multiset.equals(multiset)); + assertEquals(multiset, multiset); multiset.add((T) "elt2"); - assertTrue(multiset.equals(multiset)); + assertEquals(multiset, multiset); } @SuppressWarnings("unchecked") @@ -215,20 +215,20 @@ public abstract class AbstractMultiSetTest extends AbstractCollectionTest final MultiSet multiset = makeObject(); - assertEquals("MultiSet does not have at least 1 'A'", false, multiset.contains("A")); - assertEquals("MultiSet does not have at least 1 'B'", false, multiset.contains("B")); + assertFalse("MultiSet does not have at least 1 'A'", multiset.contains("A")); + assertFalse("MultiSet does not have at least 1 'B'", multiset.contains("B")); multiset.add((T) "A"); // multiset 1A - assertEquals("MultiSet has at least 1 'A'", true, multiset.contains("A")); - assertEquals("MultiSet does not have at least 1 'B'", false, multiset.contains("B")); + assertTrue("MultiSet has at least 1 'A'", multiset.contains("A")); + assertFalse("MultiSet does not have at least 1 'B'", multiset.contains("B")); multiset.add((T) "A"); // multiset 2A - assertEquals("MultiSet has at least 1 'A'", true, multiset.contains("A")); - assertEquals("MultiSet does not have at least 1 'B'", false, multiset.contains("B")); + assertTrue("MultiSet has at least 1 'A'", multiset.contains("A")); + assertFalse("MultiSet does not have at least 1 'B'", multiset.contains("B")); multiset.add((T) "B"); // multiset 2A,1B - assertEquals("MultiSet has at least 1 'A'", true, multiset.contains("A")); - assertEquals("MultiSet has at least 1 'B'", true, multiset.contains("B")); + assertTrue("MultiSet has at least 1 'A'", multiset.contains("A")); + assertTrue("MultiSet has at least 1 'B'", multiset.contains("B")); } @SuppressWarnings("unchecked") @@ -250,39 +250,39 @@ public abstract class AbstractMultiSetTest extends AbstractCollectionTest known1A1B.add("A"); known1A1B.add("B"); - assertEquals("MultiSet containsAll of empty", true, multiset.containsAll(known)); - assertEquals("MultiSet does not containsAll of 1 'A'", false, multiset.containsAll(known1A)); - assertEquals("MultiSet does not containsAll of 2 'A'", false, multiset.containsAll(known2A)); - assertEquals("MultiSet does not containsAll of 1 'B'", false, multiset.containsAll(known1B)); - assertEquals("MultiSet does not containsAll of 1 'A' 1 'B'", false, multiset.containsAll(known1A1B)); + assertTrue("MultiSet containsAll of empty", multiset.containsAll(known)); + assertFalse("MultiSet does not containsAll of 1 'A'", multiset.containsAll(known1A)); + assertFalse("MultiSet does not containsAll of 2 'A'", multiset.containsAll(known2A)); + assertFalse("MultiSet does not containsAll of 1 'B'", multiset.containsAll(known1B)); + assertFalse("MultiSet does not containsAll of 1 'A' 1 'B'", multiset.containsAll(known1A1B)); multiset.add((T) "A"); // multiset 1A - assertEquals("MultiSet containsAll of empty", true, multiset.containsAll(known)); - assertEquals("MultiSet containsAll of 1 'A'", true, multiset.containsAll(known1A)); - assertEquals("MultiSet does not containsAll 'A'", true, multiset.containsAll(known2A)); - assertEquals("MultiSet does not containsAll of 1 'B'", false, multiset.containsAll(known1B)); - assertEquals("MultiSet does not containsAll of 1 'A' 1 'B'", false, multiset.containsAll(known1A1B)); + assertTrue("MultiSet containsAll of empty", multiset.containsAll(known)); + assertTrue("MultiSet containsAll of 1 'A'", multiset.containsAll(known1A)); + assertTrue("MultiSet does not containsAll 'A'", multiset.containsAll(known2A)); + assertFalse("MultiSet does not containsAll of 1 'B'", multiset.containsAll(known1B)); + assertFalse("MultiSet does not containsAll of 1 'A' 1 'B'", multiset.containsAll(known1A1B)); multiset.add((T) "A"); // multiset 2A - assertEquals("MultiSet containsAll of empty", true, multiset.containsAll(known)); - assertEquals("MultiSet containsAll of 1 'A'", true, multiset.containsAll(known1A)); - assertEquals("MultiSet containsAll of 2 'A'", true, multiset.containsAll(known2A)); - assertEquals("MultiSet does not containsAll of 1 'B'", false, multiset.containsAll(known1B)); - assertEquals("MultiSet does not containsAll of 1 'A' 1 'B'", false, multiset.containsAll(known1A1B)); + assertTrue("MultiSet containsAll of empty", multiset.containsAll(known)); + assertTrue("MultiSet containsAll of 1 'A'", multiset.containsAll(known1A)); + assertTrue("MultiSet containsAll of 2 'A'", multiset.containsAll(known2A)); + assertFalse("MultiSet does not containsAll of 1 'B'", multiset.containsAll(known1B)); + assertFalse("MultiSet does not containsAll of 1 'A' 1 'B'", multiset.containsAll(known1A1B)); multiset.add((T) "A"); // multiset 3A - assertEquals("MultiSet containsAll of empty", true, multiset.containsAll(known)); - assertEquals("MultiSet containsAll of 1 'A'", true, multiset.containsAll(known1A)); - assertEquals("MultiSet containsAll of 2 'A'", true, multiset.containsAll(known2A)); - assertEquals("MultiSet does not containsAll of 1 'B'", false, multiset.containsAll(known1B)); - assertEquals("MultiSet does not containsAll of 1 'A' 1 'B'", false, multiset.containsAll(known1A1B)); + assertTrue("MultiSet containsAll of empty", multiset.containsAll(known)); + assertTrue("MultiSet containsAll of 1 'A'", multiset.containsAll(known1A)); + assertTrue("MultiSet containsAll of 2 'A'", multiset.containsAll(known2A)); + assertFalse("MultiSet does not containsAll of 1 'B'", multiset.containsAll(known1B)); + assertFalse("MultiSet does not containsAll of 1 'A' 1 'B'", multiset.containsAll(known1A1B)); multiset.add((T) "B"); // multiset 3A1B - assertEquals("MultiSet containsAll of empty", true, multiset.containsAll(known)); - assertEquals("MultiSet containsAll of 1 'A'", true, multiset.containsAll(known1A)); - assertEquals("MultiSet containsAll of 2 'A'", true, multiset.containsAll(known2A)); - assertEquals("MultiSet containsAll of 1 'B'", true, multiset.containsAll(known1B)); - assertEquals("MultiSet containsAll of 1 'A' 1 'B'", true, multiset.containsAll(known1A1B)); + assertTrue("MultiSet containsAll of empty", multiset.containsAll(known)); + assertTrue("MultiSet containsAll of 1 'A'", multiset.containsAll(known1A)); + assertTrue("MultiSet containsAll of 2 'A'", multiset.containsAll(known2A)); + assertTrue("MultiSet containsAll of 1 'B'", multiset.containsAll(known1B)); + assertTrue("MultiSet containsAll of 1 'A' 1 'B'", multiset.containsAll(known1A1B)); } @SuppressWarnings("unchecked") @@ -444,18 +444,18 @@ public abstract class AbstractMultiSetTest extends AbstractCollectionTest assertEquals(2, multiset.size()); final Iterator it = multiset.iterator(); assertEquals("A", it.next()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); it.remove(); assertEquals(1, multiset.size()); - assertEquals(true, it.hasNext()); + assertTrue(it.hasNext()); assertEquals("A", it.next()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); it.remove(); assertEquals(0, multiset.size()); - assertEquals(false, it.hasNext()); + assertFalse(it.hasNext()); final Iterator it2 = multiset.iterator(); - assertEquals(false, it2.hasNext()); + assertFalse(it2.hasNext()); } @SuppressWarnings("unchecked") @@ -530,11 +530,11 @@ public abstract class AbstractMultiSetTest extends AbstractCollectionTest final MultiSet multiset = makeObject(); final MultiSet multiset2 = makeObject(); - assertEquals(true, multiset.equals(multiset2)); + assertTrue(multiset.equals(multiset2)); multiset.add((T) "A"); - assertEquals(false, multiset.equals(multiset2)); + assertFalse(multiset.equals(multiset2)); multiset2.add((T) "A"); - assertEquals(true, multiset.equals(multiset2)); + assertTrue(multiset.equals(multiset2)); multiset.add((T) "A"); multiset.add((T) "B"); multiset.add((T) "B"); @@ -543,7 +543,7 @@ public abstract class AbstractMultiSetTest extends AbstractCollectionTest multiset2.add((T) "B"); multiset2.add((T) "B"); multiset2.add((T) "C"); - assertEquals(true, multiset.equals(multiset2)); + assertTrue(multiset.equals(multiset2)); } @SuppressWarnings("unchecked") @@ -554,11 +554,11 @@ public abstract class AbstractMultiSetTest extends AbstractCollectionTest final MultiSet multiset = makeObject(); final MultiSet multiset2 = new HashMultiSet<>(); - assertEquals(true, multiset.equals(multiset2)); + assertTrue(multiset.equals(multiset2)); multiset.add((T) "A"); - assertEquals(false, multiset.equals(multiset2)); + assertFalse(multiset.equals(multiset2)); multiset2.add((T) "A"); - assertEquals(true, multiset.equals(multiset2)); + assertTrue(multiset.equals(multiset2)); multiset.add((T) "A"); multiset.add((T) "B"); multiset.add((T) "B"); @@ -567,7 +567,7 @@ public abstract class AbstractMultiSetTest extends AbstractCollectionTest multiset2.add((T) "B"); multiset2.add((T) "B"); multiset2.add((T) "C"); - assertEquals(true, multiset.equals(multiset2)); + assertTrue(multiset.equals(multiset2)); } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java b/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java index befa431c5..2a52962a5 100644 --- a/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java +++ b/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java @@ -72,11 +72,11 @@ public class PredicatedMultiSetTest extends AbstractMultiSetTest { for (int i = 0; i < els.length; i++) { multiset.add(els[i]); assertEquals(i + 1, multiset.size()); - assertEquals(true, multiset.contains(els[i])); + assertTrue(multiset.contains(els[i])); } Set set = ((PredicatedMultiSet) multiset).uniqueSet(); assertTrue("Unique set contains the first element", set.contains(els[0])); - assertEquals(true, multiset.remove(els[0])); + assertTrue(multiset.remove(els[0])); set = ((PredicatedMultiSet) multiset).uniqueSet(); assertTrue("Unique set does not contain anymore the first element", set.contains(els[0])); @@ -92,8 +92,7 @@ public class PredicatedMultiSetTest extends AbstractMultiSetTest { } catch (final IllegalArgumentException e) { // expected } - assertTrue("Collection shouldn't contain illegal element", - !multiset.contains(i)); + assertFalse("Collection shouldn't contain illegal element", multiset.contains(i)); } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/apache/commons/collections4/properties/EmptyPropertiesTest.java b/src/test/java/org/apache/commons/collections4/properties/EmptyPropertiesTest.java index c70173c52..e49b192b7 100644 --- a/src/test/java/org/apache/commons/collections4/properties/EmptyPropertiesTest.java +++ b/src/test/java/org/apache/commons/collections4/properties/EmptyPropertiesTest.java @@ -32,6 +32,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; @@ -95,14 +96,14 @@ public class EmptyPropertiesTest { @Test public void testEquals() { - assertTrue(PropertiesFactory.EMPTY_PROPERTIES.equals(PropertiesFactory.EMPTY_PROPERTIES)); - assertTrue(PropertiesFactory.EMPTY_PROPERTIES.equals(new Properties())); - assertTrue(new Properties().equals(PropertiesFactory.EMPTY_PROPERTIES)); - assertFalse(PropertiesFactory.EMPTY_PROPERTIES.equals(null)); + assertEquals(PropertiesFactory.EMPTY_PROPERTIES, PropertiesFactory.EMPTY_PROPERTIES); + assertEquals(PropertiesFactory.EMPTY_PROPERTIES, new Properties()); + assertEquals(new Properties(), PropertiesFactory.EMPTY_PROPERTIES); + assertNotEquals(null, PropertiesFactory.EMPTY_PROPERTIES); final Properties p = new Properties(); p.put("Key", "Value"); - assertFalse(PropertiesFactory.EMPTY_PROPERTIES.equals(p)); - assertFalse(p.equals(PropertiesFactory.EMPTY_PROPERTIES)); + assertNotEquals(PropertiesFactory.EMPTY_PROPERTIES, p); + assertNotEquals(p, PropertiesFactory.EMPTY_PROPERTIES); } public void testForEach() { diff --git a/src/test/java/org/apache/commons/collections4/queue/CircularFifoQueueTest.java b/src/test/java/org/apache/commons/collections4/queue/CircularFifoQueueTest.java index 05fd204ae..b1cb67a95 100644 --- a/src/test/java/org/apache/commons/collections4/queue/CircularFifoQueueTest.java +++ b/src/test/java/org/apache/commons/collections4/queue/CircularFifoQueueTest.java @@ -116,16 +116,16 @@ public class CircularFifoQueueTest extends AbstractQueueTest { list.add((E) "C"); final Queue queue = new CircularFifoQueue<>(list); - assertEquals(true, queue.contains("A")); - assertEquals(true, queue.contains("B")); - assertEquals(true, queue.contains("C")); + assertTrue(queue.contains("A")); + assertTrue(queue.contains("B")); + assertTrue(queue.contains("C")); queue.add((E) "D"); - assertEquals(false, queue.contains("A")); - assertEquals(true, queue.contains("B")); - assertEquals(true, queue.contains("C")); - assertEquals(true, queue.contains("D")); + assertFalse(queue.contains("A")); + assertTrue(queue.contains("B")); + assertTrue(queue.contains("C")); + assertTrue(queue.contains("D")); assertEquals("B", queue.peek()); assertEquals("B", queue.remove()); @@ -369,7 +369,7 @@ public class CircularFifoQueueTest extends AbstractQueueTest { final CircularFifoQueue b = new CircularFifoQueue<>(2); b.add((E) "a"); assertEquals(1, b.size()); - assertEquals(true, b.contains("a")); + assertTrue(b.contains("a")); ByteArrayOutputStream bos = new ByteArrayOutputStream(); new ObjectOutputStream(bos).writeObject(b); @@ -378,11 +378,11 @@ public class CircularFifoQueueTest extends AbstractQueueTest { new ByteArrayInputStream(bos.toByteArray())).readObject(); assertEquals(1, b2.size()); - assertEquals(true, b2.contains("a")); + assertTrue(b2.contains("a")); b2.add((E) "b"); assertEquals(2, b2.size()); - assertEquals(true, b2.contains("a")); - assertEquals(true, b2.contains("b")); + assertTrue(b2.contains("a")); + assertTrue(b2.contains("b")); bos = new ByteArrayOutputStream(); new ObjectOutputStream(bos).writeObject(b2); @@ -391,12 +391,12 @@ public class CircularFifoQueueTest extends AbstractQueueTest { new ByteArrayInputStream(bos.toByteArray())).readObject(); assertEquals(2, b3.size()); - assertEquals(true, b3.contains("a")); - assertEquals(true, b3.contains("b")); + assertTrue(b3.contains("a")); + assertTrue(b3.contains("b")); b3.add((E) "c"); assertEquals(2, b3.size()); - assertEquals(true, b3.contains("b")); - assertEquals(true, b3.contains("c")); + assertTrue(b3.contains("b")); + assertTrue(b3.contains("c")); } public void testGetIndex() { diff --git a/src/test/java/org/apache/commons/collections4/queue/TransformedQueueTest.java b/src/test/java/org/apache/commons/collections4/queue/TransformedQueueTest.java index bcf2179dc..cd3a9e996 100644 --- a/src/test/java/org/apache/commons/collections4/queue/TransformedQueueTest.java +++ b/src/test/java/org/apache/commons/collections4/queue/TransformedQueueTest.java @@ -69,12 +69,12 @@ public class TransformedQueueTest extends AbstractQueueTest { for (int i = 0; i < elements.length; i++) { queue.add(elements[i]); assertEquals(i + 1, queue.size()); - assertEquals(true, queue.contains(Integer.valueOf((String) elements[i]))); - assertEquals(false, queue.contains(elements[i])); + assertTrue(queue.contains(Integer.valueOf((String) elements[i]))); + assertFalse(queue.contains(elements[i])); } - assertEquals(false, queue.remove(elements[0])); - assertEquals(true, queue.remove(Integer.valueOf((String) elements[0]))); + assertFalse(queue.remove(elements[0])); + assertTrue(queue.remove(Integer.valueOf((String) elements[0]))); } @@ -87,12 +87,12 @@ public class TransformedQueueTest extends AbstractQueueTest { TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(elements.length, queue.size()); for (final Object el : elements) { - assertEquals(true, queue.contains(Integer.valueOf((String) el))); - assertEquals(false, queue.contains(el)); + assertTrue(queue.contains(Integer.valueOf((String) el))); + assertFalse(queue.contains(el)); } - assertEquals(false, queue.remove(elements[0])); - assertEquals(true, queue.remove(Integer.valueOf((String) elements[0]))); + assertFalse(queue.remove(elements[0])); + assertTrue(queue.remove(Integer.valueOf((String) elements[0]))); } @Override diff --git a/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java b/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java index 38f458b78..e9a10ea62 100644 --- a/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java @@ -146,7 +146,7 @@ public abstract class AbstractSetTest extends AbstractCollectionTest { final Collection set2 = makeConfirmedCollection(); set2.add((E) "foo"); - assertTrue("Empty set shouldn't equal nonempty set", !getCollection().equals(set2)); + assertFalse("Empty set shouldn't equal nonempty set", getCollection().equals(set2)); resetFull(); assertEquals("Full sets should be equal", getCollection(), getConfirmed()); @@ -154,7 +154,7 @@ public abstract class AbstractSetTest extends AbstractCollectionTest { set2.clear(); set2.addAll(Arrays.asList(getOtherElements())); - assertTrue("Sets with different contents shouldn't be equal", !getCollection().equals(set2)); + assertFalse("Sets with different contents shouldn't be equal", getCollection().equals(set2)); } /** diff --git a/src/test/java/org/apache/commons/collections4/set/CompositeSetTest.java b/src/test/java/org/apache/commons/collections4/set/CompositeSetTest.java index f37535a1e..55e35901a 100644 --- a/src/test/java/org/apache/commons/collections4/set/CompositeSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/CompositeSetTest.java @@ -149,7 +149,7 @@ public class CompositeSetTest extends AbstractSetTest { set.addComposited(null, null, null); final CompositeSet set2 = new CompositeSet<>(buildOne()); set2.addComposited(buildTwo()); - assertTrue(set.equals(set2)); + assertEquals(set, set2); final HashSet set3 = new HashSet<>(); set3.add((E) "1"); set3.add((E) "2"); @@ -158,7 +158,7 @@ public class CompositeSetTest extends AbstractSetTest { set4.add((E) "4"); final CompositeSet set5 = new CompositeSet<>(set3); set5.addComposited(set4); - assertTrue(set.equals(set5)); + assertEquals(set, set5); try { set.addComposited(set3); fail("Expecting UnsupportedOperationException."); diff --git a/src/test/java/org/apache/commons/collections4/set/PredicatedNavigableSetTest.java b/src/test/java/org/apache/commons/collections4/set/PredicatedNavigableSetTest.java index 0beaaeb75..320d25b18 100644 --- a/src/test/java/org/apache/commons/collections4/set/PredicatedNavigableSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/PredicatedNavigableSetTest.java @@ -69,7 +69,7 @@ public class PredicatedNavigableSetTest extends AbstractNavigableSetTest { public void testGetSet() { final PredicatedNavigableSet set = makeTestSet(); - assertTrue("returned set should not be null", set.decorated() != null); + assertNotNull("returned set should not be null", set.decorated()); } @SuppressWarnings("unchecked") @@ -82,7 +82,7 @@ public class PredicatedNavigableSetTest extends AbstractNavigableSetTest { } catch (final IllegalArgumentException e) { // expected } - assertTrue("Collection shouldn't contain illegal element", !set.contains(testString)); + assertFalse("Collection shouldn't contain illegal element", set.contains(testString)); } @SuppressWarnings("unchecked") @@ -99,16 +99,16 @@ public class PredicatedNavigableSetTest extends AbstractNavigableSetTest { } catch (final IllegalArgumentException e) { // expected } - assertTrue("Set shouldn't contain illegal element", !set.contains("Aone")); - assertTrue("Set shouldn't contain illegal element", !set.contains("Atwo")); - assertTrue("Set shouldn't contain illegal element", !set.contains("Bthree")); - assertTrue("Set shouldn't contain illegal element", !set.contains("Afour")); + assertFalse("Set shouldn't contain illegal element", set.contains("Aone")); + assertFalse("Set shouldn't contain illegal element", set.contains("Atwo")); + assertFalse("Set shouldn't contain illegal element", set.contains("Bthree")); + assertFalse("Set shouldn't contain illegal element", set.contains("Afour")); } public void testComparator() { final NavigableSet set = makeTestSet(); final Comparator c = set.comparator(); - assertTrue("natural order, so comparator should be null", c == null); + assertNull("natural order, so comparator should be null", c); } @Override diff --git a/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java b/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java index 410849f96..c2a6515d2 100644 --- a/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java @@ -64,7 +64,7 @@ public class PredicatedSetTest extends AbstractSetTest { public void testGetSet() { final PredicatedSet set = makeTestSet(); - assertTrue("returned set should not be null", set.decorated() != null); + assertNotNull("returned set should not be null", set.decorated()); } @SuppressWarnings("unchecked") @@ -77,7 +77,7 @@ public class PredicatedSetTest extends AbstractSetTest { } catch (final IllegalArgumentException e) { // expected } - assertTrue("Collection shouldn't contain illegal element", !set.contains(i)); + assertFalse("Collection shouldn't contain illegal element", set.contains(i)); } @SuppressWarnings("unchecked") @@ -94,10 +94,10 @@ public class PredicatedSetTest extends AbstractSetTest { } catch (final IllegalArgumentException e) { // expected } - assertTrue("Set shouldn't contain illegal element", !set.contains("one")); - assertTrue("Set shouldn't contain illegal element", !set.contains("two")); - assertTrue("Set shouldn't contain illegal element", !set.contains(Integer.valueOf(3))); - assertTrue("Set shouldn't contain illegal element", !set.contains("four")); + assertFalse("Set shouldn't contain illegal element", set.contains("one")); + assertFalse("Set shouldn't contain illegal element", set.contains("two")); + assertFalse("Set shouldn't contain illegal element", set.contains(Integer.valueOf(3))); + assertFalse("Set shouldn't contain illegal element", set.contains("four")); } @Override diff --git a/src/test/java/org/apache/commons/collections4/set/PredicatedSortedSetTest.java b/src/test/java/org/apache/commons/collections4/set/PredicatedSortedSetTest.java index a06217eec..1100ddfab 100644 --- a/src/test/java/org/apache/commons/collections4/set/PredicatedSortedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/PredicatedSortedSetTest.java @@ -66,7 +66,7 @@ public class PredicatedSortedSetTest extends AbstractSortedSetTest { public void testGetSet() { final PredicatedSortedSet set = makeTestSet(); - assertTrue("returned set should not be null", set.decorated() != null); + assertNotNull("returned set should not be null", set.decorated()); } @SuppressWarnings("unchecked") @@ -79,7 +79,7 @@ public class PredicatedSortedSetTest extends AbstractSortedSetTest { } catch (final IllegalArgumentException e) { // expected } - assertTrue("Collection shouldn't contain illegal element", !set.contains(testString)); + assertFalse("Collection shouldn't contain illegal element", set.contains(testString)); } @SuppressWarnings("unchecked") @@ -96,16 +96,16 @@ public class PredicatedSortedSetTest extends AbstractSortedSetTest { } catch (final IllegalArgumentException e) { // expected } - assertTrue("Set shouldn't contain illegal element", !set.contains("Aone")); - assertTrue("Set shouldn't contain illegal element", !set.contains("Atwo")); - assertTrue("Set shouldn't contain illegal element", !set.contains("Bthree")); - assertTrue("Set shouldn't contain illegal element", !set.contains("Afour")); + assertFalse("Set shouldn't contain illegal element", set.contains("Aone")); + assertFalse("Set shouldn't contain illegal element", set.contains("Atwo")); + assertFalse("Set shouldn't contain illegal element", set.contains("Bthree")); + assertFalse("Set shouldn't contain illegal element", set.contains("Afour")); } public void testComparator() { final SortedSet set = makeTestSet(); final Comparator c = set.comparator(); - assertTrue("natural order, so comparator should be null", c == null); + assertNull("natural order, so comparator should be null", c); } @Override diff --git a/src/test/java/org/apache/commons/collections4/set/TransformedNavigableSetTest.java b/src/test/java/org/apache/commons/collections4/set/TransformedNavigableSetTest.java index 8331a7c30..457069a82 100644 --- a/src/test/java/org/apache/commons/collections4/set/TransformedNavigableSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/TransformedNavigableSetTest.java @@ -68,10 +68,10 @@ public class TransformedNavigableSetTest extends AbstractNavigableSetTest for (int i = 0; i < els.length; i++) { set.add(els[i]); assertEquals(i + 1, set.size()); - assertEquals(true, set.contains(Integer.valueOf((String) els[i]))); + assertTrue(set.contains(Integer.valueOf((String) els[i]))); } - assertEquals(true, set.remove(Integer.valueOf((String) els[0]))); + assertTrue(set.remove(Integer.valueOf((String) els[0]))); } public void testTransformedSet_decorateTransform() { @@ -82,10 +82,10 @@ public class TransformedNavigableSetTest extends AbstractNavigableSetTest TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, set.size()); for (final Object el : els) { - assertEquals(true, set.contains(Integer.valueOf((String) el))); + assertTrue(set.contains(Integer.valueOf((String) el))); } - assertEquals(true, set.remove(Integer.valueOf((String) els[0]))); + assertTrue(set.remove(Integer.valueOf((String) els[0]))); } @Override diff --git a/src/test/java/org/apache/commons/collections4/set/TransformedSetTest.java b/src/test/java/org/apache/commons/collections4/set/TransformedSetTest.java index 582a36a29..9c71c0222 100644 --- a/src/test/java/org/apache/commons/collections4/set/TransformedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/TransformedSetTest.java @@ -70,12 +70,12 @@ public class TransformedSetTest extends AbstractSetTest { for (int i = 0; i < els.length; i++) { set.add(els[i]); assertEquals(i + 1, set.size()); - assertEquals(true, set.contains(Integer.valueOf((String) els[i]))); - assertEquals(false, set.contains(els[i])); + assertTrue(set.contains(Integer.valueOf((String) els[i]))); + assertFalse(set.contains(els[i])); } - assertEquals(false, set.remove(els[0])); - assertEquals(true, set.remove(Integer.valueOf((String) els[0]))); + assertFalse(set.remove(els[0])); + assertTrue(set.remove(Integer.valueOf((String) els[0]))); } @@ -86,12 +86,12 @@ public class TransformedSetTest extends AbstractSetTest { final Set set = TransformedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, set.size()); for (final Object el : els) { - assertEquals(true, set.contains(Integer.valueOf((String) el))); - assertEquals(false, set.contains(el)); + assertTrue(set.contains(Integer.valueOf((String) el))); + assertFalse(set.contains(el)); } - assertEquals(false, set.remove(els[0])); - assertEquals(true, set.remove(Integer.valueOf((String) els[0]))); + assertFalse(set.remove(els[0])); + assertTrue(set.remove(Integer.valueOf((String) els[0]))); } @Override diff --git a/src/test/java/org/apache/commons/collections4/set/TransformedSortedSetTest.java b/src/test/java/org/apache/commons/collections4/set/TransformedSortedSetTest.java index f7b1de88c..d22239705 100644 --- a/src/test/java/org/apache/commons/collections4/set/TransformedSortedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/TransformedSortedSetTest.java @@ -66,10 +66,10 @@ public class TransformedSortedSetTest extends AbstractSortedSetTest { for (int i = 0; i < els.length; i++) { set.add(els[i]); assertEquals(i + 1, set.size()); - assertEquals(true, set.contains(Integer.valueOf((String) els[i]))); + assertTrue(set.contains(Integer.valueOf((String) els[i]))); } - assertEquals(true, set.remove(Integer.valueOf((String) els[0]))); + assertTrue(set.remove(Integer.valueOf((String) els[0]))); } public void testTransformedSet_decorateTransform() { @@ -79,10 +79,10 @@ public class TransformedSortedSetTest extends AbstractSortedSetTest { final Set set = TransformedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, set.size()); for (final Object el : els) { - assertEquals(true, set.contains(Integer.valueOf((String) el))); + assertTrue(set.contains(Integer.valueOf((String) el))); } - assertEquals(true, set.remove(Integer.valueOf((String) els[0]))); + assertTrue(set.remove(Integer.valueOf((String) els[0]))); } @Override diff --git a/src/test/java/org/apache/commons/collections4/set/UnmodifiableSortedSetTest.java b/src/test/java/org/apache/commons/collections4/set/UnmodifiableSortedSetTest.java index b8a79ac47..177046f4f 100644 --- a/src/test/java/org/apache/commons/collections4/set/UnmodifiableSortedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/UnmodifiableSortedSetTest.java @@ -143,7 +143,7 @@ public class UnmodifiableSortedSetTest extends AbstractSortedSetTest { public void testComparator() { setupSet(); final Comparator c = set.comparator(); - assertTrue("natural order, so comparator should be null", c == null); + assertNull("natural order, so comparator should be null", c); } diff --git a/src/test/java/org/apache/commons/collections4/splitmap/TransformedSplitMapTest.java b/src/test/java/org/apache/commons/collections4/splitmap/TransformedSplitMapTest.java index 8059a9fe6..8c2c120cd 100644 --- a/src/test/java/org/apache/commons/collections4/splitmap/TransformedSplitMapTest.java +++ b/src/test/java/org/apache/commons/collections4/splitmap/TransformedSplitMapTest.java @@ -66,7 +66,7 @@ public class TransformedSplitMapTest extends BulkTest { } int sz = map.size(); - assertEquals(null, map.remove(k[0])); + assertNull(map.remove(k[0])); assertEquals(sz, map.size()); assertEquals(objectToClass.transform(v[0]), map.remove(intToString.transform(k[0]))); assertEquals(--sz, map.size()); From ff0fabd09c067a8b54e9a5ccd5a1a12c800bdead Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Sat, 9 Oct 2021 21:49:35 +1300 Subject: [PATCH 2/2] [COLLECTIONS-793] Changelog --- src/changes/changes.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 1cf9dd6b1..1b607d75a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -291,6 +291,9 @@ Bump easymock from 4.2 to 4.3 #226. + + Simplify Assertion. +