COLLECTIONS-777 JUnit v5 (#282)

JUnit v5 assertThrows SetOperationsTest

JUnit v5 assertThrows CompositeCollectionTest

JUnit v5 assertThrows MultiValueMapTest

JUnit v5 assertThrows UnmodifiableMapTest

JUnit v5 assertThrows UnmodifiableOrderedMapTest

JUnit v5 assertThrows UnmodifiableSortedMapTest

JUnit v5 assertThrows CatchAndRethrowClosureTest

JUnit v5 assertThrows PredicatedCollectionTest

JUnit v5 assertThrows ComparatorChainTest

JUnit v5 assertThrows ArrayListIteratorTest

JUnit v5 assertThrows ListIteratorWrapper2Test

JUnit v5 assertThrows ObjectArrayListIteratorTest

JUnit v5 assertThrows PeekingIteratorTest

JUnit v5 assertThrows DefaultKeyValueTest

JUnit v5 assertThrows MultiKeyTest
This commit is contained in:
John Patrick 2022-03-04 13:40:31 +00:00 committed by GitHub
parent f4c041ba94
commit e113297085
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 126 additions and 182 deletions

View File

@ -17,7 +17,7 @@
package org.apache.commons.collections4.bloomfilter; package org.apache.commons.collections4.bloomfilter;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.List; import java.util.List;
import java.util.Arrays; import java.util.Arrays;
@ -73,12 +73,7 @@ public class SetOperationsTest {
final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape2); final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape2);
final BloomFilter filter2 = new HasherBloomFilter(hasher2, shape2); final BloomFilter filter2 = new HasherBloomFilter(hasher2, shape2);
try { assertThrows(IllegalArgumentException.class, () -> SetOperations.cosineDistance(filter1, filter2));
SetOperations.cosineDistance(filter1, filter2);
fail("Expected an IllegalArgumentException");
} catch (final IllegalArgumentException expected) {
// Ignore
}
} }
/** /**
@ -351,4 +346,5 @@ public class SetOperationsTest {
assertEquals(1.0, SetOperations.jaccardSimilarity(filter1, filter3), 0.0001); assertEquals(1.0, SetOperations.jaccardSimilarity(filter1, filter3), 0.0001);
assertEquals(1.0, SetOperations.jaccardSimilarity(filter3, filter1), 0.0001); assertEquals(1.0, SetOperations.jaccardSimilarity(filter3, filter1), 0.0001);
} }
} }

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.collections4.collection; package org.apache.commons.collections4.collection;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -426,12 +428,9 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
@Override @Override
public void testUnsupportedRemove() { public void testUnsupportedRemove() {
resetFull(); resetFull();
try {
getCollection().remove(null); assertThrows(UnsupportedOperationException.class, () -> getCollection().remove(null));
fail("remove should raise UnsupportedOperationException");
} catch (final UnsupportedOperationException e) {
// expected
}
verify(); verify();
} }

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.collections4.collection; package org.apache.commons.collections4.collection;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -82,12 +84,9 @@ public class PredicatedCollectionTest<E> extends AbstractCollectionTest<E> {
public void testIllegalAdd() { public void testIllegalAdd() {
final Collection<E> c = makeTestCollection(); final Collection<E> c = makeTestCollection();
final Integer i = 3; final Integer i = 3;
try {
c.add((E) i); assertThrows(IllegalArgumentException.class, () -> c.add((E) i), "Integer should fail string predicate.");
fail("Integer should fail string predicate.");
} catch (final IllegalArgumentException e) {
// expected
}
assertFalse("Collection shouldn't contain illegal element", c.contains(i)); assertFalse("Collection shouldn't contain illegal element", c.contains(i));
} }
@ -99,12 +98,9 @@ public class PredicatedCollectionTest<E> extends AbstractCollectionTest<E> {
elements.add((E) "two"); elements.add((E) "two");
elements.add((E) Integer.valueOf(3)); elements.add((E) Integer.valueOf(3));
elements.add((E) "four"); elements.add((E) "four");
try {
c.addAll(elements); assertThrows(IllegalArgumentException.class, () -> c.addAll(elements), "Integer should fail string predicate.");
fail("Integer should fail string predicate.");
} catch (final IllegalArgumentException e) {
// expected
}
assertFalse("Collection shouldn't contain illegal element", c.contains("one")); assertFalse("Collection shouldn't contain illegal element", c.contains("one"));
assertFalse("Collection shouldn't contain illegal element", c.contains("two")); assertFalse("Collection shouldn't contain illegal element", c.contains("two"));
assertFalse("Collection shouldn't contain illegal element", c.contains(3)); assertFalse("Collection shouldn't contain illegal element", c.contains(3));

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.collections4.comparators; package org.apache.commons.collections4.comparators;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@ -26,7 +28,6 @@ import org.junit.Test;
/** /**
* Tests for ComparatorChain. * Tests for ComparatorChain.
*
*/ */
public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainTest.PseudoRow> { public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainTest.PseudoRow> {
@ -67,11 +68,8 @@ public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainT
final ComparatorChain<Integer> chain = new ComparatorChain<>(); final ComparatorChain<Integer> chain = new ComparatorChain<>();
final Integer i1 = 4; final Integer i1 = 4;
final Integer i2 = 6; final Integer i2 = 6;
try {
chain.compare(i1, i2); assertThrows(UnsupportedOperationException.class, () -> chain.compare(i1, i2), "An exception should be thrown when a chain contains zero comparators.");
fail("An exception should be thrown when a chain contains zero comparators.");
} catch (final UnsupportedOperationException e) {
}
} }
@Test @Test
@ -92,11 +90,8 @@ public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainT
final ComparatorChain<Integer> chain = new ComparatorChain<>(list); final ComparatorChain<Integer> chain = new ComparatorChain<>(list);
final Integer i1 = 4; final Integer i1 = 4;
final Integer i2 = 6; final Integer i2 = 6;
try {
chain.compare(i1, i2); assertThrows(UnsupportedOperationException.class, () -> chain.compare(i1, i2));
fail("An exception should be thrown when a chain contains zero comparators.");
} catch (final UnsupportedOperationException e) {
}
} }
@Test @Test
@ -188,4 +183,5 @@ public class ComparatorChainTest extends AbstractComparatorTest<ComparatorChainT
return that instanceof ColumnComparator && colIndex == ((ColumnComparator) that).colIndex; return that instanceof ColumnComparator && colIndex == ((ColumnComparator) that).colIndex;
} }
} }
} }

View File

@ -17,13 +17,17 @@
package org.apache.commons.collections4.functors; package org.apache.commons.collections4.functors;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import org.apache.commons.collections4.Closure; import org.apache.commons.collections4.Closure;
import org.apache.commons.collections4.FunctorException; import org.apache.commons.collections4.FunctorException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.DynamicTest.dynamicTest;
public class CatchAndRethrowClosureTest extends AbstractClosureTest { public class CatchAndRethrowClosureTest extends AbstractClosureTest {
@ -61,33 +65,28 @@ public class CatchAndRethrowClosureTest extends AbstractClosureTest {
return generateNoExceptionClosure(); return generateNoExceptionClosure();
} }
@Test @TestFactory
public void testThrowingClosure() { public Collection<DynamicTest> testThrowingClosure() {
Closure<Integer> closure = generateNoExceptionClosure();
try {
closure.execute(Integer.valueOf(0));
} catch (final RuntimeException ex) {
fail();
}
closure = generateIOExceptionClosure(); return Arrays.asList(
try {
closure.execute(Integer.valueOf(0));
fail();
} catch (final FunctorException ex) {
assertTrue(ex.getCause() instanceof IOException);
} catch (final RuntimeException ex) {
fail();
}
closure = generateNullPointerExceptionClosure(); dynamicTest("Closure NoException", () -> {
try { Closure<Integer> closure = generateNoExceptionClosure();
closure.execute(Integer.valueOf(0)); closure.execute(Integer.valueOf(0));
fail(); }),
} catch (final FunctorException ex) {
fail(); dynamicTest("Closure IOException", () -> {
} catch (final RuntimeException ex) { Closure<Integer> closure = generateIOExceptionClosure();
assertTrue(ex instanceof NullPointerException); final FunctorException thrown = assertThrows(FunctorException.class, () -> closure.execute(Integer.valueOf(0)));
} assertTrue(thrown.getCause() instanceof IOException);
}),
dynamicTest("Closure NullPointerException", () -> {
Closure<Integer> closure = generateNullPointerExceptionClosure();
assertThrows(NullPointerException.class, () -> closure.execute(Integer.valueOf(0)));
})
);
} }
} }

View File

@ -20,6 +20,7 @@ import java.util.ListIterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Test the ArrayListIterator class. * Test the ArrayListIterator class.
@ -104,15 +105,8 @@ public class ArrayListIteratorTest<E> extends ArrayIteratorTest<E> {
// a call to set() before a call to next() or previous() should throw an IllegalStateException // a call to set() before a call to next() or previous() should throw an IllegalStateException
iter = makeArrayListIterator(testArray); iter = makeArrayListIterator(testArray);
try { ListIterator<E> finalIter = iter;
iter.set((E) "should fail"); assertThrows(IllegalStateException.class, () -> finalIter.set((E) "should fail"), "ListIterator#set should fail if next() or previous() have not yet been called.");
fail("ListIterator#set should fail if next() or previous() have not yet been called.");
} catch (final IllegalStateException e) {
// expected
} catch (final Throwable t) { // should never happen
fail(t.toString());
}
} }
} }

View File

@ -23,9 +23,10 @@ import java.util.NoSuchElementException;
import org.apache.commons.collections4.ResettableListIterator; import org.apache.commons.collections4.ResettableListIterator;
import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Tests the ListIteratorWrapper to insure that it behaves as expected when wrapping a ListIterator. * Tests the ListIteratorWrapper to insure that it behaves as expected when wrapping a ListIterator.
*
*/ */
public class ListIteratorWrapper2Test<E> extends AbstractIteratorTest<E> { public class ListIteratorWrapper2Test<E> extends AbstractIteratorTest<E> {
@ -109,11 +110,7 @@ public class ListIteratorWrapper2Test<E> extends AbstractIteratorTest<E> {
assertEquals(-1, iter.previousIndex()); assertEquals(-1, iter.previousIndex());
assertEquals(0, iter.nextIndex()); assertEquals(0, iter.nextIndex());
try { assertThrows(IllegalStateException.class, () -> iter.remove(), "ListIteratorWrapper#remove() should fail; must be initially positioned first");
iter.remove();
fail("ListIteratorWrapper#remove() should fail; must be initially positioned first");
} catch (final IllegalStateException e) {
}
//no change from invalid op: //no change from invalid op:
assertEquals(-1, iter.previousIndex()); assertEquals(-1, iter.previousIndex());
@ -134,11 +131,7 @@ public class ListIteratorWrapper2Test<E> extends AbstractIteratorTest<E> {
assertEquals(-1, iter.previousIndex()); assertEquals(-1, iter.previousIndex());
assertEquals(0, iter.nextIndex()); assertEquals(0, iter.nextIndex());
try { assertThrows(IllegalStateException.class, () -> iter.remove(), "ListIteratorWrapper#remove() should fail; must be repositioned first");
iter.remove();
fail("ListIteratorWrapper#remove() should fail; must be repositioned first");
} catch (final IllegalStateException e) {
}
//no change from invalid op: //no change from invalid op:
assertEquals(-1, iter.previousIndex()); assertEquals(-1, iter.previousIndex());

View File

@ -20,6 +20,7 @@ import java.util.ListIterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Tests the ObjectArrayListIterator class. * Tests the ObjectArrayListIterator class.
@ -101,15 +102,8 @@ public class ObjectArrayListIteratorTest<E> extends ObjectArrayIteratorTest<E> {
// a call to set() before a call to next() or previous() should throw an IllegalStateException // a call to set() before a call to next() or previous() should throw an IllegalStateException
iter = makeArrayListIterator((E[]) testArray); iter = makeArrayListIterator((E[]) testArray);
try { ListIterator<E> finalIter = iter;
iter.set((E) "should fail"); assertThrows(IllegalStateException.class, () -> finalIter.set((E) "should fail"), "ListIterator#set should fail if next() or previous() have not yet been called.");
fail("ListIterator#set should fail if next() or previous() have not yet been called.");
} catch (final IllegalStateException e) {
// expected
} catch (final Throwable t) { // should never happen
fail(t.toString());
}
} }
} }

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.collections4.iterators; package org.apache.commons.collections4.iterators;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -105,12 +107,7 @@ public class PeekingIteratorTest<E> extends AbstractIteratorTest<E> {
assertFalse(it.hasNext()); assertFalse(it.hasNext());
assertNull(it.peek()); assertNull(it.peek());
try { assertThrows(NoSuchElementException.class, () -> it.element());
it.element();
fail();
} catch (final NoSuchElementException e) {
// expected
}
} }
@Test @Test
@ -122,12 +119,7 @@ public class PeekingIteratorTest<E> extends AbstractIteratorTest<E> {
assertTrue(it.hasNext()); assertTrue(it.hasNext());
assertEquals("b", it.peek()); assertEquals("b", it.peek());
try { assertThrows(IllegalStateException.class, () -> it.remove());
it.remove();
fail();
} catch (final IllegalStateException e) {
// expected
}
} }
private void validate(final Iterator<E> iter, final E... items) { private void validate(final Iterator<E> iter, final E... items) {

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.collections4.keyvalue; package org.apache.commons.collections4.keyvalue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.HashMap; import java.util.HashMap;
@ -25,7 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/** /**
* Test the DefaultKeyValue class. * Test the DefaultKeyValue class.
@ -72,7 +73,6 @@ public class DefaultKeyValueTest<K, V> {
kv.setValue(null); kv.setValue(null);
assertNull(kv.getValue()); assertNull(kv.getValue());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -84,25 +84,9 @@ public class DefaultKeyValueTest<K, V> {
final DefaultKeyValue<K, V> kv = makeDefaultKeyValue(); final DefaultKeyValue<K, V> kv = makeDefaultKeyValue();
try { assertThrows(IllegalArgumentException.class, () -> kv.setKey((K) kv));
kv.setKey((K) kv); // check that the KVP's state has not changed
fail("Should throw an IllegalArgumentException"); assertTrue(kv.getKey() == null && kv.getValue() == null);
} catch (final IllegalArgumentException iae) {
// expected to happen...
// check that the KVP's state has not changed
assertTrue(kv.getKey() == null && kv.getValue() == null);
}
try {
kv.setValue((V) kv);
fail("Should throw an IllegalArgumentException");
} catch (final IllegalArgumentException iae) {
// expected to happen...
// check that the KVP's state has not changed
assertTrue(kv.getKey() == null && kv.getValue() == null);
}
} }
/** /**
@ -140,7 +124,6 @@ public class DefaultKeyValueTest<K, V> {
// test that the KVP is independent of the Map.Entry // test that the KVP is independent of the Map.Entry
entry.setValue(null); entry.setValue(null);
assertSame(value, kv.getValue()); assertSame(value, kv.getValue());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -16,7 +16,9 @@
*/ */
package org.apache.commons.collections4.keyvalue; package org.apache.commons.collections4.keyvalue;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -24,6 +26,8 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -33,12 +37,12 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame; 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.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.DynamicTest.dynamicTest;
/** /**
* Unit tests for {@link org.apache.commons.collections4.keyvalue.MultiKey}. * Unit tests for {@link org.apache.commons.collections4.keyvalue.MultiKey}.
*
*/ */
public class MultiKeyTest { public class MultiKeyTest {
@ -86,12 +90,14 @@ public class MultiKeyTest {
return this; return this;
} }
} }
Integer ONE = Integer.valueOf(1); Integer ONE = Integer.valueOf(1);
Integer TWO = Integer.valueOf(2); Integer TWO = Integer.valueOf(2);
Integer THREE = Integer.valueOf(3); Integer THREE = Integer.valueOf(3);
Integer FOUR = Integer.valueOf(4); Integer FOUR = Integer.valueOf(4);
Integer FIVE = Integer.valueOf(5); Integer FIVE = Integer.valueOf(5);
@Test @Test
public void testConstructors() throws Exception { public void testConstructors() throws Exception {
MultiKey<Integer> mk; MultiKey<Integer> mk;
@ -139,21 +145,22 @@ public class MultiKeyTest {
assertArrayEquals(new Object[]{THREE, FOUR, ONE, FIVE}, mk.getKeys()); assertArrayEquals(new Object[]{THREE, FOUR, ONE, FIVE}, mk.getKeys());
} }
@Test @TestFactory
public void testConstructorsByArrayNull() throws Exception { public Collection<DynamicTest> testConstructorsByArrayNull() {
final Integer[] keys = null; final Integer[] keys = null;
try { return Arrays.asList(
new MultiKey<>(keys); dynamicTest("Integer[] null", () -> {
fail(); assertThrows(NullPointerException.class, () -> new MultiKey<>(keys));
} catch (final NullPointerException ex) {} }),
try {
new MultiKey<>(keys, true); dynamicTest("Integer[] null + makeClone true", () -> {
fail(); assertThrows(NullPointerException.class, () -> new MultiKey<>(keys, true));
} catch (final NullPointerException ex) {} }),
try {
new MultiKey<>(keys, false); dynamicTest("Integer[] null + makeClone false", () -> {
fail(); assertThrows(NullPointerException.class, () -> new MultiKey<>(keys, false));
} catch (final NullPointerException ex) {} })
);
} }
@Test @Test
@ -215,19 +222,26 @@ public class MultiKeyTest {
assertEquals(mk.hashCode(), mk2.hashCode()); assertEquals(mk.hashCode(), mk2.hashCode());
} }
@Test @TestFactory
public void testGetIndexed() { public Collection<DynamicTest> testGetIndexed() {
final MultiKey<Integer> mk = new MultiKey<>(ONE, TWO); final MultiKey<Integer> mk = new MultiKey<>(ONE, TWO);
assertSame(ONE, mk.getKey(0)); return Arrays.asList(
assertSame(TWO, mk.getKey(1)); dynamicTest("0", () -> {
try { assertSame(ONE, mk.getKey(0));
mk.getKey(-1); }),
fail();
} catch (final IndexOutOfBoundsException ex) {} dynamicTest("1", () -> {
try { assertSame(TWO, mk.getKey(1));
mk.getKey(2); }),
fail();
} catch (final IndexOutOfBoundsException ex) {} dynamicTest("-1", () -> {
assertThrows(IndexOutOfBoundsException.class, () -> mk.getKey(-1));
}),
dynamicTest("2", () -> {
assertThrows(IndexOutOfBoundsException.class, () -> mk.getKey(2));
})
);
} }
@Test @Test

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.collections4.map; package org.apache.commons.collections4.map;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -397,12 +399,9 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
final MultiValueMap map2 = MultiValueMap.multiValueMap(new HashMap(), (Class) String.class); final MultiValueMap map2 = MultiValueMap.multiValueMap(new HashMap(), (Class) String.class);
bytes = serialize(map2); bytes = serialize(map2);
try {
result = deserialize(bytes); byte[] finalBytes = bytes;
fail("unsafe clazz accepted when de-serializing MultiValueMap"); assertThrows(UnsupportedOperationException.class, () -> deserialize(finalBytes));
} catch (final UnsupportedOperationException ex) {
// expected
}
} }
private byte[] serialize(final Object object) throws IOException { private byte[] serialize(final Object object) throws IOException {
@ -453,6 +452,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
final Map<?, ?> map2 = (Map<?, ?>) readExternalFormFromDisk(getCanonicalEmptyCollectionName(map)); final Map<?, ?> map2 = (Map<?, ?>) readExternalFormFromDisk(getCanonicalEmptyCollectionName(map));
assertEquals("Map is empty", 0, map2.size()); assertEquals("Map is empty", 0, map2.size());
} }
public void testFullMapCompatibility() throws Exception { public void testFullMapCompatibility() throws Exception {
final Map<?, ?> map = (Map<?, ?>) makeObject(); final Map<?, ?> map = (Map<?, ?>) makeObject();
final Map<?, ?> map2 = (Map<?, ?>) readExternalFormFromDisk(getCanonicalFullCollectionName(map)); final Map<?, ?> map2 = (Map<?, ?>) readExternalFormFromDisk(getCanonicalFullCollectionName(map));

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.collections4.map; package org.apache.commons.collections4.map;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -63,7 +65,6 @@ public class UnmodifiableMapTest<K, V> extends AbstractIterableMapTest<K, V> {
return (IterableMap<K, V>) UnmodifiableMap.unmodifiableMap(m); return (IterableMap<K, V>) UnmodifiableMap.unmodifiableMap(m);
} }
public void testUnmodifiable() { public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable); assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullMap() instanceof Unmodifiable); assertTrue(makeFullMap() instanceof Unmodifiable);
@ -73,13 +74,9 @@ public class UnmodifiableMapTest<K, V> extends AbstractIterableMapTest<K, V> {
final Map<K, V> map = makeFullMap(); final Map<K, V> map = makeFullMap();
assertSame(map, UnmodifiableMap.unmodifiableMap(map)); assertSame(map, UnmodifiableMap.unmodifiableMap(map));
try { assertThrows(NullPointerException.class, () -> UnmodifiableMap.unmodifiableMap(null));
UnmodifiableMap.unmodifiableMap(null);
fail();
} catch (final NullPointerException ex) {}
} }
@Override @Override
public String getCompatibilityVersion() { public String getCompatibilityVersion() {
return "4"; return "4";

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.collections4.map; package org.apache.commons.collections4.map;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.HashMap; import java.util.HashMap;
import org.apache.commons.collections4.OrderedMap; import org.apache.commons.collections4.OrderedMap;
@ -62,7 +64,6 @@ public class UnmodifiableOrderedMapTest<K, V> extends AbstractOrderedMapTest<K,
return UnmodifiableOrderedMap.unmodifiableOrderedMap(m); return UnmodifiableOrderedMap.unmodifiableOrderedMap(m);
} }
public void testUnmodifiable() { public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable); assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullMap() instanceof Unmodifiable); assertTrue(makeFullMap() instanceof Unmodifiable);
@ -72,13 +73,9 @@ public class UnmodifiableOrderedMapTest<K, V> extends AbstractOrderedMapTest<K,
final OrderedMap<K, V> map = makeFullMap(); final OrderedMap<K, V> map = makeFullMap();
assertSame(map, UnmodifiableOrderedMap.unmodifiableOrderedMap(map)); assertSame(map, UnmodifiableOrderedMap.unmodifiableOrderedMap(map));
try { assertThrows(NullPointerException.class, () -> UnmodifiableOrderedMap.unmodifiableOrderedMap(null));
UnmodifiableOrderedMap.unmodifiableOrderedMap(null);
fail();
} catch (final NullPointerException ex) {}
} }
@Override @Override
public String getCompatibilityVersion() { public String getCompatibilityVersion() {
return "4"; return "4";

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.collections4.map; package org.apache.commons.collections4.map;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
@ -62,7 +64,6 @@ public class UnmodifiableSortedMapTest<K, V> extends AbstractSortedMapTest<K, V>
return UnmodifiableSortedMap.unmodifiableSortedMap(m); return UnmodifiableSortedMap.unmodifiableSortedMap(m);
} }
public void testUnmodifiable() { public void testUnmodifiable() {
assertTrue(makeObject() instanceof Unmodifiable); assertTrue(makeObject() instanceof Unmodifiable);
assertTrue(makeFullMap() instanceof Unmodifiable); assertTrue(makeFullMap() instanceof Unmodifiable);
@ -72,13 +73,9 @@ public class UnmodifiableSortedMapTest<K, V> extends AbstractSortedMapTest<K, V>
final SortedMap<K, V> map = makeFullMap(); final SortedMap<K, V> map = makeFullMap();
assertSame(map, UnmodifiableSortedMap.unmodifiableSortedMap(map)); assertSame(map, UnmodifiableSortedMap.unmodifiableSortedMap(map));
try { assertThrows(NullPointerException.class, () -> UnmodifiableSortedMap.unmodifiableSortedMap(null));
UnmodifiableSortedMap.unmodifiableSortedMap(null);
fail();
} catch (final NullPointerException ex) {}
} }
public void testHeadMap() { public void testHeadMap() {
final SortedMap<K, V> map = makeFullMap(); final SortedMap<K, V> map = makeFullMap();
final SortedMap<K, V> m = new TreeMap<>(); final SortedMap<K, V> m = new TreeMap<>();
@ -91,7 +88,6 @@ public class UnmodifiableSortedMapTest<K, V> extends AbstractSortedMapTest<K, V>
assertSame(16, map.headMap((K) "we'll").size()); assertSame(16, map.headMap((K) "we'll").size());
} }
public void testTailMap() { public void testTailMap() {
final SortedMap<K, V> map = makeFullMap(); final SortedMap<K, V> map = makeFullMap();
@ -104,7 +100,6 @@ public class UnmodifiableSortedMapTest<K, V> extends AbstractSortedMapTest<K, V>
assertSame(18, map.tailMap((K) "again").size()); assertSame(18, map.tailMap((K) "again").size());
} }
public void testSubMap() { public void testSubMap() {
final SortedMap<K, V> map = makeFullMap(); final SortedMap<K, V> map = makeFullMap();
@ -119,7 +114,6 @@ public class UnmodifiableSortedMapTest<K, V> extends AbstractSortedMapTest<K, V>
assertSame(map.headMap((K) "you").size(), map.subMap((K) "again", (K) "you").size()); assertSame(map.headMap((K) "you").size(), map.subMap((K) "again", (K) "you").size());
} }
@Override @Override
public String getCompatibilityVersion() { public String getCompatibilityVersion() {
return "4"; return "4";