diff --git a/src/conf/checkstyle.xml b/src/conf/checkstyle.xml index d4b8cff4ba..0b543f10e3 100644 --- a/src/conf/checkstyle.xml +++ b/src/conf/checkstyle.xml @@ -59,6 +59,7 @@ limitations under the License. + diff --git a/src/main/java/org/apache/commons/collections4/BagUtils.java b/src/main/java/org/apache/commons/collections4/BagUtils.java index 225437a233..2cffccf587 100644 --- a/src/main/java/org/apache/commons/collections4/BagUtils.java +++ b/src/main/java/org/apache/commons/collections4/BagUtils.java @@ -263,5 +263,8 @@ public static SortedBag unmodifiableSortedBag(final SortedBag bag) { /** * Don't allow instances. */ - private BagUtils() {} + private BagUtils() { + // empty + } + } diff --git a/src/main/java/org/apache/commons/collections4/ClosureUtils.java b/src/main/java/org/apache/commons/collections4/ClosureUtils.java index 819e444167..def04ea9c9 100644 --- a/src/main/java/org/apache/commons/collections4/ClosureUtils.java +++ b/src/main/java/org/apache/commons/collections4/ClosureUtils.java @@ -370,6 +370,8 @@ public static Closure whileClosure(final Predicate predicate, /** * Don't allow instances. */ - private ClosureUtils() {} + private ClosureUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/CollectionUtils.java b/src/main/java/org/apache/commons/collections4/CollectionUtils.java index 5a62e92697..5283c17357 100644 --- a/src/main/java/org/apache/commons/collections4/CollectionUtils.java +++ b/src/main/java/org/apache/commons/collections4/CollectionUtils.java @@ -2151,5 +2151,7 @@ public static Collection unmodifiableCollection(final Collection Comparator transformedComparator(Comparator comparato /** * Don't allow instances. */ - private ComparatorUtils() {} + private ComparatorUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/FactoryUtils.java b/src/main/java/org/apache/commons/collections4/FactoryUtils.java index 76c58ec2be..36d5679448 100644 --- a/src/main/java/org/apache/commons/collections4/FactoryUtils.java +++ b/src/main/java/org/apache/commons/collections4/FactoryUtils.java @@ -145,6 +145,8 @@ public static Factory prototypeFactory(final T prototype) { /** * Don't allow instances. */ - private FactoryUtils() {} + private FactoryUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/IteratorUtils.java b/src/main/java/org/apache/commons/collections4/IteratorUtils.java index ecf5b21c53..5918e8c7ab 100644 --- a/src/main/java/org/apache/commons/collections4/IteratorUtils.java +++ b/src/main/java/org/apache/commons/collections4/IteratorUtils.java @@ -1438,6 +1438,8 @@ public static ZippingIterator zippingIterator(final Iterator /** * Don't allow instances. */ - private IteratorUtils() {} + private IteratorUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/ListUtils.java b/src/main/java/org/apache/commons/collections4/ListUtils.java index f7eb95c5eb..1d24b1849a 100644 --- a/src/main/java/org/apache/commons/collections4/ListUtils.java +++ b/src/main/java/org/apache/commons/collections4/ListUtils.java @@ -744,5 +744,8 @@ public static List unmodifiableList(final List list) { /** * Don't allow instances. */ - private ListUtils() {} + private ListUtils() { + // empty + } + } diff --git a/src/main/java/org/apache/commons/collections4/MultiMapUtils.java b/src/main/java/org/apache/commons/collections4/MultiMapUtils.java index d17dd53de4..a91372722c 100644 --- a/src/main/java/org/apache/commons/collections4/MultiMapUtils.java +++ b/src/main/java/org/apache/commons/collections4/MultiMapUtils.java @@ -240,6 +240,8 @@ public static MultiValuedMap unmodifiableMultiValuedMap( /** * Don't allow instances. */ - private MultiMapUtils() {} + private MultiMapUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/MultiSetUtils.java b/src/main/java/org/apache/commons/collections4/MultiSetUtils.java index e472b72da5..f424236e22 100644 --- a/src/main/java/org/apache/commons/collections4/MultiSetUtils.java +++ b/src/main/java/org/apache/commons/collections4/MultiSetUtils.java @@ -112,6 +112,8 @@ public static MultiSet unmodifiableMultiSet(final MultiSet m /** * Don't allow instances. */ - private MultiSetUtils() {} + private MultiSetUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/PredicateUtils.java b/src/main/java/org/apache/commons/collections4/PredicateUtils.java index f5cec7ef1f..4cb824932f 100644 --- a/src/main/java/org/apache/commons/collections4/PredicateUtils.java +++ b/src/main/java/org/apache/commons/collections4/PredicateUtils.java @@ -380,7 +380,7 @@ public static Predicate notPredicate(final Predicate predicate * @throws NullPointerException if the predicate is null. * @see NullIsExceptionPredicate */ - public static Predicate nullIsExceptionPredicate(final Predicate predicate){ + public static Predicate nullIsExceptionPredicate(final Predicate predicate) { return NullIsExceptionPredicate.nullIsExceptionPredicate(predicate); } @@ -395,7 +395,7 @@ public static Predicate nullIsExceptionPredicate(final Predicate Predicate nullIsFalsePredicate(final Predicate predicate){ + public static Predicate nullIsFalsePredicate(final Predicate predicate) { return NullIsFalsePredicate.nullIsFalsePredicate(predicate); } @@ -410,7 +410,7 @@ public static Predicate nullIsFalsePredicate(final Predicate p * @throws NullPointerException if the predicate is null. * @see NullIsTruePredicate */ - public static Predicate nullIsTruePredicate(final Predicate predicate){ + public static Predicate nullIsTruePredicate(final Predicate predicate) { return NullIsTruePredicate.nullIsTruePredicate(predicate); } @@ -486,8 +486,7 @@ public static Predicate orPredicate(final Predicate predicate1 * @see TransformedPredicate * @since 3.1 */ - public static Predicate transformedPredicate( - final Transformer transformer, final Predicate predicate) { + public static Predicate transformedPredicate(final Transformer transformer, final Predicate predicate) { return TransformedPredicate.transformedPredicate(transformer, predicate); } @@ -521,6 +520,8 @@ public static Predicate uniquePredicate() { /** * Don't allow instances. */ - private PredicateUtils() {} + private PredicateUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/QueueUtils.java b/src/main/java/org/apache/commons/collections4/QueueUtils.java index 63e409cb1e..aff6a24194 100644 --- a/src/main/java/org/apache/commons/collections4/QueueUtils.java +++ b/src/main/java/org/apache/commons/collections4/QueueUtils.java @@ -113,8 +113,7 @@ public static Queue synchronizedQueue(final Queue queue) { * @return a transformed queue backed by the given queue * @throws NullPointerException if the queue or transformer is null */ - public static Queue transformingQueue(final Queue queue, - final Transformer transformer) { + public static Queue transformingQueue(final Queue queue, final Transformer transformer) { return TransformedQueue.transformingQueue(queue, transformer); } @@ -133,5 +132,7 @@ public static Queue unmodifiableQueue(final Queue queue) { /** * Don't allow instances. */ - private QueueUtils() {} + private QueueUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/SetUtils.java b/src/main/java/org/apache/commons/collections4/SetUtils.java index c1317f0885..cf5e438b4c 100644 --- a/src/main/java/org/apache/commons/collections4/SetUtils.java +++ b/src/main/java/org/apache/commons/collections4/SetUtils.java @@ -652,5 +652,8 @@ public static SortedSet unmodifiableSortedSet(final SortedSet set) { /** * Don't allow instances. */ - private SetUtils() {} + private SetUtils() { + // empty + } + } diff --git a/src/main/java/org/apache/commons/collections4/SplitMapUtils.java b/src/main/java/org/apache/commons/collections4/SplitMapUtils.java index 2f77982a1c..b645d3049b 100644 --- a/src/main/java/org/apache/commons/collections4/SplitMapUtils.java +++ b/src/main/java/org/apache/commons/collections4/SplitMapUtils.java @@ -259,6 +259,8 @@ public static Map writableMap(final Put put) { /** * Don't allow instances. */ - private SplitMapUtils() {} + private SplitMapUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/TransformerUtils.java b/src/main/java/org/apache/commons/collections4/TransformerUtils.java index 9d51a24f3f..7ad0b9f99d 100644 --- a/src/main/java/org/apache/commons/collections4/TransformerUtils.java +++ b/src/main/java/org/apache/commons/collections4/TransformerUtils.java @@ -480,6 +480,8 @@ public static Transformer switchTransformer(final Predicate Trie unmodifiableTrie(final Trie trie /** * Don't allow instances. */ - private TrieUtils() {} + private TrieUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java index d1ddb23305..9ab69afa73 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java @@ -1969,13 +1969,13 @@ public void putAll(final Map map) { * @throws ClassNotFoundException if an object read from the stream can not be loaded */ @SuppressWarnings("unchecked") // This will fail at runtime if the stream is incorrect - private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException{ + private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); rootNode = new Node[2]; final int size = stream.readInt(); - for (int i = 0; i < size; i++){ - final K k =(K) stream.readObject(); - final V v =(V) stream.readObject(); + for (int i = 0; i < size; i++) { + final K k = (K) stream.readObject(); + final V v = (V) stream.readObject(); put(k, v); } } @@ -2224,7 +2224,7 @@ public Set values() { * @param stream the output stream * @throws IOException if an error occurs while writing to the stream */ - private void writeObject(final ObjectOutputStream stream) throws IOException{ + private void writeObject(final ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeInt(this.size()); for (final Entry entry : entrySet()) { diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java index feb32a483d..41ec91058b 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java @@ -166,7 +166,7 @@ default int estimateIntersection(final BloomFilter other) { estimate = Math.round(eThis + eOther - eUnion); estimate = estimate < 0 ? 0 : estimate; } - return estimate>Integer.MAX_VALUE?Integer.MAX_VALUE:(int) estimate; + return estimate > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) estimate; } /** diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexUtils.java b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexUtils.java index bea31d733b..3c835ea570 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexUtils.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexUtils.java @@ -42,6 +42,10 @@ static int[] ensureCapacityForAdd(final int[] array, final int index) { return array; } - // do not instantiate - private IndexUtils() {} + /** + * Don't instantiate. + */ + private IndexUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java b/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java index c16b0dad0c..f5500f747c 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java @@ -125,8 +125,10 @@ public static final class Cleanup { * A Cleanup that never removes anything. * @return A Consumer suitable for the LayerManager {@code cleanup} parameter. */ - public static Consumer> noCleanup() { - return x -> {}; + public static Consumer> noCleanup() { + return x -> { + // empty + }; } /** diff --git a/src/main/java/org/apache/commons/collections4/comparators/ComparableComparator.java b/src/main/java/org/apache/commons/collections4/comparators/ComparableComparator.java index f6ec7917f5..fcd03fb782 100644 --- a/src/main/java/org/apache/commons/collections4/comparators/ComparableComparator.java +++ b/src/main/java/org/apache/commons/collections4/comparators/ComparableComparator.java @@ -45,7 +45,7 @@ public class ComparableComparator> implements Comparator, Serializable { /** Serialization version. */ - private static final long serialVersionUID=-291439688585137865L; + private static final long serialVersionUID = -291439688585137865L; /** The singleton instance. */ @SuppressWarnings("rawtypes") diff --git a/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java b/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java index 637b51e344..fc3788d7d5 100644 --- a/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java @@ -112,7 +112,7 @@ public IfTransformer(final Predicate predicate, * * @return the predicate */ - public Predicate getPredicate(){ + public Predicate getPredicate() { return iPredicate; } @@ -133,7 +133,7 @@ public Predicate getPredicate(){ */ @Override public O transform(final I input) { - if (iPredicate.evaluate(input)){ + if (iPredicate.evaluate(input)) { return iTrueTransformer.transform(input); } return iFalseTransformer.transform(input); diff --git a/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java b/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java index 3c9839ca09..9a6b906e48 100644 --- a/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java @@ -93,7 +93,7 @@ public static Closure switchClosure(final Predicate[] predicat throw new IllegalArgumentException("The predicate and closure arrays must be the same size"); } if (predicates.length == 0) { - return (Closure) (defaultClosure == null ? NOPClosure.nopClosure(): defaultClosure); + return (Closure) (defaultClosure == null ? NOPClosure.nopClosure() : defaultClosure); } return new SwitchClosure<>(predicates, closures, defaultClosure); } diff --git a/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java b/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java index 0109df27c6..5aeb6f5754 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java @@ -182,7 +182,7 @@ public E previous() { @Override public int previousIndex() { - return nextIndex-1; + return nextIndex - 1; } /** Not supported. */ diff --git a/src/main/java/org/apache/commons/collections4/map/LRUMap.java b/src/main/java/org/apache/commons/collections4/map/LRUMap.java index 1e91c3257a..c15ca6be54 100644 --- a/src/main/java/org/apache/commons/collections4/map/LRUMap.java +++ b/src/main/java/org/apache/commons/collections4/map/LRUMap.java @@ -492,10 +492,8 @@ protected void reuseMapping(final LinkEntry entry, final int hashIndex, fi reuseEntry(entry, hashIndex, hashCode, key, value); addEntry(entry, hashIndex); } catch (final NullPointerException ex) { - throw new IllegalStateException( - "NPE, entry=" + entry + " entryIsHeader=" + (entry==header) + - " key=" + key + " value=" + value + " size=" + size + " maxSize=" + maxSize + - " This should not occur if your keys are immutable, and you have used synchronization properly."); + throw new IllegalStateException("NPE, entry=" + entry + " entryIsHeader=" + (entry == header) + " key=" + key + " value=" + value + " size=" + size + + " maxSize=" + maxSize + " This should not occur if your keys are immutable, and you have used synchronization properly."); } } diff --git a/src/main/java/org/apache/commons/collections4/sequence/SequencesComparator.java b/src/main/java/org/apache/commons/collections4/sequence/SequencesComparator.java index daa48c0f01..f1ec95659f 100644 --- a/src/main/java/org/apache/commons/collections4/sequence/SequencesComparator.java +++ b/src/main/java/org/apache/commons/collections4/sequence/SequencesComparator.java @@ -264,11 +264,11 @@ private Snake getMiddleSnake(final int start1, final int end1, final int start2, return null; } - final int delta = m - n; - final int sum = n + m; + final int delta = m - n; + final int sum = n + m; final int offset = (sum % 2 == 0 ? sum : sum + 1) / 2; - vDown[1+offset] = start1; - vUp[1+offset] = end1 + 1; + vDown[1 + offset] = start1; + vUp[1 + offset] = end1 + 1; for (int d = 0; d <= offset; ++d) { // Down @@ -276,10 +276,10 @@ private Snake getMiddleSnake(final int start1, final int end1, final int start2, // First step final int i = k + offset; - if (k == -d || k != d && vDown[i-1] < vDown[i+1]) { - vDown[i] = vDown[i+1]; + if (k == -d || k != d && vDown[i - 1] < vDown[i + 1]) { + vDown[i] = vDown[i + 1]; } else { - vDown[i] = vDown[i-1] + 1; + vDown[i] = vDown[i - 1] + 1; } int x = vDown[i]; @@ -290,8 +290,8 @@ private Snake getMiddleSnake(final int start1, final int end1, final int start2, ++y; } // Second step - if (delta % 2 != 0 && delta - d <= k && k <= delta + d && vUp[i-delta] <= vDown[i]) { // NOPMD - return buildSnake(vUp[i-delta], k + start1 - start2, end1, end2); + if (delta % 2 != 0 && delta - d <= k && k <= delta + d && vUp[i - delta] <= vDown[i]) { // NOPMD + return buildSnake(vUp[i - delta], k + start1 - start2, end1, end2); } } @@ -299,17 +299,15 @@ private Snake getMiddleSnake(final int start1, final int end1, final int start2, for (int k = delta - d; k <= delta + d; k += 2) { // First step final int i = k + offset - delta; - if (k == delta - d - || k != delta + d && vUp[i+1] <= vUp[i-1]) { - vUp[i] = vUp[i+1] - 1; + if (k == delta - d || k != delta + d && vUp[i + 1] <= vUp[i - 1]) { + vUp[i] = vUp[i + 1] - 1; } else { - vUp[i] = vUp[i-1]; + vUp[i] = vUp[i - 1]; } int x = vUp[i] - 1; int y = x - start1 + start2 - k; - while (x >= start1 && y >= start2 - && equator.equate(sequence1.get(x), sequence2.get(y))) { + while (x >= start1 && y >= start2 && equator.equate(sequence1.get(x), sequence2.get(y))) { vUp[i] = x--; y--; } diff --git a/src/main/java/org/apache/commons/collections4/trie/AbstractPatriciaTrie.java b/src/main/java/org/apache/commons/collections4/trie/AbstractPatriciaTrie.java index 5ce903acb1..ec50fa7fff 100644 --- a/src/main/java/org/apache/commons/collections4/trie/AbstractPatriciaTrie.java +++ b/src/main/java/org/apache/commons/collections4/trie/AbstractPatriciaTrie.java @@ -2061,11 +2061,11 @@ public V put(final K key, final V value) { * Reads the content of the stream. */ @SuppressWarnings("unchecked") // This will fail at runtime if the stream is incorrect - private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException{ + private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); root = new TrieEntry<>(null, null, -1); final int size = stream.readInt(); - for (int i = 0; i < size; i++){ + for (int i = 0; i < size; i++) { final K k = (K) stream.readObject(); final V v = (V) stream.readObject(); put(k, v); @@ -2434,7 +2434,7 @@ public Collection values() { /** * Writes the content to the stream for serialization. */ - private void writeObject(final ObjectOutputStream stream) throws IOException{ + private void writeObject(final ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeInt(this.size()); for (final Entry entry : entrySet()) { diff --git a/src/test/java/org/apache/commons/collections4/AbstractLinkedListTest.java b/src/test/java/org/apache/commons/collections4/AbstractLinkedListTest.java index 04477a9543..698a610f34 100644 --- a/src/test/java/org/apache/commons/collections4/AbstractLinkedListTest.java +++ b/src/test/java/org/apache/commons/collections4/AbstractLinkedListTest.java @@ -31,12 +31,10 @@ /** * Tests base {@link java.util.LinkedList} methods and contracts. *

- * To use, simply extend this class, and implement - * the {@link #makeObject()} method. + * To use, simply extend this class, and implement the {@link #makeObject()} method. *

- * If your {@link LinkedList} fails one of these tests by design, - * you may still use this base set of cases. Simply override the - * test case (method) your {@link List} fails. + * If your {@link LinkedList} fails one of these tests by design, you may still use this base set of cases. Simply override the test case (method) your + * {@link List} fails. */ public abstract class AbstractLinkedListTest extends AbstractListTest { @@ -45,9 +43,9 @@ public AbstractLinkedListTest(final String testName) { } /** - * Returns the {@link #collection} field cast to a {@link LinkedList}. + * Returns the {@link #collection} field cast to a {@link LinkedList}. * - * @return the collection field as a List + * @return the collection field as a List */ @Override public LinkedList getCollection() { @@ -55,16 +53,16 @@ public LinkedList getCollection() { } /** - * Returns the {@link #confirmed} field cast to a {@link LinkedList}. + * Returns the {@link #confirmed} field cast to a {@link LinkedList}. * - * @return the confirmed field as a List + * @return the confirmed field as a List */ protected LinkedList getConfirmedLinkedList() { return (LinkedList) getConfirmed(); } /** - * Returns an empty {@link LinkedList}. + * Returns an empty {@link LinkedList}. */ @Override public Collection makeConfirmedCollection() { @@ -72,7 +70,7 @@ public Collection makeConfirmedCollection() { } /** - * Returns a full {@link LinkedList}. + * Returns a full {@link LinkedList}. */ @Override public Collection makeConfirmedFullCollection() { @@ -83,7 +81,7 @@ public Collection makeConfirmedFullCollection() { public abstract LinkedList makeObject(); /** - * Tests {@link LinkedList#addFirst(Object)}. + * Tests {@link LinkedList#addFirst(Object)}. */ @Test @SuppressWarnings("unchecked") @@ -105,7 +103,7 @@ public void testLinkedListAddFirst() { } /** - * Tests {@link LinkedList#addLast(Object)}. + * Tests {@link LinkedList#addLast(Object)}. */ @Test @SuppressWarnings("unchecked") @@ -127,43 +125,39 @@ public void testLinkedListAddLast() { } /** - * Tests {@link LinkedList#getFirst()}. + * Tests {@link LinkedList#getFirst()}. */ @Test public void testLinkedListGetFirst() { resetEmpty(); - assertThrows(NoSuchElementException.class, () -> getCollection().getFirst(), - "getFirst() should throw a NoSuchElementException for an empty list."); + assertThrows(NoSuchElementException.class, () -> getCollection().getFirst(), "getFirst() should throw a NoSuchElementException for an empty list."); verify(); resetFull(); final Object first = getCollection().getFirst(); final Object confirmedFirst = getConfirmedLinkedList().getFirst(); - assertEquals(confirmedFirst, first, - "Result returned by getFirst() was wrong."); + assertEquals(confirmedFirst, first, "Result returned by getFirst() was wrong."); verify(); } /** - * Tests {@link LinkedList#getLast()}. + * Tests {@link LinkedList#getLast()}. */ @Test public void testLinkedListGetLast() { resetEmpty(); - assertThrows(NoSuchElementException.class, () -> getCollection().getLast(), - "getLast() should throw a NoSuchElementException for an empty list."); + assertThrows(NoSuchElementException.class, () -> getCollection().getLast(), "getLast() should throw a NoSuchElementException for an empty list."); verify(); resetFull(); final Object last = getCollection().getLast(); final Object confirmedLast = getConfirmedLinkedList().getLast(); - assertEquals(confirmedLast, last, - "Result returned by getLast() was wrong."); + assertEquals(confirmedLast, last, "Result returned by getLast() was wrong."); verify(); } /** - * Tests {@link LinkedList#removeFirst()}. + * Tests {@link LinkedList#removeFirst()}. */ @Test public void testLinkedListRemoveFirst() { @@ -179,13 +173,12 @@ public void testLinkedListRemoveFirst() { resetFull(); final Object first = getCollection().removeFirst(); final Object confirmedFirst = getConfirmedLinkedList().removeFirst(); - assertEquals(confirmedFirst, first, - "Result returned by removeFirst() was wrong."); + assertEquals(confirmedFirst, first, "Result returned by removeFirst() was wrong."); verify(); } /** - * Tests {@link LinkedList#removeLast()}. + * Tests {@link LinkedList#removeLast()}. */ @Test public void testLinkedListRemoveLast() { @@ -194,15 +187,13 @@ public void testLinkedListRemoveLast() { } resetEmpty(); - assertThrows(NoSuchElementException.class, () -> getCollection().removeLast(), - "removeLast() should throw a NoSuchElementException for an empty list."); + assertThrows(NoSuchElementException.class, () -> getCollection().removeLast(), "removeLast() should throw a NoSuchElementException for an empty list."); verify(); resetFull(); final Object last = getCollection().removeLast(); final Object confirmedLast = getConfirmedLinkedList().removeLast(); - assertEquals(confirmedLast, last, - "Result returned by removeLast() was wrong."); + assertEquals(confirmedLast, last, "Result returned by removeLast() was wrong."); verify(); } diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java index 497effce68..63fca40229 100644 --- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java @@ -280,12 +280,12 @@ public void forAllButLastDoCollection() { final Collection strings = Arrays.asList("a", "b", "c"); final StringBuilder result = new StringBuilder(); - result.append(CollectionUtils.forAllButLastDo(strings, (Closure) input -> result.append(input+";"))); + result.append(CollectionUtils.forAllButLastDo(strings, (Closure) input -> result.append(input + ";"))); assertEquals("a;b;c", result.toString()); final Collection oneString = Arrays.asList("a"); final StringBuilder resultOne = new StringBuilder(); - resultOne.append(CollectionUtils.forAllButLastDo(oneString, (Closure) input -> resultOne.append(input+";"))); + resultOne.append(CollectionUtils.forAllButLastDo(oneString, (Closure) input -> resultOne.append(input + ";"))); assertEquals("a", resultOne.toString()); assertNull(CollectionUtils.forAllButLastDo(strings, (Closure) null)); // do not remove cast assertNull(CollectionUtils.forAllButLastDo((Collection) null, (Closure) null)); // do not remove cast diff --git a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java index 9b8ecb9e2a..676dd231f7 100644 --- a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java @@ -247,7 +247,7 @@ public void testDebugPrintNullKeyToMap2() { final String INDENT = " "; final Map map = new HashMap<>(); - final Map map2= new HashMap<>(); + final Map map2 = new HashMap<>(); map.put(null, map2); map2.put("2", "B"); diff --git a/src/test/java/org/apache/commons/collections4/TestUtils.java b/src/test/java/org/apache/commons/collections4/TestUtils.java index fd80a9e70e..c87e14ac7a 100644 --- a/src/test/java/org/apache/commons/collections4/TestUtils.java +++ b/src/test/java/org/apache/commons/collections4/TestUtils.java @@ -76,5 +76,8 @@ public static void assertSameAfterSerialization(final String msg, final Object o } } - private TestUtils() {} + private TestUtils() { + // empty + } + } diff --git a/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java b/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java index 939d7a43df..2dd9fef3c5 100644 --- a/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java +++ b/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java @@ -81,7 +81,7 @@ public T[] getFullElements() { } @Override - protected int getIterationBehaviour(){ + protected int getIterationBehaviour() { return AbstractBagTest.this.getIterationBehaviour(); } diff --git a/src/test/java/org/apache/commons/collections4/bag/SynchronizedBagTest.java b/src/test/java/org/apache/commons/collections4/bag/SynchronizedBagTest.java index 5e0128147c..483bce8f5c 100644 --- a/src/test/java/org/apache/commons/collections4/bag/SynchronizedBagTest.java +++ b/src/test/java/org/apache/commons/collections4/bag/SynchronizedBagTest.java @@ -19,8 +19,7 @@ import org.apache.commons.collections4.Bag; /** - * Extension of {@link AbstractBagTest} for exercising the {@link SynchronizedBag} - * implementation. + * Extension of {@link AbstractBagTest} for exercising the {@link SynchronizedBag} implementation. */ public class SynchronizedBagTest extends AbstractBagTest { @@ -34,7 +33,7 @@ public String getCompatibilityVersion() { } @Override - protected int getIterationBehaviour(){ + protected int getIterationBehaviour() { return UNORDERED; } 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 0b198af6ec..0cb194337a 100644 --- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java +++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java @@ -149,7 +149,9 @@ public void testNextKey() { if (!isAllowNullKey()) { try { assertNull(bidi.nextKey(null)); // this is allowed too - } catch (final NullPointerException ex) {} + } catch (final NullPointerException ignore) { + // ignore + } } else { assertNull(bidi.nextKey(null)); } @@ -182,7 +184,9 @@ public void testPreviousKey() { if (!isAllowNullKey()) { try { assertNull(bidi.previousKey(null)); // this is allowed too - } catch (final NullPointerException ex) {} + } catch (final NullPointerException ignore) { + // ignore + } } else { assertNull(bidi.previousKey(null)); } diff --git a/src/test/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap2Test.java b/src/test/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap2Test.java index 97578f2da0..45890f11b9 100644 --- a/src/test/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap2Test.java +++ b/src/test/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap2Test.java @@ -42,8 +42,9 @@ @SuppressWarnings("boxing") public class DualTreeBidiMap2Test, V extends Comparable> extends AbstractSortedBidiMapTest { - private static final class IntegerComparator implements Comparator, Serializable{ + private static final class IntegerComparator implements Comparator, Serializable { private static final long serialVersionUID = 1L; + @Override public int compare(final Integer o1, final Integer o2) { return o1.compareTo(o2); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java index 7ed18c9c37..a0eaa4a5c4 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java @@ -221,19 +221,17 @@ public final void testContains() { BitMapProducer bitMapProducer = BitMapProducer.fromIndexProducer(new IncrementingHasher(1, 1).indices(getTestShape()), getTestShape().getNumberOfBits()); assertTrue(bf2.contains(bitMapProducer), "BF2 Should contain this hasher"); - bitMapProducer = BitMapProducer.fromIndexProducer(new IncrementingHasher(1, 3).indices(getTestShape()), - getTestShape().getNumberOfBits()); + bitMapProducer = BitMapProducer.fromIndexProducer(new IncrementingHasher(1, 3).indices(getTestShape()), getTestShape().getNumberOfBits()); assertFalse(bf2.contains(bitMapProducer), "BF2 Should not contain this hasher"); // Test different lengths bf1 = createFilter(getTestShape(), TestingHashers.FROM1); - final BloomFilter bf3 = createFilter(Shape.fromKM(getTestShape().getNumberOfHashFunctions(), Long.SIZE - 1), - TestingHashers.FROM1); + final BloomFilter bf3 = createFilter(Shape.fromKM(getTestShape().getNumberOfHashFunctions(), Long.SIZE - 1), TestingHashers.FROM1); assertTrue(bf1.contains(bf3)); assertTrue(bf3.contains(bf1)); - final BloomFilter bf4 = TestingHashers.populateRange(createEmptyFilter(Shape.fromKM(getTestShape().getNumberOfHashFunctions(), Long.SIZE - 1)), - 1, 11+getTestShape().getNumberOfHashFunctions()); + final BloomFilter bf4 = TestingHashers.populateRange(createEmptyFilter(Shape.fromKM(getTestShape().getNumberOfHashFunctions(), Long.SIZE - 1)), 1, + 11 + getTestShape().getNumberOfHashFunctions()); assertFalse(bf1.contains(bf4)); assertTrue(bf4.contains(bf1)); @@ -253,7 +251,6 @@ public void testEmptyAfterMergeWithNothing() { */ @Test public final void testEstimateIntersection() { - final BloomFilter bf = createFilter(getTestShape(), TestingHashers.FROM1); final BloomFilter bf2 = TestingHashers.populateFromHashersFrom1AndFrom11(createEmptyFilter(getTestShape())); @@ -272,7 +269,7 @@ public final void testEstimateIntersection() { final int midPoint = getTestShape().getNumberOfBits() / 2; final BloomFilter bf5 = TestingHashers.populateRange(createEmptyFilter(getTestShape()), 0, midPoint); - final BloomFilter bf6 = TestingHashers.populateRange(createEmptyFilter(getTestShape()), midPoint+1, getTestShape().getNumberOfBits()-1); + final BloomFilter bf6 = TestingHashers.populateRange(createEmptyFilter(getTestShape()), midPoint + 1, getTestShape().getNumberOfBits() - 1); assertThrows(IllegalArgumentException.class, () -> bf5.estimateIntersection(bf6)); // infinite with infinite diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromBloomFilterArrayTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromBloomFilterArrayTest.java index 56015d7f41..f18025e5b3 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromBloomFilterArrayTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromBloomFilterArrayTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.collections4.bloomfilter; -public class BloomFilterProducerFromBloomFilterArrayTest extends AbstractBloomFilterProducerTest{ +public class BloomFilterProducerFromBloomFilterArrayTest extends AbstractBloomFilterProducerTest { @Override protected BloomFilterProducer createUnderTest(final BloomFilter... filters) { diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromLayeredBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromLayeredBloomFilterTest.java index 29f209f036..1c298f80ee 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromLayeredBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromLayeredBloomFilterTest.java @@ -16,14 +16,13 @@ */ package org.apache.commons.collections4.bloomfilter; -public class BloomFilterProducerFromLayeredBloomFilterTest extends AbstractBloomFilterProducerTest{ +public class BloomFilterProducerFromLayeredBloomFilterTest extends AbstractBloomFilterProducerTest { @Override protected BloomFilterProducer createUnderTest(final BloomFilter... filters) { final Shape shape = filters[0].getShape(); - final LayerManager layerManager = LayerManager.builder().setSupplier( () -> new SimpleBloomFilter(shape) ) - .setExtendCheck( LayerManager.ExtendCheck.advanceOnPopulated()) - .setCleanup(LayerManager.Cleanup.noCleanup()).build(); + final LayerManager layerManager = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(shape)) + .setExtendCheck(LayerManager.ExtendCheck.advanceOnPopulated()).setCleanup(LayerManager.Cleanup.noCleanup()).build(); final LayeredBloomFilter underTest = new LayeredBloomFilter(shape, layerManager); for (final BloomFilter bf : filters) { underTest.merge(bf); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/CountingPredicateTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/CountingPredicateTest.java index cc1cecc27b..2e925db0a4 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/CountingPredicateTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/CountingPredicateTest.java @@ -51,7 +51,7 @@ public void testPredicateLonger() { final List> result = new ArrayList<>(); expected.add(Pair.of(1, 3)); - CountingPredicate cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x!=null, result)); + CountingPredicate cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x != null, result)); assertTrue(cp.test(Integer.valueOf(3))); assertEquals(expected, result); expected.add(Pair.of(2, null)); @@ -64,16 +64,16 @@ public void testPredicateLonger() { expected.add(Pair.of(1, null)); expected.add(Pair.of(2, null)); result.clear(); - cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x!=null, result)); + cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x != null, result)); assertTrue(cp.forEachRemaining()); - assertEquals( expected, result); + assertEquals(expected, result); // If a test fails then the result should be false and the rest of the list should // not be processed. expected.clear(); expected.add(Pair.of(1, null)); result.clear(); - cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x == Integer.valueOf(1), result)); + cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x == Integer.valueOf(1), result)); assertFalse(cp.forEachRemaining()); assertEquals(expected, result); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromSparseBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromSparseBloomFilterTest.java index ba7f958c16..6ad25e4400 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromSparseBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromSparseBloomFilterTest.java @@ -35,11 +35,11 @@ protected IndexProducer createProducer() { @Override protected int getAsIndexArrayBehaviour() { - return DISTINCT |ORDERED; + return DISTINCT | ORDERED; } @Override protected int[] getExpectedIndices() { - return new int[] {2, 4, 9, 11, 16, 18, 23, 25, 30, 32, 37, 39, 44, 46, 53, 60, 67}; + return new int[] { 2, 4, 9, 11, 16, 18, 23, 25, 30, 32, 37, 39, 44, 46, 53, 60, 67 }; } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/LayerManagerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/LayerManagerTest.java index e9ff966a9e..09ffac2e74 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/LayerManagerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/LayerManagerTest.java @@ -78,7 +78,7 @@ public void testAdvanceOnSaturation() { while (layerManager.getTarget().getShape().estimateN(layerManager.getTarget().cardinality()) < maxN) { assertFalse(underTest.test(layerManager)); layerManager.getTarget().merge(new IncrementingHasher(hashStart, shape.getNumberOfHashFunctions())); - hashStart+=shape.getNumberOfHashFunctions(); + hashStart += shape.getNumberOfHashFunctions(); } assertTrue(underTest.test(layerManager)); assertThrows(IllegalArgumentException.class, () -> LayerManager.ExtendCheck.advanceOnSaturation(0)); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java b/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java index 0f2e62f8b8..78f95ace20 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java @@ -90,11 +90,14 @@ public static T populateRange(final T filter, final int * Creates an EnhancedDoubleHasher hasher from 2 random longs. */ public static Hasher randomHasher() { - return new EnhancedDoubleHasher( ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong() ); + return new EnhancedDoubleHasher(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong()); } /** * Do not instantiate. */ - private TestingHashers() {} + private TestingHashers() { + // empty + } + } 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 06f59830fa..0f5f2f57d0 100644 --- a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java @@ -384,7 +384,7 @@ public Object[] getFullNonNullStringElements() { * @return the iteration behavior * @see #UNORDERED */ - protected int getIterationBehaviour(){ + protected int getIterationBehaviour() { return 0; } diff --git a/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java b/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java index a305a20810..fe519047ce 100644 --- a/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java +++ b/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java @@ -137,20 +137,19 @@ public FixedOrderComparatorTest() { /** Shuffles the keys and asserts that the comparator sorts them back to * their original order. */ - private void assertComparatorYieldsOrder(final String[] orderedObjects, - final Comparator comparator) { + private void assertComparatorYieldsOrder(final String[] orderedObjects, final Comparator comparator) { final String[] keys = orderedObjects.clone(); - // shuffle until the order changes. It's extremely rare that + // shuffle until the order changes. It's extremely rare that // this requires more than one shuffle. boolean isInNewOrder = false; final Random rand = new Random(); while (keys.length > 1 && !isInNewOrder) { // shuffle: - for (int i = keys.length-1; i > 0; i--) { + for (int i = keys.length - 1; i > 0; i--) { final String swap = keys[i]; - final int j = rand.nextInt(i+1); + final int j = rand.nextInt(i + 1); keys[i] = keys[j]; keys[j] = swap; } @@ -164,7 +163,7 @@ private void assertComparatorYieldsOrder(final String[] orderedObjects, } } - // The real test: sort and make sure they come out right. + // The real test: sort and make sure they come out right. Arrays.sort(keys, comparator); 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 0139b422d5..b1779571a9 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/AbstractIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/AbstractIteratorTest.java @@ -159,7 +159,8 @@ public void testRemove() { // check for UnsupportedOperationException if not supported try { it.remove(); - } catch (final UnsupportedOperationException ex) {} + } catch (final UnsupportedOperationException ex) { + } return; } diff --git a/src/test/java/org/apache/commons/collections4/iterators/NodeListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/NodeListIteratorTest.java index d5fa77be53..c54ec547db 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/NodeListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/NodeListIteratorTest.java @@ -56,6 +56,7 @@ public Iterator makeEmptyIterator() { public int getLength() { return 0; } + @Override public Node item(final int index) { throw new IndexOutOfBoundsException(); @@ -79,6 +80,7 @@ public Iterator makeObject() { public int getLength() { return nodes.length; } + @Override public Node item(final int index) { return nodes[index]; @@ -99,7 +101,7 @@ protected void setUp() throws Exception { final Node node2 = createMock(Element.class); final Node node3 = createMock(Text.class); final Node node4 = createMock(Element.class); - nodes = new Node[] {node1, node2, node3, node4}; + nodes = new Node[] { node1, node2, node3, node4 }; replay(node1); replay(node2); @@ -116,7 +118,7 @@ public boolean supportsRemove() { * tests the convenience Constructor with parameter type org.w3c.Node */ @Test - public void testEmptyIteratorWithNodeConstructor(){ + public void testEmptyIteratorWithNodeConstructor() { createIteratorWithStandardConstr = false; testEmptyIterator(); } @@ -125,7 +127,7 @@ public void testEmptyIteratorWithNodeConstructor(){ * tests the convenience Constructor with parameter type org.w3c.Node */ @Test - public void testFullIteratorWithNodeConstructor(){ + public void testFullIteratorWithNodeConstructor() { createIteratorWithStandardConstr = false; testFullIterator(); } diff --git a/src/test/java/org/apache/commons/collections4/iterators/PermutationIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/PermutationIteratorTest.java index a8203ec0dd..83537d2e32 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/PermutationIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/PermutationIteratorTest.java @@ -151,7 +151,7 @@ public void testPermutationExhaustivity() { @SuppressWarnings("boxing") // OK in test code public void testPermutationResultSize() { int factorial = 1; - for (int i = 0; i < 8; i++, factorial*=i) { + for (int i = 0; i < 8; i++, factorial *= i) { final List list = new ArrayList<>(); for (int j = 0; j < i; j++) { list.add(j); 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 2ebba47274..2803e3e40d 100644 --- a/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java +++ b/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java @@ -87,7 +87,7 @@ public int hashCode() { } private Object readResolve() { - hashCode=2; // simulate different hashCode after deserialization in another process + hashCode = 2; // simulate different hashCode after deserialization in another process return this; } } diff --git a/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java b/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java index 452dceec73..397cb03d01 100644 --- a/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java @@ -37,8 +37,7 @@ protected void checkNodes() { for (int i = 0; i < list.size; i++) { assertEquals(list.getNode(i, false).next, list.getNode(i + 1, true)); if (i < list.size - 1) { - assertEquals(list.getNode(i + 1, false).previous, - list.getNode(i, false)); + assertEquals(list.getNode(i + 1, false).previous, list.getNode(i, false)); } } } @@ -59,7 +58,8 @@ public void testAddNodeAfter() { if (!isAddSupported()) { try { list.addFirst(null); - } catch (final UnsupportedOperationException ex) {} + } catch (final UnsupportedOperationException ex) { + } } list.addFirst((E) "value1"); @@ -92,20 +92,16 @@ public void testGetNode() { final AbstractLinkedList list = getCollection(); // get marker assertEquals(list.getNode(0, true).previous, list.getNode(0, true).next); - assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(0, false), - "Expecting IndexOutOfBoundsException."); - list.addAll( Arrays.asList((E[]) new String[]{"value1", "value2"})); + assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(0, false), "Expecting IndexOutOfBoundsException."); + list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" })); checkNodes(); list.addFirst((E) "value0"); checkNodes(); list.removeNode(list.getNode(1, false)); checkNodes(); - assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(2, false), - "Expecting IndexOutOfBoundsException."); - assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(-1, false), - "Expecting IndexOutOfBoundsException."); - assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(3, true), - "Expecting IndexOutOfBoundsException."); + assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(2, false), "Expecting IndexOutOfBoundsException."); + assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(-1, false), "Expecting IndexOutOfBoundsException."); + assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(3, true), "Expecting IndexOutOfBoundsException."); } @Test @@ -116,7 +112,8 @@ public void testRemoveFirst() { if (!isRemoveSupported()) { try { list.removeFirst(); - } catch (final UnsupportedOperationException ex) {} + } catch (final UnsupportedOperationException ex) { + } } list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" })); @@ -141,7 +138,8 @@ public void testRemoveLast() { if (!isRemoveSupported()) { try { list.removeLast(); - } catch (final UnsupportedOperationException ex) {} + } catch (final UnsupportedOperationException ex) { + } } list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" })); 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 8d67aac9b5..960e5276f4 100644 --- a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java @@ -817,11 +817,13 @@ public void testListListIteratorByIndex() { resetFull(); try { getCollection().listIterator(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); try { getCollection().listIterator(getCollection().size() + 1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); for (int i = 0; i <= getConfirmed().size(); i++) { forwardTest(getCollection().listIterator(i), i); diff --git a/src/test/java/org/apache/commons/collections4/list/DefaultAbstractLinkedListForJava21Test.java b/src/test/java/org/apache/commons/collections4/list/DefaultAbstractLinkedListForJava21Test.java index c507493026..e831ede3e9 100644 --- a/src/test/java/org/apache/commons/collections4/list/DefaultAbstractLinkedListForJava21Test.java +++ b/src/test/java/org/apache/commons/collections4/list/DefaultAbstractLinkedListForJava21Test.java @@ -57,8 +57,7 @@ protected void checkNodes() { for (int i = 0; i < list.size; i++) { assertEquals(list.getNode(i, false).next, list.getNode(i + 1, true)); if (i < list.size - 1) { - assertEquals(list.getNode(i + 1, false).previous, - list.getNode(i, false)); + assertEquals(list.getNode(i + 1, false).previous, list.getNode(i, false)); } } } @@ -91,7 +90,8 @@ public void testAddNodeAfter() { if (!isAddSupported()) { try { list.addFirst(null); - } catch (final UnsupportedOperationException ex) {} + } catch (final UnsupportedOperationException ex) { + } } list.addFirst((E) "value1"); @@ -124,20 +124,16 @@ public void testGetNode() { final AbstractLinkedListForJava21 list = getCollection(); // get marker assertEquals(list.getNode(0, true).previous, list.getNode(0, true).next); - assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(0, false), - "Expecting IndexOutOfBoundsException."); - list.addAll( Arrays.asList((E[]) new String[]{"value1", "value2"})); + assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(0, false), "Expecting IndexOutOfBoundsException."); + list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" })); checkNodes(); list.addFirst((E) "value0"); checkNodes(); list.removeNode(list.getNode(1, false)); checkNodes(); - assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(2, false), - "Expecting IndexOutOfBoundsException."); - assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(-1, false), - "Expecting IndexOutOfBoundsException."); - assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(3, true), - "Expecting IndexOutOfBoundsException."); + assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(2, false), "Expecting IndexOutOfBoundsException."); + assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(-1, false), "Expecting IndexOutOfBoundsException."); + assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(3, true), "Expecting IndexOutOfBoundsException."); } @Test @@ -148,7 +144,8 @@ public void testRemoveFirst() { if (!isRemoveSupported()) { try { list.removeFirst(); - } catch (final UnsupportedOperationException ex) {} + } catch (final UnsupportedOperationException ex) { + } } list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" })); @@ -173,7 +170,8 @@ public void testRemoveLast() { if (!isRemoveSupported()) { try { list.removeLast(); - } catch (final UnsupportedOperationException ex) {} + } catch (final UnsupportedOperationException ex) { + } } list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" })); 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 7891346584..5a845ae775 100644 --- a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java @@ -51,14 +51,10 @@ /** * Abstract test class for {@link java.util.Map} methods and contracts. *

- * The forces at work here are similar to those in {@link AbstractCollectionTest}. - * If your class implements the full Map interface, including optional - * operations, simply extend this class, and implement the - * {@link #makeObject()} method. + * The forces at work here are similar to those in {@link AbstractCollectionTest}. If your class implements the full Map interface, including optional + * operations, simply extend this class, and implement the {@link #makeObject()} method. *

- * On the other hand, if your map implementation is weird, you may have to - * override one or more of the other protected methods. They're described - * below. + * On the other hand, if your map implementation is weird, you may have to override one or more of the other protected methods. They're described below. *

* Entry Population Methods *

@@ -84,58 +80,45 @@ * Override these methods if your map doesn't support certain operations: * *

    - *
  • {@link #isPutAddSupported()} - *
  • {@link #isPutChangeSupported()} - *
  • {@link #isSetValueSupported()} - *
  • {@link #isRemoveSupported()} - *
  • {@link #isGetStructuralModify()} - *
  • {@link #isAllowDuplicateValues()} - *
  • {@link #isAllowNullKey()} - *
  • {@link #isAllowNullValue()} + *
  • {@link #isPutAddSupported()} + *
  • {@link #isPutChangeSupported()} + *
  • {@link #isSetValueSupported()} + *
  • {@link #isRemoveSupported()} + *
  • {@link #isGetStructuralModify()} + *
  • {@link #isAllowDuplicateValues()} + *
  • {@link #isAllowNullKey()} + *
  • {@link #isAllowNullValue()} *
* * Fixture Methods *

- * For tests on modification operations (puts and removes), fixtures are used - * to verify that that operation results in correct state for the map and its - * collection views. Basically, the modification is performed against your - * map implementation, and an identical modification is performed against - * a confirmed map implementation. A confirmed map implementation is - * something like java.util.HashMap, which is known to conform - * exactly to the {@link Map} contract. After the modification takes place - * on both your map implementation and the confirmed map implementation, the - * two maps are compared to see if their state is identical. The comparison - * also compares the collection views to make sure they're still the same.

+ * For tests on modification operations (puts and removes), fixtures are used to verify that that operation results in correct state for the map and its + * collection views. Basically, the modification is performed against your map implementation, and an identical modification is performed against a + * confirmed map implementation. A confirmed map implementation is something like java.util.HashMap, which is known to conform exactly to + * the {@link Map} contract. After the modification takes place on both your map implementation and the confirmed map implementation, the two maps are compared + * to see if their state is identical. The comparison also compares the collection views to make sure they're still the same. + *

* - * The upshot of all that is that any test that modifies the map in - * any way will verify that all of the map's state is still - * correct, including the state of its collection views. So for instance - * if a key is removed by the map's key set's iterator, then the entry set - * is checked to make sure the key/value pair no longer appears.

+ * The upshot of all that is that any test that modifies the map in any way will verify that all of the map's state is still correct, + * including the state of its collection views. So for instance if a key is removed by the map's key set's iterator, then the entry set is checked to make sure + * the key/value pair no longer appears. + *

* - * The {@link #map} field holds an instance of your collection implementation. - * The {@link #entrySet}, {@link #keySet} and {@link #values} fields hold - * that map's collection views. And the {@link #confirmed} field holds - * an instance of the confirmed collection implementation. The - * {@link #resetEmpty()} and {@link #resetFull()} methods set these fields to - * empty or full maps, so that tests can proceed from a known state.

+ * The {@link #map} field holds an instance of your collection implementation. The {@link #entrySet}, {@link #keySet} and {@link #values} fields hold that map's + * collection views. And the {@link #confirmed} field holds an instance of the confirmed collection implementation. The {@link #resetEmpty()} and + * {@link #resetFull()} methods set these fields to empty or full maps, so that tests can proceed from a known state. + *

* - * After a modification operation to both {@link #map} and {@link #confirmed}, - * the {@link #verify()} method is invoked to compare the results. The - * {@link #verify} method calls separate methods to verify the map and its three - * collection views ({@link #verifyMap}, {@link #verifyEntrySet}, - * {@link #verifyKeySet}, and {@link #verifyValues}). You may want to override - * one of the verification methods to perform additional verifications. For - * instance, TestDoubleOrderedMap would want override its - * {@link #verifyValues()} method to verify that the values are unique and in - * ascending order.

+ * After a modification operation to both {@link #map} and {@link #confirmed}, the {@link #verify()} method is invoked to compare the results. The + * {@link #verify} method calls separate methods to verify the map and its three collection views ({@link #verifyMap}, {@link #verifyEntrySet}, + * {@link #verifyKeySet}, and {@link #verifyValues}). You may want to override one of the verification methods to perform additional verifications. For + * instance, TestDoubleOrderedMap would want override its {@link #verifyValues()} method to verify that the values are unique and in ascending order. + *

* * Other Notes *

- * If your {@link Map} fails one of these tests by design, you may still use - * this base set of cases. Simply override the test case (method) your map - * fails and/or the methods that define the assumptions used by the test - * cases. For example, if your map does not allow duplicate values, override + * If your {@link Map} fails one of these tests by design, you may still use this base set of cases. Simply override the test case (method) your map fails + * and/or the methods that define the assumptions used by the test cases. For example, if your map does not allow duplicate values, override * {@link #isAllowDuplicateValues()} and have it return {@code false} */ public abstract class AbstractMapTest extends AbstractObjectTest { @@ -188,7 +171,7 @@ public Map.Entry[] getFullNonNullElements() { } @Override - protected int getIterationBehaviour(){ + protected int getIterationBehaviour() { return AbstractMapTest.this.getIterationBehaviour(); } @@ -265,7 +248,7 @@ public void testMapEntrySetIteratorEntrySetValue() { final K key1 = getSampleKeys()[0]; final K key2 = getSampleKeys().length == 1 ? getSampleKeys()[0] : getSampleKeys()[1]; final V newValue1 = getNewSampleValues()[0]; - final V newValue2 = getNewSampleValues().length ==1 ? getNewSampleValues()[0] : getNewSampleValues()[1]; + final V newValue2 = getNewSampleValues().length == 1 ? getNewSampleValues()[0] : getNewSampleValues()[1]; resetFull(); // explicitly get entries as sample values/keys are connected for some maps @@ -329,6 +312,7 @@ public void verify() { AbstractMapTest.this.verify(); } } + public class TestMapKeySet extends AbstractSetTest { public TestMapKeySet() { super(StringUtils.EMPTY); @@ -340,7 +324,7 @@ public K[] getFullElements() { } @Override - protected int getIterationBehaviour(){ + protected int getIterationBehaviour() { return AbstractMapTest.this.getIterationBehaviour(); } @@ -427,7 +411,7 @@ public V[] getFullElements() { } @Override - protected int getIterationBehaviour(){ + protected int getIterationBehaviour() { return AbstractMapTest.this.getIterationBehaviour(); } @@ -530,15 +514,14 @@ public static Map.Entry cloneMapEntry(final Map.Entry entry) /** * JUnit constructor. * - * @param testName the test name + * @param testName the test name */ public AbstractMapTest(final String testName) { super(testName); } /** - * Helper method to add all the mappings described by - * {@link #getSampleKeys()} and {@link #getSampleValues()}. + * Helper method to add all the mappings described by {@link #getSampleKeys()} and {@link #getSampleValues()}. */ public void addSampleMappings(final Map m) { @@ -549,23 +532,18 @@ public void addSampleMappings(final Map m) { try { m.put(keys[i], values[i]); } catch (final NullPointerException exception) { - assertTrue(keys[i] == null || values[i] == null, - "NullPointerException only allowed to be thrown " + - "if either the key or value is null."); + assertTrue(keys[i] == null || values[i] == null, "NullPointerException only allowed to be thrown " + "if either the key or value is null."); assertTrue(keys[i] == null || !isAllowNullKey(), - "NullPointerException on null key, but " + - "isAllowNullKey is not overridden to return false."); + "NullPointerException on null key, but " + "isAllowNullKey is not overridden to return false."); assertTrue(values[i] == null || !isAllowNullValue(), - "NullPointerException on null value, but " + - "isAllowNullValue is not overridden to return false."); + "NullPointerException on null value, but " + "isAllowNullValue is not overridden to return false."); fail("Unknown reason for NullPointer."); } } - assertEquals(keys.length, m.size(), - "size must reflect number of mappings added."); + assertEquals(keys.length, m.size(), "size must reflect number of mappings added."); } public boolean areEqualElementsDistinguishable() { @@ -573,10 +551,8 @@ public boolean areEqualElementsDistinguishable() { } /** - * Bulk test {@link Map#entrySet()}. This method runs through all of - * the tests in {@link AbstractSetTest}. - * After modification operations, {@link #verify()} is invoked to ensure - * that the map and the other collection views are still valid. + * Bulk test {@link Map#entrySet()}. This method runs through all of the tests in {@link AbstractSetTest}. After modification operations, {@link #verify()} + * is invoked to ensure that the map and the other collection views are still valid. * * @return a {@link AbstractSetTest} instance for testing the map's entry set */ @@ -585,10 +561,8 @@ public BulkTest bulkTestMapEntrySet() { } /** - * Bulk test {@link Map#keySet()}. This method runs through all of - * the tests in {@link AbstractSetTest}. - * After modification operations, {@link #verify()} is invoked to ensure - * that the map and the other collection views are still valid. + * Bulk test {@link Map#keySet()}. This method runs through all of the tests in {@link AbstractSetTest}. After modification operations, {@link #verify()} is + * invoked to ensure that the map and the other collection views are still valid. * * @return a {@link AbstractSetTest} instance for testing the map's key set */ @@ -597,13 +571,10 @@ public BulkTest bulkTestMapKeySet() { } /** - * Bulk test {@link Map#values()}. This method runs through all of - * the tests in {@link AbstractCollectionTest}. - * After modification operations, {@link #verify()} is invoked to ensure - * that the map and the other collection views are still valid. + * Bulk test {@link Map#values()}. This method runs through all of the tests in {@link AbstractCollectionTest}. After modification operations, + * {@link #verify()} is invoked to ensure that the map and the other collection views are still valid. * - * @return a {@link AbstractCollectionTest} instance for testing the map's - * values collection + * @return a {@link AbstractCollectionTest} instance for testing the map's values collection */ public BulkTest bulkTestMapValues() { return new TestMapValues(); @@ -628,6 +599,7 @@ public String getCompatibilityVersion() { /** * Gets the confirmed. + * * @return Map */ public Map getConfirmed() { @@ -635,19 +607,19 @@ public Map getConfirmed() { } /** - * Return a flag specifying the iteration behavior of the collection. - * This is used to change the assertions used by specific tests. - * The default implementation returns 0 which indicates ordered iteration behavior. + * Return a flag specifying the iteration behavior of the collection. This is used to change the assertions used by specific tests. The default + * implementation returns 0 which indicates ordered iteration behavior. * * @return the iteration behavior * @see AbstractCollectionTest#UNORDERED */ - protected int getIterationBehaviour(){ + protected int getIterationBehaviour() { return 0; } /** * Gets the map. + * * @return Map */ public Map getMap() { @@ -655,26 +627,16 @@ public Map getMap() { } /** - * Returns a set of values that can be used to replace the values - * returned from {@link #getSampleValues()}. This method must return an - * array with the same length as {@link #getSampleValues()}. The values - * returned from this method should not be the same as those returned from - * {@link #getSampleValues()}. The default implementation constructs a - * set of String values and includes a single null value if - * {@link #isAllowNullValue()} returns {@code true}, and includes two values - * that are the same if {@link #isAllowDuplicateValues()} returns - * {@code true}. + * Returns a set of values that can be used to replace the values returned from {@link #getSampleValues()}. This method must return an array with the same + * length as {@link #getSampleValues()}. The values returned from this method should not be the same as those returned from {@link #getSampleValues()}. The + * default implementation constructs a set of String values and includes a single null value if {@link #isAllowNullValue()} returns {@code true}, and + * includes two values that are the same if {@link #isAllowDuplicateValues()} returns {@code true}. */ @SuppressWarnings("unchecked") public V[] getNewSampleValues() { - final Object[] result = { - isAllowNullValue() && isAllowDuplicateValues() ? null : "newnonnullvalue", - "newvalue", - isAllowDuplicateValues() ? "newvalue" : "newvalue2", - "newblahv", "newfoov", "newbarv", "newbazv", "newtmpv", "newgoshv", - "newgollyv", "newgeev", "newhellov", "newgoodbyev", "newwe'llv", - "newseev", "newyouv", "newallv", "newagainv", - }; + final Object[] result = { isAllowNullValue() && isAllowDuplicateValues() ? null : "newnonnullvalue", "newvalue", + isAllowDuplicateValues() ? "newvalue" : "newvalue2", "newblahv", "newfoov", "newbarv", "newbazv", "newtmpv", "newgoshv", "newgollyv", "newgeev", + "newhellov", "newgoodbyev", "newwe'llv", "newseev", "newyouv", "newallv", "newagainv" }; return (V[]) result; } @@ -684,18 +646,15 @@ public K[] getOtherKeys() { } /** - * Returns a list of string elements suitable for return by - * {@link #getOtherKeys()} or {@link #getOtherValues}. + * Returns a list of string elements suitable for return by {@link #getOtherKeys()} or {@link #getOtherValues}. * - *

Override getOtherElements to return the results of this method if your - * collection does not support heterogeneous elements or the null element. + *

+ * Override getOtherElements to return the results of this method if your collection does not support heterogeneous elements or the null element. *

*/ public Object[] getOtherNonNullStringElements() { - return new Object[] { - "For", "then", "despite", /* of */"space", "I", "would", "be", "brought", - "From", "limits", "far", "remote", "where", "thou", "dost", "stay" - }; + return new Object[] { "For", "then", "despite", /* of */"space", "I", "would", "be", "brought", "From", "limits", "far", "remote", "where", "thou", + "dost", "stay" }; } @SuppressWarnings("unchecked") @@ -704,165 +663,121 @@ public V[] getOtherValues() { } /** - * Returns the set of keys in the mappings used to test the map. This - * method must return an array with the same length as {@link - * #getSampleValues()} and all array elements must be different. The - * default implementation constructs a set of String keys, and includes a - * single null key if {@link #isAllowNullKey()} returns {@code true}. + * Returns the set of keys in the mappings used to test the map. This method must return an array with the same length as {@link #getSampleValues()} and all + * array elements must be different. The default implementation constructs a set of String keys, and includes a single null key if {@link #isAllowNullKey()} + * returns {@code true}. */ @SuppressWarnings("unchecked") public K[] getSampleKeys() { - final Object[] result = { - "blah", "foo", "bar", "baz", "tmp", "gosh", "golly", "gee", - "hello", "goodbye", "we'll", "see", "you", "all", "again", - "key", - "key2", - isAllowNullKey() ? null : "nonnullkey" - }; + final Object[] result = { "blah", "foo", "bar", "baz", "tmp", "gosh", "golly", "gee", "hello", "goodbye", "we'll", "see", "you", "all", "again", "key", + "key2", isAllowNullKey() ? null : "nonnullkey" }; return (K[]) result; } /** - * Returns the set of values in the mappings used to test the map. This - * method must return an array with the same length as - * {@link #getSampleKeys()}. The default implementation constructs a set of - * String values and includes a single null value if - * {@link #isAllowNullValue()} returns {@code true}, and includes - * two values that are the same if {@link #isAllowDuplicateValues()} returns - * {@code true}. + * Returns the set of values in the mappings used to test the map. This method must return an array with the same length as {@link #getSampleKeys()}. The + * default implementation constructs a set of String values and includes a single null value if {@link #isAllowNullValue()} returns {@code true}, and + * includes two values that are the same if {@link #isAllowDuplicateValues()} returns {@code true}. */ @SuppressWarnings("unchecked") public V[] getSampleValues() { - final Object[] result = { - "blahv", "foov", "barv", "bazv", "tmpv", "goshv", "gollyv", "geev", - "hellov", "goodbyev", "we'llv", "seev", "youv", "allv", "againv", - isAllowNullValue() ? null : "nonnullvalue", - "value", - isAllowDuplicateValues() ? "value" : "value2", - }; + final Object[] result = { "blahv", "foov", "barv", "bazv", "tmpv", "goshv", "gollyv", "geev", "hellov", "goodbyev", "we'llv", "seev", "youv", "allv", + "againv", isAllowNullValue() ? null : "nonnullvalue", "value", isAllowDuplicateValues() ? "value" : "value2", }; return (V[]) result; } /** - * Returns true if the maps produced by - * {@link #makeObject()} and {@link #makeFullMap()} - * supports duplicate values. + * Returns true if the maps produced by {@link #makeObject()} and {@link #makeFullMap()} supports duplicate values. *

- * Default implementation returns true. - * Override if your collection class does not support duplicate values. + * Default implementation returns true. Override if your collection class does not support duplicate values. */ public boolean isAllowDuplicateValues() { return true; } /** - * Returns true if the maps produced by - * {@link #makeObject()} and {@link #makeFullMap()} - * supports null keys. + * Returns true if the maps produced by {@link #makeObject()} and {@link #makeFullMap()} supports null keys. *

- * Default implementation returns true. - * Override if your collection class does not support null keys. + * Default implementation returns true. Override if your collection class does not support null keys. */ public boolean isAllowNullKey() { return true; } /** - * Returns true if the maps produced by - * {@link #makeObject()} and {@link #makeFullMap()} - * supports null values. + * Returns true if the maps produced by {@link #makeObject()} and {@link #makeFullMap()} supports null values. *

- * Default implementation returns true. - * Override if your collection class does not support null values. + * Default implementation returns true. Override if your collection class does not support null values. */ public boolean isAllowNullValue() { return true; } /** - * Returns true if the maps produced by - * {@link #makeObject()} and {@link #makeFullMap()} - * provide fail-fast behavior on their various iterators. + * Returns true if the maps produced by {@link #makeObject()} and {@link #makeFullMap()} provide fail-fast behavior on their various iterators. *

- * Default implementation returns true. - * Override if your collection class does not support fast failure. + * Default implementation returns true. Override if your collection class does not support fast failure. */ public boolean isFailFastExpected() { return true; } /** - * Returns true if the maps produced by - * {@link #makeObject()} and {@link #makeFullMap()} - * can cause structural modification on a get(). The example is LRUMap. + * Returns true if the maps produced by {@link #makeObject()} and {@link #makeFullMap()} can cause structural modification on a get(). The example is + * LRUMap. *

- * Default implementation returns false. - * Override if your map class structurally modifies on get. + * Default implementation returns false. Override if your map class structurally modifies on get. */ public boolean isGetStructuralModify() { return false; } /** - * Returns true if the maps produced by - * {@link #makeObject()} and {@link #makeFullMap()} - * support the {@code put} and {@code putAll} operations - * adding new mappings. + * Returns true if the maps produced by {@link #makeObject()} and {@link #makeFullMap()} support the {@code put} and {@code putAll} operations adding new + * mappings. *

- * Default implementation returns true. - * Override if your collection class does not support put adding. + * Default implementation returns true. Override if your collection class does not support put adding. */ public boolean isPutAddSupported() { return true; } - // tests begin here. Each test adds a little bit of tested functionality. - // Many methods assume previous methods passed. That is, they do not + // tests begin here. Each test adds a little bit of tested functionality. + // Many methods assume previous methods passed. That is, they do not // exhaustively recheck things that have already been checked in a previous // test methods. /** - * Returns true if the maps produced by - * {@link #makeObject()} and {@link #makeFullMap()} - * support the {@code put} and {@code putAll} operations - * changing existing mappings. + * Returns true if the maps produced by {@link #makeObject()} and {@link #makeFullMap()} support the {@code put} and {@code putAll} operations changing + * existing mappings. *

- * Default implementation returns true. - * Override if your collection class does not support put changing. + * Default implementation returns true. Override if your collection class does not support put changing. */ public boolean isPutChangeSupported() { return true; } /** - * Returns true if the maps produced by - * {@link #makeObject()} and {@link #makeFullMap()} - * support the {@code remove} and {@code clear} operations. + * Returns true if the maps produced by {@link #makeObject()} and {@link #makeFullMap()} support the {@code remove} and {@code clear} operations. *

- * Default implementation returns true. - * Override if your collection class does not support removal operations. + * Default implementation returns true. Override if your collection class does not support removal operations. */ public boolean isRemoveSupported() { return true; } /** - * Returns true if the maps produced by - * {@link #makeObject()} and {@link #makeFullMap()} - * support the {@code setValue} operation on entrySet entries. + * Returns true if the maps produced by {@link #makeObject()} and {@link #makeFullMap()} support the {@code setValue} operation on entrySet entries. *

- * Default implementation returns isPutChangeSupported(). - * Override if your collection class does not support setValue but does - * support put changing. + * Default implementation returns isPutChangeSupported(). Override if your collection class does not support setValue but does support put changing. */ public boolean isSetValueSupported() { return isPutChangeSupported(); } /** - * Returns whether the sub map views of SortedMap are serializable. - * If the class being tested is based around a TreeMap then you should - * override and return false as TreeMap has a bug in deserialization. + * Returns whether the sub map views of SortedMap are serializable. If the class being tested is based around a TreeMap then you should override and return + * false as TreeMap has a bug in deserialization. * * @return false */ @@ -880,11 +795,11 @@ public Map makeConfirmedMap() { } /** - * Utility methods to create an array of Map.Entry objects - * out of the given key and value arrays.

+ * Utility methods to create an array of Map.Entry objects out of the given key and value arrays. + *

* - * @param keys the array of keys - * @param values the array of values + * @param keys the array of keys + * @param values the array of values * @return an array of Map.Entry of those keys to those values */ @SuppressWarnings("unchecked") @@ -899,11 +814,8 @@ private Map.Entry[] makeEntryArray(final K[] keys, final V[] values) { } /** - * Return a new, populated map. The mappings in the map should match the - * keys and values returned from {@link #getSampleKeys()} and - * {@link #getSampleValues()}. The default implementation uses makeEmptyMap() - * and calls {@link #addSampleMappings} to add all the mappings to the - * map. + * Return a new, populated map. The mappings in the map should match the keys and values returned from {@link #getSampleKeys()} and + * {@link #getSampleValues()}. The default implementation uses makeEmptyMap() and calls {@link #addSampleMappings} to add all the mappings to the map. * * @return the map to be tested */ @@ -922,8 +834,7 @@ public Map makeFullMap() { public abstract Map makeObject(); /** - * Resets the {@link #map}, {@link #entrySet}, {@link #keySet}, - * {@link #values} and {@link #confirmed} fields to empty. + * Resets the {@link #map}, {@link #entrySet}, {@link #keySet}, {@link #values} and {@link #confirmed} fields to empty. */ public void resetEmpty() { this.map = makeObject(); @@ -932,8 +843,7 @@ public void resetEmpty() { } /** - * Resets the {@link #map}, {@link #entrySet}, {@link #keySet}, - * {@link #values} and {@link #confirmed} fields to full. + * Resets the {@link #map}, {@link #entrySet}, {@link #keySet}, {@link #values} and {@link #confirmed} fields to full. */ public void resetFull() { this.map = makeFullMap(); @@ -959,18 +869,15 @@ public void tearDown() throws Exception { } /** - * Compare the current serialized form of the Map - * against the canonical version in SCM. + * Compare the current serialized form of the Map against the canonical version in SCM. */ @Test public void testEmptyMapCompatibility() throws Exception { /* - * Create canonical objects with this code - Map map = makeEmptyMap(); - if (!(map instanceof Serializable)) return; - - writeExternalFormToDisk((Serializable) map, getCanonicalEmptyCollectionName(map)); - */ + * Create canonical objects with this code Map map = makeEmptyMap(); if (!(map instanceof Serializable)) return; + * + * writeExternalFormToDisk((Serializable) map, getCanonicalEmptyCollectionName(map)); + */ // test to make sure the canonical form has been preserved final Map map = makeObject(); @@ -982,8 +889,7 @@ public void testEmptyMapCompatibility() throws Exception { } /** - * Tests that the {@link Map#entrySet()} collection is backed by - * the underlying map for clear(). + * Tests that the {@link Map#entrySet()} collection is backed by the underlying map for clear(). */ @Test public void testEntrySetClearChangesMap() { @@ -1117,7 +1023,7 @@ public void testEntrySetRemoveAll() { resetFull(); final K[] sampleKeys = getSampleKeys(); final V[] sampleValues = getSampleValues(); - //verify map looks as expected: + // verify map looks as expected: for (int i = 0; i < sampleKeys.length; i++) { if (!getMap().containsKey(sampleKeys[i])) { return; @@ -1146,9 +1052,8 @@ public void testEntrySetRemoveAll() { } /** - * Tests that the {@link Map#entrySet} set is backed by - * the underlying map by removing from the entrySet set - * and testing if the entry was removed from the map. + * Tests that the {@link Map#entrySet} set is backed by the underlying map by removing from the entrySet set and testing if the entry was removed from the + * map. */ @Test public void testEntrySetRemoveChangesMap() { @@ -1175,7 +1080,7 @@ public void testEntrySetRetainAll() { resetFull(); final K[] sampleKeys = getSampleKeys(); final V[] sampleValues = getSampleValues(); - //verify map looks as expected: + // verify map looks as expected: for (int i = 0; i < sampleKeys.length; i++) { if (!getMap().containsKey(sampleKeys[i])) { return; @@ -1204,18 +1109,15 @@ public void testEntrySetRetainAll() { } /** - * Compare the current serialized form of the Map - * against the canonical version in SCM. + * Compare the current serialized form of the Map against the canonical version in SCM. */ @Test public void testFullMapCompatibility() throws Exception { /* - * Create canonical objects with this code - Map map = makeFullMap(); - if (!(map instanceof Serializable)) return; - - writeExternalFormToDisk((Serializable) map, getCanonicalFullCollectionName(map)); - */ + * Create canonical objects with this code Map map = makeFullMap(); if (!(map instanceof Serializable)) return; + * + * writeExternalFormToDisk((Serializable) map, getCanonicalFullCollectionName(map)); + */ // test to make sure the canonical form has been preserved final Map map = makeFullMap(); @@ -1227,8 +1129,7 @@ public void testFullMapCompatibility() throws Exception { } /** - * Tests that the {@link Map#keySet} collection is backed by - * the underlying map for clear(). + * Tests that the {@link Map#keySet} collection is backed by the underlying map for clear(). */ @Test public void testKeySetClearChangesMap() { @@ -1298,9 +1199,7 @@ public void testKeySetRemoveAll() { } /** - * Tests that the {@link Map#keySet} set is backed by - * the underlying map by removing from the keySet set - * and testing if the key was removed from the map. + * Tests that the {@link Map#keySet} set is backed by the underlying map by removing from the keySet set and testing if the key was removed from the map. */ @Test public void testKeySetRemoveChangesMap() { @@ -1344,8 +1243,7 @@ public void testKeySetRetainAll() { } /** - * Test to ensure that makeEmptyMap and makeFull returns a new non-null - * map with each invocation. + * Test to ensure that makeEmptyMap and makeFull returns a new non-null map with each invocation. */ @Test public void testMakeMap() { @@ -1355,8 +1253,7 @@ public void testMakeMap() { final Map em2 = makeObject(); assertNotNull(em, "failure in test: makeEmptyMap must return a non-null map."); - assertNotSame(em, em2, "failure in test: makeEmptyMap must return a new map " + - "with each invocation."); + assertNotSame(em, em2, "failure in test: makeEmptyMap must return a new map " + "with each invocation."); final Map fm = makeFullMap(); assertNotNull(fm, "failure in test: makeFullMap must return a non-null map."); @@ -1364,24 +1261,19 @@ public void testMakeMap() { final Map fm2 = makeFullMap(); assertNotNull(fm2, "failure in test: makeFullMap must return a non-null map."); - assertNotSame(fm, fm2, "failure in test: makeFullMap must return a new map " + - "with each invocation."); + assertNotSame(fm, fm2, "failure in test: makeFullMap must return a new map " + "with each invocation."); } /** - * Tests {@link Map#clear()}. If the map {@link #isRemoveSupported() - * can add and remove elements}, then {@link Map#size()} and - * {@link Map#isEmpty()} are used to ensure that map has no elements after - * a call to clear. If the map does not support adding and removing - * elements, this method checks to ensure clear throws an - * UnsupportedOperationException. + * Tests {@link Map#clear()}. If the map {@link #isRemoveSupported() can add and remove elements}, then {@link Map#size()} and {@link Map#isEmpty()} are + * used to ensure that map has no elements after a call to clear. If the map does not support adding and removing elements, this method checks to ensure + * clear throws an UnsupportedOperationException. */ @Test public void testMapClear() { if (!isRemoveSupported()) { resetFull(); - assertThrows(UnsupportedOperationException.class, () -> getMap().clear(), - "Expected UnsupportedOperationException on clear"); + assertThrows(UnsupportedOperationException.class, () -> getMap().clear(), "Expected UnsupportedOperationException on clear"); return; } @@ -1397,9 +1289,8 @@ public void testMapClear() { } /** - * Tests Map.containsKey(Object) by verifying it returns false for all - * sample keys on a map created using an empty map and returns true for - * all sample keys returned on a full map. + * Tests Map.containsKey(Object) by verifying it returns false for all sample keys on a map created using an empty map and returns true for all sample keys + * returned on a full map. */ @Test public void testMapContainsKey() { @@ -1413,16 +1304,13 @@ public void testMapContainsKey() { resetFull(); for (final Object key : keys) { - assertTrue(getMap().containsKey(key), "Map must contain key for a mapping in the map. " + - "Missing: " + key); + assertTrue(getMap().containsKey(key), "Map must contain key for a mapping in the map. " + "Missing: " + key); } verify(); } /** - * Tests Map.containsValue(Object) by verifying it returns false for all - * sample values on an empty map and returns true for all sample values on - * a full map. + * Tests Map.containsValue(Object) by verifying it returns false for all sample values on an empty map and returns true for all sample values on a full map. */ @Test public void testMapContainsValue() { @@ -1436,8 +1324,7 @@ public void testMapContainsValue() { resetFull(); for (final Object value : values) { - assertTrue(getMap().containsValue(value), - "Map must contain value for a mapping in the map."); + assertTrue(getMap().containsValue(value), "Map must contain value for a mapping in the map."); } verify(); } @@ -1486,8 +1373,7 @@ public void testMapGet() { resetFull(); for (int i = 0; i < keys.length; i++) { - assertEquals(values[i], getMap().get(keys[i]), - "Full map.get() should return value from mapping."); + assertEquals(values[i], getMap().get(keys[i]), "Full map.get() should return value from mapping."); } } @@ -1533,10 +1419,8 @@ public void testMapPut() { getConfirmed().put(keys[i], values[i]); verify(); assertNull(o, "First map.put should return null"); - assertTrue(getMap().containsKey(keys[i]), - "Map should contain key after put"); - assertTrue(getMap().containsValue(values[i]), - "Map should contain value after put"); + assertTrue(getMap().containsKey(keys[i]), "Map should contain key after put"); + assertTrue(getMap().containsValue(values[i]), "Map should contain value after put"); } if (isPutChangeSupported()) { for (int i = 0; i < keys.length; i++) { @@ -1544,10 +1428,8 @@ public void testMapPut() { getConfirmed().put(keys[i], newValues[i]); verify(); assertEquals(values[i], o, "Map.put should return previous value when changed"); - assertTrue(getMap().containsKey(keys[i]), - "Map should still contain key after put when changed"); - assertTrue(getMap().containsValue(newValues[i]), - "Map should contain new value after put when changed"); + assertTrue(getMap().containsKey(keys[i]), "Map should still contain key after put when changed"); + assertTrue(getMap().containsValue(newValues[i]), "Map should contain new value after put when changed"); // if duplicates are allowed, we're not guaranteed that the value // no longer exists, so don't try checking that. @@ -1577,15 +1459,13 @@ public void testMapPut() { resetFull(); int i = 0; for (final Iterator it = getMap().keySet().iterator(); it.hasNext() && i < newValues.length; i++) { - final K key = it.next(); + final K key = it.next(); final V o = getMap().put(key, newValues[i]); final V value = getConfirmed().put(key, newValues[i]); verify(); assertEquals(value, o, "Map.put should return previous value when changed"); - assertTrue(getMap().containsKey(key), - "Map should still contain key after put when changed"); - assertTrue(getMap().containsValue(newValues[i]), - "Map should contain new value after put when changed"); + assertTrue(getMap().containsKey(key), "Map should still contain key after put when changed"); + assertTrue(getMap().containsValue(newValues[i]), "Map should contain new value after put when changed"); // if duplicates are allowed, we're not guaranteed that the value // no longer exists, so don't try checking that. @@ -1594,8 +1474,7 @@ public void testMapPut() { } } } else { - assertThrows(UnsupportedOperationException.class, () -> getMap().put(keys[0], values[0]), - "Expected UnsupportedOperationException on put (add)"); + assertThrows(UnsupportedOperationException.class, () -> getMap().put(keys[0], values[0]), "Expected UnsupportedOperationException on put (add)"); } } @@ -1608,8 +1487,7 @@ public void testMapPutAll() { if (!isPutChangeSupported()) { final Map temp = makeFullMap(); resetEmpty(); - assertThrows(UnsupportedOperationException.class, () -> getMap().putAll(temp), - "Expected UnsupportedOperationException on putAll"); + assertThrows(UnsupportedOperationException.class, () -> getMap().putAll(temp), "Expected UnsupportedOperationException on putAll"); } return; } @@ -1674,7 +1552,8 @@ public void testMapPutNullKey() { try { getMap().put(null, values[0]); fail("put(null, value) should throw NPE/IAE"); - } catch (final NullPointerException | IllegalArgumentException ex) {} + } catch (final NullPointerException | IllegalArgumentException ex) { + } } } } @@ -1694,7 +1573,8 @@ public void testMapPutNullValue() { try { getMap().put(keys[0], null); fail("put(key, null) should throw NPE/IAE"); - } catch (final NullPointerException | IllegalArgumentException ex) {} + } catch (final NullPointerException | IllegalArgumentException ex) { + } } } } @@ -1728,8 +1608,7 @@ public void testMapRemove() { getConfirmed().remove(keys[i]); verify(); - assertEquals(values[i], o, - "map.remove with valid key should return value"); + assertEquals(values[i], o, "map.remove with valid key should return value"); } final Object[] other = getOtherKeys(); @@ -1739,8 +1618,7 @@ public void testMapRemove() { for (final Object element : other) { final Object o = getMap().remove(element); assertNull(o, "map.remove for nonexistent key should return null"); - assertEquals(size, getMap().size(), - "map.remove for nonexistent key should not " + "shrink map"); + assertEquals(size, getMap().size(), "map.remove for nonexistent key should not " + "shrink map"); } verify(); } @@ -1751,24 +1629,18 @@ public void testMapRemove() { @Test public void testMapSize() { resetEmpty(); - assertEquals(0, getMap().size(), - "Map.size() should be 0 with an empty map"); + assertEquals(0, getMap().size(), "Map.size() should be 0 with an empty map"); verify(); resetFull(); - assertEquals(getSampleKeys().length, getMap().size(), - "Map.size() should equal the number of entries " + "in the map"); + assertEquals(getSampleKeys().length, getMap().size(), "Map.size() should equal the number of entries " + "in the map"); verify(); } /** - * Tests Map.toString(). Since the format of the string returned by the - * toString() method is not defined in the Map interface, there is no - * common way to test the results of the toString() method. Therefore, - * it is encouraged that Map implementations override this test with one - * that checks the format matches any format defined in its API. This - * default implementation just verifies that the toString() method does - * not return null. + * Tests Map.toString(). Since the format of the string returned by the toString() method is not defined in the Map interface, there is no common way to + * test the results of the toString() method. Therefore, it is encouraged that Map implementations override this test with one that checks the format + * matches any format defined in its API. This default implementation just verifies that the toString() method does not return null. */ @Test public void testMapToString() { @@ -1782,14 +1654,10 @@ public void testMapToString() { } /** - * Test to ensure the test setup is working properly. This method checks - * to ensure that the getSampleKeys and getSampleValues methods are - * returning results that look appropriate. That is, they both return a - * non-null array of equal length. The keys array must not have any - * duplicate values, and may only contain a (single) null key if - * isNullKeySupported() returns true. The values array must only have a null - * value if useNullValue() is true and may only have duplicate values if - * isAllowDuplicateValues() returns true. + * Test to ensure the test setup is working properly. This method checks to ensure that the getSampleKeys and getSampleValues methods are returning results + * that look appropriate. That is, they both return a non-null array of equal length. The keys array must not have any duplicate values, and may only + * contain a (single) null key if isNullKeySupported() returns true. The values array must only have a null value if useNullValue() is true and may only + * have duplicate values if isAllowDuplicateValues() returns true. */ @Test public void testSampleMappings() { @@ -1797,42 +1665,33 @@ public void testSampleMappings() { final Object[] values = getSampleValues(); final Object[] newValues = getNewSampleValues(); - assertNotNull(keys, "failure in test: Must have keys returned from " + - "getSampleKeys."); + assertNotNull(keys, "failure in test: Must have keys returned from " + "getSampleKeys."); - assertNotNull(values, "failure in test: Must have values returned from " + - "getSampleValues."); + assertNotNull(values, "failure in test: Must have values returned from " + "getSampleValues."); // verify keys and values have equivalent lengths (in case getSampleX are // overridden) - assertEquals(keys.length, values.length, "failure in test: not the same number of sample " + - "keys and values."); + assertEquals(keys.length, values.length, "failure in test: not the same number of sample " + "keys and values."); - assertEquals(values.length, newValues.length, - "failure in test: not the same number of values and new values."); + assertEquals(values.length, newValues.length, "failure in test: not the same number of values and new values."); // verify there aren't duplicate keys, and check values for (int i = 0; i < keys.length - 1; i++) { for (int j = i + 1; j < keys.length; j++) { - assertTrue(keys[i] != null || keys[j] != null, - "failure in test: duplicate null keys."); + assertTrue(keys[i] != null || keys[j] != null, "failure in test: duplicate null keys."); assertTrue(keys[i] == null || keys[j] == null || !keys[i].equals(keys[j]) && !keys[j].equals(keys[i]), "failure in test: duplicate non-null key."); } - assertTrue(keys[i] != null || isAllowNullKey(), - "failure in test: found null key, but isNullKeySupported " + "is false."); - assertTrue(values[i] != null || isAllowNullValue(), - "failure in test: found null value, but isNullValueSupported " + "is false."); - assertTrue(newValues[i] != null || isAllowNullValue(), - "failure in test: found null new value, but isNullValueSupported " + "is false."); + assertTrue(keys[i] != null || isAllowNullKey(), "failure in test: found null key, but isNullKeySupported " + "is false."); + assertTrue(values[i] != null || isAllowNullValue(), "failure in test: found null value, but isNullValueSupported " + "is false."); + assertTrue(newValues[i] != null || isAllowNullValue(), "failure in test: found null new value, but isNullValueSupported " + "is false."); assertTrue(values[i] != newValues[i] && (values[i] == null || !values[i].equals(newValues[i])), "failure in test: values should not be the same as new value"); } } /** - * Tests that the {@link Map#bitMaps} collection is backed by - * the underlying map for clear(). + * Tests that the {@link Map#bitMaps} collection is backed by the underlying map for clear(). */ @Test public void testValuesClearChangesMap() { @@ -1919,18 +1778,14 @@ public void testValuesRemoveAll() { } /** - * Tests that the {@link Map#bitMaps} collection is backed by - * the underlying map by removing from the values collection - * and testing if the value was removed from the map. + * Tests that the {@link Map#bitMaps} collection is backed by the underlying map by removing from the values collection and testing if the value was removed + * from the map. *

- * We should really test the "vice versa" case--that values removed - * from the map are removed from the values collection--also, - * but that's a more difficult test to construct (lacking a - * "removeValue" method.) + * We should really test the "vice versa" case--that values removed from the map are removed from the values collection--also, but that's a more difficult + * test to construct (lacking a "removeValue" method.) *

*

- * See bug - * COLLECTIONS-92. + * See bug COLLECTIONS-92. *

*/ @Test @@ -1940,7 +1795,7 @@ public void testValuesRemoveChangesMap() { final Collection values = getMap().values(); for (final V sampleValue : sampleValues) { if (map.containsValue(sampleValue)) { - int j = 0; // loop counter prevents infinite loops when remove is broken + int j = 0; // loop counter prevents infinite loops when remove is broken while (values.contains(sampleValue) && j < 10000) { try { values.remove(sampleValue); @@ -1984,14 +1839,9 @@ public void testValuesRetainAll() { } /** - * Verifies that {@link #map} is still equal to {@link #confirmed}. - * This method checks that the map is equal to the HashMap, - * and that the map's collection views are still equal to - * the HashMap's collection views. An equals test - * is done on the maps and their collection views; their size and - * isEmpty results are compared; their hashCodes are - * compared; and containsAll tests are run on the - * collection views. + * Verifies that {@link #map} is still equal to {@link #confirmed}. This method checks that the map is equal to the HashMap, and that the map's + * collection views are still equal to the HashMap's collection views. An equals test is done on the maps and their collection views; their + * size and isEmpty results are compared; their hashCodes are compared; and containsAll tests are run on the collection views. */ public void verify() { verifyMap(); @@ -2003,39 +1853,25 @@ public void verify() { public void verifyEntrySet() { final int size = getConfirmed().size(); final boolean empty = getConfirmed().isEmpty(); - assertEquals(size, entrySet.size(), - "entrySet should be same size as HashMap's" + - "\nTest: " + entrySet + "\nReal: " + getConfirmed().entrySet()); - assertEquals(empty, entrySet.isEmpty(), - "entrySet should be empty if HashMap is" + - "\nTest: " + entrySet + "\nReal: " + getConfirmed().entrySet()); + assertEquals(size, entrySet.size(), "entrySet should be same size as HashMap's" + "\nTest: " + entrySet + "\nReal: " + getConfirmed().entrySet()); + assertEquals(empty, entrySet.isEmpty(), "entrySet should be empty if HashMap is" + "\nTest: " + entrySet + "\nReal: " + getConfirmed().entrySet()); assertTrue(entrySet.containsAll(getConfirmed().entrySet()), - "entrySet should contain all HashMap's elements" + - "\nTest: " + entrySet + "\nReal: " + getConfirmed().entrySet()); + "entrySet should contain all HashMap's elements" + "\nTest: " + entrySet + "\nReal: " + getConfirmed().entrySet()); assertEquals(getConfirmed().entrySet().hashCode(), entrySet.hashCode(), - "entrySet hashCodes should be the same" + - "\nTest: " + entrySet + "\nReal: " + getConfirmed().entrySet()); - assertEquals(getConfirmed().entrySet(), entrySet, - "Map's entry set should still equal HashMap's"); + "entrySet hashCodes should be the same" + "\nTest: " + entrySet + "\nReal: " + getConfirmed().entrySet()); + assertEquals(getConfirmed().entrySet(), entrySet, "Map's entry set should still equal HashMap's"); } public void verifyKeySet() { final int size = getConfirmed().size(); final boolean empty = getConfirmed().isEmpty(); - assertEquals(size, keySet.size(), - "keySet should be same size as HashMap's" + - "\nTest: " + keySet + "\nReal: " + getConfirmed().keySet()); - assertEquals(empty, keySet.isEmpty(), - "keySet should be empty if HashMap is" + - "\nTest: " + keySet + "\nReal: " + getConfirmed().keySet()); + assertEquals(size, keySet.size(), "keySet should be same size as HashMap's" + "\nTest: " + keySet + "\nReal: " + getConfirmed().keySet()); + assertEquals(empty, keySet.isEmpty(), "keySet should be empty if HashMap is" + "\nTest: " + keySet + "\nReal: " + getConfirmed().keySet()); assertTrue(keySet.containsAll(getConfirmed().keySet()), - "keySet should contain all HashMap's elements" + - "\nTest: " + keySet + "\nReal: " + getConfirmed().keySet()); + "keySet should contain all HashMap's elements" + "\nTest: " + keySet + "\nReal: " + getConfirmed().keySet()); assertEquals(getConfirmed().keySet().hashCode(), keySet.hashCode(), - "keySet hashCodes should be the same" + - "\nTest: " + keySet + "\nReal: " + getConfirmed().keySet()); - assertEquals(getConfirmed().keySet(), keySet, - "Map's key set should still equal HashMap's"); + "keySet hashCodes should be the same" + "\nTest: " + keySet + "\nReal: " + getConfirmed().keySet()); + assertEquals(getConfirmed().keySet(), keySet, "Map's key set should still equal HashMap's"); } public void verifyMap() { @@ -2062,18 +1898,10 @@ public void verifyValues() { final int size = getConfirmed().size(); final boolean empty = getConfirmed().isEmpty(); - assertEquals(size, values.size(), - "values should be same size as HashMap's" + - "\nTest: " + test + "\nReal: " + known); - assertEquals(empty, values.isEmpty(), - "values should be empty if HashMap is" + - "\nTest: " + test + "\nReal: " + known); - assertTrue(test.containsAll(known), - "values should contain all HashMap's elements" + - "\nTest: " + test + "\nReal: " + known); - assertTrue(known.containsAll(test), - "values should contain all HashMap's elements" + - "\nTest: " + test + "\nReal: " + known); + assertEquals(size, values.size(), "values should be same size as HashMap's" + "\nTest: " + test + "\nReal: " + known); + assertEquals(empty, values.isEmpty(), "values should be empty if HashMap is" + "\nTest: " + test + "\nReal: " + known); + assertTrue(test.containsAll(known), "values should contain all HashMap's elements" + "\nTest: " + test + "\nReal: " + known); + assertTrue(known.containsAll(test), "values should contain all HashMap's elements" + "\nTest: " + test + "\nReal: " + known); // originally coded to use a HashBag, but now separate jar so... for (final V v : known) { final boolean removed = test.remove(v); 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 0fa05a2ab5..62bc5346ce 100644 --- a/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java @@ -95,7 +95,7 @@ public void verify() { /** * JUnit constructor. * - * @param testName the test name + * @param testName the test name */ public AbstractOrderedMapTest(final String testName) { super(testName); @@ -114,8 +114,7 @@ public OrderedMap getMap() { } /** - * The only confirmed collection we have that is ordered is the sorted one. - * Thus, sort the keys. + * The only confirmed collection we have that is ordered is the sorted one. Thus, sort the keys. */ @Override @SuppressWarnings("unchecked") @@ -186,7 +185,8 @@ public void testNextKey() { if (!isAllowNullKey()) { try { assertNull(ordered.nextKey(null)); // this is allowed too - } catch (final NullPointerException ex) {} + } catch (final NullPointerException ex) { + } } else { assertNull(ordered.nextKey(null)); } @@ -218,7 +218,8 @@ public void testPreviousKey() { if (!isAllowNullKey()) { try { assertNull(ordered.previousKey(null)); // this is allowed too - } catch (final NullPointerException ex) {} + } catch (final NullPointerException ex) { + } } else { assertNull(ordered.previousKey(null)); } 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 64f6c52f41..bce52b9b80 100644 --- a/src/test/java/org/apache/commons/collections4/map/LinkedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LinkedMapTest.java @@ -57,22 +57,27 @@ public boolean isAddSupported() { public boolean isNullSupported() { return LinkedMapTest.this.isAllowNullKey(); } + @Override public boolean isRemoveSupported() { return false; } + @Override public boolean isSetSupported() { return false; } + @Override public boolean isTestSerialization() { return false; } + @Override public List makeFullCollection() { return LinkedMapTest.this.makeFullMap().asList(); } + @Override public List makeObject() { return LinkedMapTest.this.makeObject().asList(); @@ -129,19 +134,23 @@ public void testGetByIndex() { LinkedMap lm = getMap(); try { lm.get(0); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lm.get(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); lm = getMap(); try { lm.get(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lm.get(lm.size()); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } int i = 0; for (final MapIterator it = lm.mapIterator(); it.hasNext(); i++) { @@ -155,19 +164,23 @@ public void testGetValueByIndex() { LinkedMap lm = getMap(); try { lm.getValue(0); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lm.getValue(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); lm = getMap(); try { lm.getValue(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lm.getValue(lm.size()); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } int i = 0; for (final MapIterator it = lm.mapIterator(); it.hasNext(); i++) { @@ -263,19 +276,23 @@ public void testRemoveByIndex() { LinkedMap lm = getMap(); try { lm.remove(0); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lm.remove(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); lm = getMap(); try { lm.remove(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lm.remove(lm.size()); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } final List list = new ArrayList<>(); for (final MapIterator it = lm.mapIterator(); it.hasNext();) { 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 45625f74c2..1da8296472 100644 --- a/src/test/java/org/apache/commons/collections4/map/ListOrderedMap2Test.java +++ b/src/test/java/org/apache/commons/collections4/map/ListOrderedMap2Test.java @@ -29,8 +29,7 @@ import org.junit.jupiter.api.Test; /** - * Extension of {@link AbstractOrderedMapTest} for exercising the {@link ListOrderedMap} - * implementation. + * Extension of {@link AbstractOrderedMapTest} for exercising the {@link ListOrderedMap} implementation. */ public class ListOrderedMap2Test extends AbstractOrderedMapTest { @@ -54,22 +53,27 @@ public boolean isAddSupported() { public boolean isNullSupported() { return ListOrderedMap2Test.this.isAllowNullKey(); } + @Override public boolean isRemoveSupported() { return false; } + @Override public boolean isSetSupported() { return false; } + @Override public boolean isTestSerialization() { return false; } + @Override public List makeFullCollection() { return ListOrderedMap2Test.this.makeFullMap().asList(); } + @Override public List makeObject() { return ListOrderedMap2Test.this.makeObject().asList(); @@ -116,19 +120,23 @@ public void testGetByIndex() { ListOrderedMap lom = getMap(); try { lom.get(0); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.get(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); lom = getMap(); try { lom.get(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.get(lom.size()); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } int i = 0; for (final MapIterator it = lom.mapIterator(); it.hasNext(); i++) { @@ -142,19 +150,23 @@ public void testGetValueByIndex() { ListOrderedMap lom = getMap(); try { lom.getValue(0); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.getValue(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); lom = getMap(); try { lom.getValue(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.getValue(lom.size()); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } int i = 0; for (final MapIterator it = lom.mapIterator(); it.hasNext(); i++) { @@ -197,19 +209,23 @@ public void testRemoveByIndex() { ListOrderedMap lom = getMap(); try { lom.remove(0); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.remove(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); lom = getMap(); try { lom.remove(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.remove(lom.size()); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } final List list = new ArrayList<>(); for (final MapIterator it = lom.mapIterator(); it.hasNext();) { 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 353a3c48a7..2b2e4e6089 100644 --- a/src/test/java/org/apache/commons/collections4/map/ListOrderedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/ListOrderedMapTest.java @@ -35,8 +35,7 @@ import org.junit.jupiter.api.Test; /** - * Extension of {@link AbstractOrderedMapTest} for exercising the {@link ListOrderedMap} - * implementation. + * Extension of {@link AbstractOrderedMapTest} for exercising the {@link ListOrderedMap} implementation. */ public class ListOrderedMapTest extends AbstractOrderedMapTest { @@ -175,7 +174,7 @@ public ListOrderedMap makeObject() { } @Test - public void testCOLLECTIONS_474_nonNullValues () { + public void testCOLLECTIONS_474_nonNullValues() { final Object key1 = new Object(); final Object key2 = new Object(); final HashMap hmap = new HashMap<>(); @@ -190,7 +189,7 @@ public void testCOLLECTIONS_474_nonNullValues () { } @Test - public void testCOLLECTIONS_474_nullValues () { + public void testCOLLECTIONS_474_nullValues() { final Object key1 = new Object(); final Object key2 = new Object(); final HashMap hmap = new HashMap<>(); @@ -210,19 +209,23 @@ public void testGetByIndex() { ListOrderedMap lom = getMap(); try { lom.get(0); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.get(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); lom = getMap(); try { lom.get(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.get(lom.size()); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } int i = 0; for (final MapIterator it = lom.mapIterator(); it.hasNext(); i++) { @@ -236,19 +239,23 @@ public void testGetValueByIndex() { ListOrderedMap lom = getMap(); try { lom.getValue(0); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.getValue(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); lom = getMap(); try { lom.getValue(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.getValue(lom.size()); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } int i = 0; for (final MapIterator it = lom.mapIterator(); it.hasNext(); i++) { @@ -285,8 +292,7 @@ public void testPut_intObjectObject() { () -> assertThrows(IndexOutOfBoundsException.class, () -> finalLom.put(1, (K) "testInsert1", (V) "testInsert1v"), "should not be able to insert at pos 1 in empty Map"), () -> assertThrows(IndexOutOfBoundsException.class, () -> finalLom.put(-1, (K) "testInsert-1", (V) "testInsert-1v"), - "should not be able to insert at pos -1 in empty Map") - ); + "should not be able to insert at pos -1 in empty Map")); // put where key doesn't exist lom.put(0, (K) "testInsert1", (V) "testInsert1v"); @@ -450,19 +456,23 @@ public void testRemoveByIndex() { ListOrderedMap lom = getMap(); try { lom.remove(0); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.remove(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); lom = getMap(); try { lom.remove(-1); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.remove(lom.size()); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } final List list = new ArrayList<>(); for (final MapIterator it = lom.mapIterator(); it.hasNext();) { @@ -484,19 +494,23 @@ public void testSetValueByIndex() { ListOrderedMap lom = getMap(); try { lom.setValue(0, (V) StringUtils.EMPTY); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.setValue(-1, (V) StringUtils.EMPTY); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } resetFull(); lom = getMap(); try { lom.setValue(-1, (V) StringUtils.EMPTY); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } try { lom.setValue(lom.size(), (V) StringUtils.EMPTY); - } catch (final IndexOutOfBoundsException ex) {} + } catch (final IndexOutOfBoundsException ex) { + } for (int i = 0; i < lom.size(); i++) { final V value = lom.getValue(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 7ffe49be96..f4d368287f 100644 --- a/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java @@ -1337,7 +1337,7 @@ public void testSizeWithPutRemove() { } @Test - public void testToString(){ + public void testToString() { assumeTrue(isAddSupported()); final MultiValuedMap map = makeObject(); map.put((K) "A", (V) "X"); @@ -1346,18 +1346,11 @@ public void testToString(){ map.put((K) "B", (V) "U"); map.put((K) "B", (V) "V"); map.put((K) "B", (V) "W"); - assertTrue( - "{A=[X, Y, Z], B=[U, V, W]}".equals(map.toString()) || - "{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString()) - ); + assertTrue("{A=[X, Y, Z], B=[U, V, W]}".equals(map.toString()) || "{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString())); final MultiValuedMap originalNull = null; - assertThrows(NullPointerException.class, () -> map.putAll(originalNull), - "expecting NullPointerException"); - assertTrue( - "{A=[X, Y, Z], B=[U, V, W]}".equals(map.toString()) || - "{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString()) - ); + assertThrows(NullPointerException.class, () -> map.putAll(originalNull), "expecting NullPointerException"); + assertTrue("{A=[X, Y, Z], B=[U, V, W]}".equals(map.toString()) || "{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString())); map.remove("A"); map.remove("B"); diff --git a/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java index 8901ce2fdf..89830a9d08 100644 --- a/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java +++ b/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java @@ -176,7 +176,7 @@ public void testListValuedMapRemoveViaListIterator() { } @Test - public void testTrimToSize(){ + public void testTrimToSize() { final ArrayListValuedHashMap listMap = new ArrayListValuedHashMap<>(4); assertEquals("{}", listMap.toString()); @@ -192,7 +192,7 @@ public void testTrimToSize(){ } @Test - public void testValuesListIteratorMethods(){ + public void testValuesListIteratorMethods() { final ListValuedMap listMap = makeObject(); final List listA = listMap.get((K) "A"); final List list = Arrays.asList((V) "W", (V) "X", (V) "F", (V) "Q", (V) "Q", (V) "F"); diff --git a/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java index 7c31016d60..b36f4ed01e 100644 --- a/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java +++ b/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java @@ -61,7 +61,7 @@ public SetValuedMap makeObject() { } @Test - public void testHashSetValuedHashMap_2(){ + public void testHashSetValuedHashMap_2() { final Map map = new HashMap<>(); final SetValuedMap map1; final SetValuedMap map2; diff --git a/src/test/java/org/apache/commons/collections4/sequence/SequencesComparatorTest.java b/src/test/java/org/apache/commons/collections4/sequence/SequencesComparatorTest.java index 2a599109c6..ad7545265b 100644 --- a/src/test/java/org/apache/commons/collections4/sequence/SequencesComparatorTest.java +++ b/src/test/java/org/apache/commons/collections4/sequence/SequencesComparatorTest.java @@ -178,20 +178,18 @@ public void testMinimal() { final Random random = new Random(4564634237452342L); - for (int nbCom = 0; nbCom <= 40; nbCom+=5) { + for (int nbCom = 0; nbCom <= 40; nbCom += 5) { sentenceAfter.clear(); sentenceAfter.addAll(sentenceBefore); - for (int i = 0; i comparator = - new SequencesComparator<>(sentenceBefore, sentenceAfter); + final SequencesComparator comparator = new SequencesComparator<>(sentenceBefore, sentenceAfter); assertTrue(comparator.getScript().getModifications() <= nbCom); } } @@ -206,7 +204,7 @@ public void testShadok() { "MEU" }; List> shadokSentences = new ArrayList<>(); - for (int lg=0; lg> newTab = new ArrayList<>(); newTab.add(new ArrayList<>()); for (final String element : shadokAlph) { 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 bb7b185e98..673396ee2d 100644 --- a/src/test/java/org/apache/commons/collections4/splitmap/TransformedSplitMapTest.java +++ b/src/test/java/org/apache/commons/collections4/splitmap/TransformedSplitMapTest.java @@ -57,8 +57,7 @@ public void testEmptyMap() throws IOException, ClassNotFoundException { NOPTransformer.nopTransformer(), NOPTransformer.nopTransformer() ); - final ObjectInputStream in = - new ObjectInputStream( new FileInputStream( TEST_DATA_PATH+"/TransformedSplitMap.emptyCollection.version4.obj" ) ); + final ObjectInputStream in = new ObjectInputStream(new FileInputStream(TEST_DATA_PATH + "/TransformedSplitMap.emptyCollection.version4.obj")); final Object readObject = in.readObject(); in.close(); @@ -78,14 +77,13 @@ public void testFullMap() throws IOException, ClassNotFoundException { map.put( "e", "f" ); map.put( "g", "h" ); - final ObjectInputStream in = - new ObjectInputStream( new FileInputStream( TEST_DATA_PATH+"TransformedSplitMap.fullCollection.version4.obj" ) ); + final ObjectInputStream in = new ObjectInputStream(new FileInputStream(TEST_DATA_PATH + "TransformedSplitMap.fullCollection.version4.obj")); final Object readObject = in.readObject(); in.close(); final TransformedSplitMap readMap = (TransformedSplitMap) readObject; assertFalse(readMap.isEmpty(), "Map should not be empty"); - assertEquals( map.entrySet(), readMap.entrySet() ); + assertEquals(map.entrySet(), readMap.entrySet()); } @Test