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
This commit is contained in:
John Patrick 2022-03-04 13:36:21 +00:00 committed by GitHub
parent 4e0fb4f809
commit f4c041ba94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 120 additions and 202 deletions

View File

@ -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 abstract class AbstractArrayListTest<E> extends AbstractListTest<E> {
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")

View File

@ -17,8 +17,8 @@
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;
@ -26,7 +26,6 @@ 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");
}

View File

@ -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 class UnmodifiableBagTest<E> extends AbstractBagTest<E> {
return false;
}
public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullCollection() instanceof Unmodifiable);
@ -83,13 +84,9 @@ public class UnmodifiableBagTest<E> extends AbstractBagTest<E> {
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";

View File

@ -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 class UnmodifiableSortedBagTest<E> extends AbstractSortedBagTest<E> {
return false;
}
public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullCollection() instanceof Unmodifiable);
@ -83,13 +84,9 @@ public class UnmodifiableSortedBagTest<E> extends AbstractSortedBagTest<E> {
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";

View File

@ -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 @@ import org.apache.commons.collections4.Unmodifiable;
/**
* JUnit tests.
*
*/
public class UnmodifiableBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {
@ -79,7 +80,6 @@ public class UnmodifiableBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {
return false;
}
public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullMap() instanceof Unmodifiable);
@ -89,10 +89,7 @@ public class UnmodifiableBidiMapTest<K, V> extends AbstractBidiMapTest<K, V> {
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));
}
}

View File

@ -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 @@ import org.apache.commons.collections4.Unmodifiable;
/**
* JUnit tests.
*
*/
public class UnmodifiableOrderedBidiMapTest<K extends Comparable<K>, V extends Comparable<V>> extends AbstractOrderedBidiMapTest<K, V> {
@ -89,7 +90,6 @@ public class UnmodifiableOrderedBidiMapTest<K extends Comparable<K>, V extends C
return false;
}
public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullMap() instanceof Unmodifiable);
@ -99,9 +99,7 @@ public class UnmodifiableOrderedBidiMapTest<K extends Comparable<K>, V extends C
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));
}
}

View File

@ -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 @@ import org.apache.commons.collections4.Unmodifiable;
/**
* JUnit tests.
*
*/
public class UnmodifiableSortedBidiMapTest<K extends Comparable<K>, V extends Comparable<V>> extends AbstractSortedBidiMapTest<K, V> {
@ -93,7 +94,6 @@ public class UnmodifiableSortedBidiMapTest<K extends Comparable<K>, V extends Co
return false;
}
public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullMap() instanceof Unmodifiable);
@ -103,10 +103,7 @@ public class UnmodifiableSortedBidiMapTest<K extends Comparable<K>, V extends Co
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));
}
}

View File

@ -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 class IndexedCollectionTest extends AbstractCollectionTest<String> {
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 class IndexedCollectionTest extends AbstractCollectionTest<String> {
assertEquals("2", indexed.get(2));
assertEquals("3", indexed.get(3));
}
}

View File

@ -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 @@ import org.apache.commons.collections4.list.FixedSizeList;
/**
* Extension of {@link AbstractCollectionTest} for exercising the
* {@link UnmodifiableBoundedCollection} implementation.
*
*/
public class UnmodifiableBoundedCollectionTest<E> extends AbstractCollectionTest<E> {
@ -88,10 +89,7 @@ public class UnmodifiableBoundedCollectionTest<E> extends AbstractCollectionTest
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));
}
}

View File

@ -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 class UnmodifiableCollectionTest<E> extends AbstractCollectionTest<E> {
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";

View File

@ -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 abstract class AbstractOrderedMapIteratorTest<K, V> extends AbstractMapIt
final OrderedMapIterator<K, V> it = makeEmptyIterator();
assertFalse(it.hasPrevious());
try {
it.previous();
fail();
} catch (final NoSuchElementException ex) {}
assertThrows(NoSuchElementException.class, () -> it.previous());
}
/**

View File

@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
* Tests the ArrayIterator to ensure that the next() method will actually
* perform the iteration rather than the hasNext() method.
* The code of this test was supplied by Mauricio S. Moura.
*
*/
public class ArrayIteratorTest<E> extends AbstractIteratorTest<E> {
@ -64,12 +63,7 @@ public class ArrayIteratorTest<E> extends AbstractIteratorTest<E> {
}
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() {

View File

@ -17,6 +17,7 @@
package org.apache.commons.collections4.iterators;
import static org.apache.commons.collections4.functors.TruePredicate.truePredicate;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ArrayList;
import java.util.Arrays;
@ -30,7 +31,6 @@ import org.apache.commons.collections4.functors.NotNullPredicate;
/**
* Test the filter iterator.
*
*/
public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
@ -147,12 +147,7 @@ public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
private void verifyNoMoreElements() {
assertFalse(iterator.hasNext());
try {
iterator.next();
fail("NoSuchElementException expected");
} catch (final NoSuchElementException e) {
// success
}
assertThrows(NoSuchElementException.class, () -> iterator.next());
}
private void verifyElementsInPredicate(final String[] elements) {
@ -210,5 +205,5 @@ public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
final Predicate<E> pred = x -> false;
return new FilterIterator<>(i, pred);
}
}
}

View File

@ -24,12 +24,11 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Tests the IteratorEnumeration.
*
*/
public class IteratorEnumerationTest {
@ -46,11 +45,7 @@ public class IteratorEnumerationTest {
assertEquals("c", enumeration.nextElement());
assertFalse(enumeration.hasMoreElements());
try {
enumeration.nextElement();
fail("NoSuchElementException expected");
} catch (final NoSuchElementException e) {
// expected
}
assertThrows(NoSuchElementException.class, () -> enumeration.nextElement());
}
}

View File

@ -17,6 +17,7 @@
package org.apache.commons.collections4.iterators;
import static org.easymock.EasyMock.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Iterator;
@ -110,13 +111,8 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
return false;
}
public void testNullConstructor(){
try{
new NodeListIterator((Node) null);
fail("NullPointerException expected!");
}catch(final NullPointerException e){
// expected.
}
public void testNullConstructor() {
assertThrows(NullPointerException.class, () -> new NodeListIterator((Node) null));
}
/**
@ -134,4 +130,5 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
createIteratorWithStandardConstr = false;
testFullIterator();
}
}

View File

@ -16,12 +16,13 @@
*/
package org.apache.commons.collections4.iterators;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* Tests the ObjectArrayIterator.
*
*/
public class ObjectArrayIteratorTest<E> extends AbstractIteratorTest<E> {
@ -83,13 +84,7 @@ public class ObjectArrayIteratorTest<E> extends AbstractIteratorTest<E> {
}
public void testNullArray() {
try {
makeArrayIterator(null);
fail("Constructor should throw a NullPointerException when constructed with a null array");
} catch (final NullPointerException e) {
// expected
}
assertThrows(NullPointerException.class, () -> makeArrayIterator(null));
}
@SuppressWarnings("unchecked")

View File

@ -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.Arrays;
import java.util.HashSet;
@ -162,12 +164,7 @@ public class PermutationIteratorTest extends AbstractIteratorTest<List<Character
resultsList.add(permutation);
}
//asking for another permutation should throw an exception
try {
it.next();
fail();
} catch (final NoSuchElementException e) {
// expected
}
assertThrows(NoSuchElementException.class, () -> it.next());
}
public void testPermutatorHasMore() {
@ -189,4 +186,5 @@ public class PermutationIteratorTest extends AbstractIteratorTest<List<Character
assertFalse(it.hasNext());
}
}

View File

@ -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.Arrays;
import java.util.Collections;
@ -26,7 +28,6 @@ import org.apache.commons.collections4.Unmodifiable;
/**
* Tests the UnmodifiableIterator.
*
*/
public class UnmodifiableIteratorTest<E> extends AbstractIteratorTest<E> {
@ -73,10 +74,7 @@ public class UnmodifiableIteratorTest<E> extends AbstractIteratorTest<E> {
it = testList.iterator();
assertNotSame(it, UnmodifiableIterator.unmodifiableIterator(it));
try {
UnmodifiableIterator.unmodifiableIterator(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableIterator.unmodifiableIterator(null));
}
}

View File

@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.iterators;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.HashMap;
import java.util.Map;
@ -26,7 +28,6 @@ import org.apache.commons.collections4.bidimap.DualHashBidiMap;
/**
* Tests the UnmodifiableMapIterator.
*
*/
public class UnmodifiableMapIteratorTest<K, V> extends AbstractMapIteratorTest<K, V> {
@ -85,10 +86,7 @@ public class UnmodifiableMapIteratorTest<K, V> extends AbstractMapIteratorTest<K
it = getMap().mapIterator();
assertNotSame(it, UnmodifiableMapIterator.unmodifiableMapIterator(it));
try {
UnmodifiableMapIterator.unmodifiableMapIterator(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableMapIterator.unmodifiableMapIterator(null));
}
}

View File

@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.iterators;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
@ -27,7 +29,6 @@ import org.apache.commons.collections4.map.ListOrderedMap;
/**
* Tests the UnmodifiableOrderedMapIterator.
*
*/
public class UnmodifiableOrderedMapIteratorTest<K, V> extends AbstractOrderedMapIteratorTest<K, V> {
@ -87,10 +88,7 @@ public class UnmodifiableOrderedMapIteratorTest<K, V> extends AbstractOrderedMap
it = getMap().mapIterator();
assertNotSame(it, UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(it));
try {
UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(null));
}
}

View File

@ -24,8 +24,8 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
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;
/**
* Abstract tests that can be extended to test any Map.Entry implementation.
@ -108,15 +108,10 @@ public abstract class AbstractMapEntryTest<K, V> {
final Map.Entry<K, V> entry = makeMapEntry();
try {
entry.setValue((V) entry);
fail("Should throw an IllegalArgumentException");
} catch (final IllegalArgumentException iae) {
// expected to happen...
assertThrows(IllegalArgumentException.class, () -> entry.setValue((V) entry));
// check that the KVP's state has not changed
assertTrue(entry.getKey() == null && entry.getValue() == null);
}
// check that the KVP's state has not changed
assertTrue(entry.getKey() == null && entry.getValue() == null);
}
/**

View File

@ -22,7 +22,7 @@ import org.apache.commons.collections4.KeyValue;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Test the DefaultMapEntry class.
@ -84,13 +84,8 @@ public class DefaultMapEntryTest<K, V> extends AbstractMapEntryTest<K, V> {
public void testSelfReferenceHandling() {
final Map.Entry<K, V> entry = makeMapEntry();
try {
entry.setValue((V) entry);
assertSame(entry, entry.getValue());
} catch (final Exception e) {
fail("This Map.Entry implementation supports value self-reference.");
}
assertThrows(Exception.class, () -> entry.setValue((V) entry));
assertSame(entry, entry.getValue());
}
}

View File

@ -23,8 +23,8 @@ import org.apache.commons.collections4.Unmodifiable;
import org.junit.jupiter.api.Test;
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;
/**
* Test the UnmodifiableMapEntry class.
@ -103,10 +103,8 @@ public class UnmodifiableMapEntryTest<K, V> extends AbstractMapEntryTest<K, V> {
@Test
public void testUnmodifiable() {
final Map.Entry<K, V> entry = makeMapEntry();
try {
entry.setValue(null);
fail();
} catch (final UnsupportedOperationException ex) {}
assertThrows(UnsupportedOperationException.class, () -> entry.setValue(null));
}
}

View File

@ -327,10 +327,8 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
resetFull();
final ListIterator<E> it = getCollection().listIterator();
it.next();
try {
it.set(null);
fail();
} catch (final UnsupportedOperationException ex) {}
assertThrows(UnsupportedOperationException.class, () -> it.set(null));
}
@Override
@ -634,6 +632,6 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
// provide null values as Parameter
assertThrows(NullPointerException.class, () -> setUniqueList.createSetBasedOnList(null, list));
assertThrows(NullPointerException.class, () -> setUniqueList.createSetBasedOnList(new HashSet<>(), null));
}
}

View File

@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.map;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Map;
import java.util.HashMap;
import java.util.Collection;
@ -27,6 +29,7 @@ import java.util.Collection;
* @since 3.0
*/
public class CompositeMapTest<K, V> extends AbstractIterableMapTest<K, V> {
/** used as a flag in MapMutator tests */
private boolean pass = false;
@ -78,12 +81,8 @@ public class CompositeMapTest<K, V> extends AbstractIterableMapTest<K, V> {
map.addComposited(null);
map.addComposited(three);
assertTrue(map.containsKey("5"));
try {
map.addComposited(three);
fail("Expecting IllegalArgumentException.");
} catch (final IllegalArgumentException ex) {
// expected
}
assertThrows(IllegalArgumentException.class, () -> map.addComposited(three));
}
@SuppressWarnings("unchecked")

View File

@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.set;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@ -63,7 +65,6 @@ public class UnmodifiableSetTest<E> extends AbstractSetTest<E> {
return false;
}
public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullCollection() instanceof Unmodifiable);
@ -73,13 +74,9 @@ public class UnmodifiableSetTest<E> extends AbstractSetTest<E> {
final Set<E> set = makeFullCollection();
assertSame(set, UnmodifiableSet.unmodifiableSet(set));
try {
UnmodifiableSet.unmodifiableSet(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableSet.unmodifiableSet(null));
}
@Override
public String getCompatibilityVersion() {
return "4";

View File

@ -58,7 +58,6 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
return false;
}
public void testPrefixMap() {
final PatriciaTrie<String> trie = new PatriciaTrie<>();
@ -202,10 +201,10 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
iterator = map.keySet().iterator();
map.put("Amber", "Amber");
Assertions.assertEquals(3, map.size());
try {
iterator.next();
Assertions.fail("CME expected");
} catch(final ConcurrentModificationException expected) {}
final Iterator<String> iterator1 = iterator;
Assertions.assertThrows(ConcurrentModificationException.class, () -> iterator1.next());
Assertions.assertEquals("Amber", map.firstKey());
Assertions.assertEquals("Ammun", map.lastKey());
@ -243,28 +242,28 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
map = trie.prefixMap("Ab");
Assertions.assertTrue(map.isEmpty());
Assertions.assertEquals(0, map.size());
try {
final Object o = map.firstKey();
Assertions.fail("got a first key: " + o);
} catch(final NoSuchElementException nsee) {}
try {
final Object o = map.lastKey();
Assertions.fail("got a last key: " + o);
} catch(final NoSuchElementException nsee) {}
final SortedMap<String, String> map1 = map;
Assertions.assertThrows(NoSuchElementException.class, () -> map1.firstKey());
final SortedMap<String, String> map2 = map;
Assertions.assertThrows(NoSuchElementException.class, () -> map2.lastKey());
iterator = map.values().iterator();
Assertions.assertFalse(iterator.hasNext());
map = trie.prefixMap("Albertooo");
Assertions.assertTrue(map.isEmpty());
Assertions.assertEquals(0, map.size());
try {
final Object o = map.firstKey();
Assertions.fail("got a first key: " + o);
} catch(final NoSuchElementException nsee) {}
try {
final Object o = map.lastKey();
Assertions.fail("got a last key: " + o);
} catch(final NoSuchElementException nsee) {}
final SortedMap<String, String> map3 = map;
Assertions.assertThrows(NoSuchElementException.class, () -> map3.firstKey(),
() -> "got a first key: " + map3.firstKey());
final SortedMap<String, String> map4 = map;
Assertions.assertThrows(NoSuchElementException.class, () -> map4.lastKey(),
() -> "got a last key: " + map4.lastKey());
iterator = map.values().iterator();
Assertions.assertFalse(iterator.hasNext());
@ -274,14 +273,15 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
map = trie.prefixMap("\0");
Assertions.assertTrue(map.isEmpty());
Assertions.assertEquals(0, map.size());
try {
final Object o = map.firstKey();
Assertions.fail("got a first key: " + o);
} catch(final NoSuchElementException nsee) {}
try {
final Object o = map.lastKey();
Assertions.fail("got a last key: " + o);
} catch(final NoSuchElementException nsee) {}
final SortedMap<String, String> map5 = map;
Assertions.assertThrows(NoSuchElementException.class, () -> map5.firstKey(),
() -> "got a first key: " + map5.firstKey());
final SortedMap<String, String> map6 = map;
Assertions.assertThrows(NoSuchElementException.class, () -> map6.lastKey(),
() -> "got a last key: " + map6.lastKey());
iterator = map.values().iterator();
Assertions.assertFalse(iterator.hasNext());
}
@ -322,9 +322,10 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
iter.remove();
Assertions.assertEquals(1, map.size());
Assertions.assertEquals("Akko", iter.next());
if (iter.hasNext()) {
Assertions.fail("shouldn't have next (but was: " + iter.next() + ")");
}
final Iterator<String> iter1 = iter;
Assertions.assertFalse(iter.hasNext(), () -> "shouldn't have next (but was: " + iter1.next() + ")");
Assertions.assertFalse(iter.hasNext());
}
@ -426,7 +427,6 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
assertEquals(Arrays.asList(2, 3, 7, 1), new ArrayList<>(trie.values()));
}
@Override
public String getCompatibilityVersion() {
return "4";

View File

@ -16,6 +16,8 @@
*/
package org.apache.commons.collections4.trie;
import static org.junit.jupiter.api.Assertions.assertThrows;
import junit.framework.Test;
import org.apache.commons.collections4.BulkTest;
@ -68,7 +70,6 @@ public class UnmodifiableTrieTest<V> extends AbstractSortedMapTest<String, V> {
return UnmodifiableTrie.unmodifiableTrie(m);
}
public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullMap() instanceof Unmodifiable);
@ -78,13 +79,9 @@ public class UnmodifiableTrieTest<V> extends AbstractSortedMapTest<String, V> {
final Trie<String, V> trie = makeFullMap();
assertSame(trie, UnmodifiableTrie.unmodifiableTrie(trie));
try {
UnmodifiableTrie.unmodifiableTrie(null);
fail();
} catch (final NullPointerException ex) {}
assertThrows(NullPointerException.class, () -> UnmodifiableTrie.unmodifiableTrie(null));
}
/**
* Override to prevent infinite recursion of tests.
*/