Skip to content
Permalink
Browse files
COLLECTIONS-777 JUnit v5 (#281)
JUnit v5 assertThrows for PatriciaTrieTest.java

JUnit v5 assertThrows UnmodifiableBagTest

JUnit v5 assertThrows UnmodifiableSortedBagTest

JUnit v5 assertThrows UnmodifiableBidiMapTest

JUnit v5 assertThrows UnmodifiableOrderedBidiMapTest

JUnit v5 assertThrows UnmodifiableSortedBidiMapTest

JUnit v5 assertThrows TrieUtilsTest

JUnit v5 assertThrows AbstractArrayListTest

JUnit v5 assertThrows UnmodifiableTrieTest

JUnit v5 assertThrows UnmodifiableSetTest

JUnit v5 assertThrows CompositeMapTest

JUnit v5 assertThrows SetUniqueListTest

JUnit v5 assertThrows UnmodifiableMapEntryTest

JUnit v5 assertThrows DefaultMapEntryTest

JUnit v5 assertThrows AbstractMapEntryTest

JUnit v5 assertThrows UnmodifiableOrderedMapIteratorTest

JUnit v5 assertThrows UnmodifiableMapIteratorTest

JUnit v5 assertThrows UnmodifiableIteratorTest

JUnit v5 assertThrows PermutationIteratorTest

JUnit v5 assertThrows ObjectArrayIteratorTest

JUnit v5 assertThrows NodeListIteratorTest

JUnit v5 assertThrows IteratorEnumerationTest

JUnit v5 assertThrows FilterIteratorTest

JUnit v5 assertThrows ArrayIteratorTest

JUnit v5 assertThrows AbstractOrderedMapIteratorTest

JUnit v5 assertThrows UnmodifiableCollectionTest

JUnit v5 assertThrows UnmodifiableBoundedCollectionTest

JUnit v5 assertThrows IndexedCollectionTest
  • Loading branch information
nhojpatrick committed Mar 4, 2022
1 parent 4e0fb4f commit f4c041ba949403ad6855a3811ad00fbf240255ea
Showing 28 changed files with 120 additions and 202 deletions.
@@ -16,13 +16,14 @@
*/
package org.apache.commons.collections4;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.ArrayList;

import org.apache.commons.collections4.list.AbstractListTest;

/**
* Abstract test class for ArrayList.
*
*/
public abstract class AbstractArrayListTest<E> extends AbstractListTest<E> {

@@ -41,12 +42,7 @@ public void testNewArrayList() {
assertTrue("New list is empty", list.isEmpty());
assertEquals("New list has size zero", 0, list.size());

try {
list.get(1);
fail("get(int i) should have thrown IndexOutOfBoundsException");
} catch (final IndexOutOfBoundsException e) {
// Expected result
}
assertThrows(IndexOutOfBoundsException.class, () -> list.get(1));
}

@SuppressWarnings("unchecked")
@@ -17,16 +17,15 @@
package org.apache.commons.collections4;

import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import org.apache.commons.collections4.trie.PatriciaTrie;
import org.apache.commons.collections4.trie.UnmodifiableTrie;
import org.junit.jupiter.api.Test;

/**
* Tests for TrieUtils factory methods.
*
*/
public class TrieUtilsTest {

@@ -36,12 +35,8 @@ public class TrieUtilsTest {
public void testUnmodifiableTrie() {
final Trie<String, Object> trie = TrieUtils.unmodifiableTrie(new PatriciaTrie<>());
assertTrue(trie instanceof UnmodifiableTrie, "Returned object should be an UnmodifiableTrie.");
try {
TrieUtils.unmodifiableTrie(null);
fail("Expecting NullPointerException for null trie.");
} catch (final NullPointerException ex) {
// expected
}

assertThrows(NullPointerException.class, () -> TrieUtils.unmodifiableTrie(null));

assertSame(trie, TrieUtils.unmodifiableTrie(trie), "UnmodifiableTrie shall not be decorated");
}
@@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.bag;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Arrays;

import junit.framework.Test;
@@ -73,7 +75,6 @@ public boolean isNullSupported() {
return false;
}


public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullCollection() instanceof Unmodifiable);
@@ -83,13 +84,9 @@ public void testDecorateFactory() {
final Bag<E> queue = makeFullCollection();
assertSame(queue, UnmodifiableBag.unmodifiableBag(queue));

try {
UnmodifiableBag.unmodifiableBag(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableBag.unmodifiableBag(null));
}


@Override
public String getCompatibilityVersion() {
return "4";
@@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.bag;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Arrays;

import junit.framework.Test;
@@ -73,7 +75,6 @@ public boolean isNullSupported() {
return false;
}


public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullCollection() instanceof Unmodifiable);
@@ -83,13 +84,9 @@ public void testDecorateFactory() {
final SortedBag<E> queue = makeFullCollection();
assertSame(queue, UnmodifiableSortedBag.unmodifiableSortedBag(queue));

try {
UnmodifiableSortedBag.unmodifiableSortedBag(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableSortedBag.unmodifiableSortedBag(null));
}


@Override
public String getCompatibilityVersion() {
return "4";
@@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.bidimap;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.HashMap;
import java.util.Map;

@@ -27,7 +29,6 @@

/**
* JUnit tests.
*
*/
public class UnmodifiableBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {

@@ -79,7 +80,6 @@ public boolean isRemoveSupported() {
return false;
}


public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullMap() instanceof Unmodifiable);
@@ -89,10 +89,7 @@ public void testDecorateFactory() {
final BidiMap<K, V> map = makeFullMap();
assertSame(map, UnmodifiableBidiMap.unmodifiableBidiMap(map));

try {
UnmodifiableBidiMap.unmodifiableBidiMap(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableBidiMap.unmodifiableBidiMap(null));
}

}
@@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.bidimap;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Map;
import java.util.TreeMap;

@@ -27,7 +29,6 @@

/**
* JUnit tests.
*
*/
public class UnmodifiableOrderedBidiMapTest<K extends Comparable<K>, V extends Comparable<V>> extends AbstractOrderedBidiMapTest<K, V> {

@@ -89,7 +90,6 @@ public boolean isRemoveSupported() {
return false;
}


public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullMap() instanceof Unmodifiable);
@@ -99,9 +99,7 @@ public void testDecorateFactory() {
final OrderedBidiMap<K, V> map = makeFullMap();
assertSame(map, UnmodifiableOrderedBidiMap.unmodifiableOrderedBidiMap(map));

try {
UnmodifiableOrderedBidiMap.unmodifiableOrderedBidiMap(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableOrderedBidiMap.unmodifiableOrderedBidiMap(null));
}

}
@@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.bidimap;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.SortedMap;
import java.util.TreeMap;

@@ -27,7 +29,6 @@

/**
* JUnit tests.
*
*/
public class UnmodifiableSortedBidiMapTest<K extends Comparable<K>, V extends Comparable<V>> extends AbstractSortedBidiMapTest<K, V> {

@@ -93,7 +94,6 @@ public boolean isRemoveSupported() {
return false;
}


public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullMap() instanceof Unmodifiable);
@@ -103,10 +103,7 @@ public void testDecorateFactory() {
final SortedBidiMap<K, V> map = makeFullMap();
assertSame(map, UnmodifiableSortedBidiMap.unmodifiableSortedBidiMap(map));

try {
UnmodifiableSortedBidiMap.unmodifiableSortedBidiMap(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableSortedBidiMap.unmodifiableSortedBidiMap(null));
}

}
@@ -17,6 +17,7 @@
package org.apache.commons.collections4.collection;

import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.Serializable;
import java.util.ArrayList;
@@ -124,12 +125,8 @@ public void testEnsureDuplicateObjectsCauseException() throws Exception {
final Collection<String> coll = makeUniqueTestCollection();

coll.add("1");
try {
coll.add("1");
fail();
} catch (final IllegalArgumentException e) {
// expected
}

assertThrows(IllegalArgumentException.class, () -> coll.add("1"));
}

public void testDecoratedCollectionIsIndexedOnCreation() throws Exception {
@@ -159,4 +156,5 @@ public void testReindexUpdatesIndexWhenDecoratedCollectionIsModifiedSeparately()
assertEquals("2", indexed.get(2));
assertEquals("3", indexed.get(3));
}

}
@@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.collection;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -27,7 +29,6 @@
/**
* Extension of {@link AbstractCollectionTest} for exercising the
* {@link UnmodifiableBoundedCollection} implementation.
*
*/
public class UnmodifiableBoundedCollectionTest<E> extends AbstractCollectionTest<E> {

@@ -88,10 +89,7 @@ public void testDecorateFactory() {
final BoundedCollection<E> coll = makeFullCollection();
assertSame(coll, UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll));

try {
UnmodifiableBoundedCollection.unmodifiableBoundedCollection(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableBoundedCollection.unmodifiableBoundedCollection(null));
}

}
@@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.collection;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -76,13 +78,9 @@ public void testDecorateFactory() {
final Collection<E> coll = makeFullCollection();
assertSame(coll, UnmodifiableCollection.unmodifiableCollection(coll));

try {
UnmodifiableCollection.unmodifiableCollection(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableCollection.unmodifiableCollection(null));
}


@Override
public String getCompatibilityVersion() {
return "4";
@@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.iterators;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -66,10 +68,8 @@ public void testEmptyMapIterator() {

final OrderedMapIterator<K, V> it = makeEmptyIterator();
assertFalse(it.hasPrevious());
try {
it.previous();
fail();
} catch (final NoSuchElementException ex) {}

assertThrows(NoSuchElementException.class, () -> it.previous());
}

/**
@@ -25,7 +25,6 @@
* Tests the ArrayIterator to ensure that the next() method will actually
* perform the iteration rather than the hasNext() method.
* The code of this test was supplied by Mauricio S. Moura.
*
*/
public class ArrayIteratorTest<E> extends AbstractIteratorTest<E> {

@@ -64,12 +63,7 @@ public void testIterator() {
}

public void testNullArray() {
try {
new ArrayIterator<>(null);
fail("Constructor should throw a NullPointerException when constructed with a null array");
} catch (final NullPointerException e) {
// expected
}
assertThrows(NullPointerException.class, () -> new ArrayIterator<>(null));
}

public void testReset() {

0 comments on commit f4c041b

Please sign in to comment.