diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java index 541428989..45a9943e8 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java @@ -17,7 +17,7 @@ package org.apache.commons.collections4.bloomfilter; 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.Arrays; @@ -73,12 +73,7 @@ public class SetOperationsTest { final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape2); final BloomFilter filter2 = new HasherBloomFilter(hasher2, shape2); - try { - SetOperations.cosineDistance(filter1, filter2); - fail("Expected an IllegalArgumentException"); - } catch (final IllegalArgumentException expected) { - // Ignore - } + assertThrows(IllegalArgumentException.class, () -> SetOperations.cosineDistance(filter1, filter2)); } /** @@ -351,4 +346,5 @@ public class SetOperationsTest { assertEquals(1.0, SetOperations.jaccardSimilarity(filter1, filter3), 0.0001); assertEquals(1.0, SetOperations.jaccardSimilarity(filter3, filter1), 0.0001); } + } diff --git a/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java index 2214520f3..91f9ad6be 100644 --- a/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java @@ -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; @@ -426,12 +428,9 @@ public class CompositeCollectionTest extends AbstractCollectionTest { @Override public void testUnsupportedRemove() { resetFull(); - try { - getCollection().remove(null); - fail("remove should raise UnsupportedOperationException"); - } catch (final UnsupportedOperationException e) { - // expected - } + + assertThrows(UnsupportedOperationException.class, () -> getCollection().remove(null)); + verify(); } diff --git a/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java index aca6ccd3b..c344bcb4b 100644 --- a/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java @@ -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; @@ -82,12 +84,9 @@ public class PredicatedCollectionTest extends AbstractCollectionTest { public void testIllegalAdd() { final Collection c = makeTestCollection(); final Integer i = 3; - try { - c.add((E) i); - fail("Integer should fail string predicate."); - } catch (final IllegalArgumentException e) { - // expected - } + + assertThrows(IllegalArgumentException.class, () -> c.add((E) i), "Integer should fail string predicate."); + assertFalse("Collection shouldn't contain illegal element", c.contains(i)); } @@ -99,12 +98,9 @@ public class PredicatedCollectionTest extends AbstractCollectionTest { elements.add((E) "two"); elements.add((E) Integer.valueOf(3)); elements.add((E) "four"); - try { - c.addAll(elements); - fail("Integer should fail string predicate."); - } catch (final IllegalArgumentException e) { - // expected - } + + assertThrows(IllegalArgumentException.class, () -> c.addAll(elements), "Integer should fail string predicate."); + 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(3)); diff --git a/src/test/java/org/apache/commons/collections4/comparators/ComparatorChainTest.java b/src/test/java/org/apache/commons/collections4/comparators/ComparatorChainTest.java index 9ddc8da47..69ec2b962 100644 --- a/src/test/java/org/apache/commons/collections4/comparators/ComparatorChainTest.java +++ b/src/test/java/org/apache/commons/collections4/comparators/ComparatorChainTest.java @@ -16,6 +16,8 @@ */ package org.apache.commons.collections4.comparators; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.io.Serializable; import java.util.Arrays; import java.util.Comparator; @@ -26,7 +28,6 @@ import org.junit.Test; /** * Tests for ComparatorChain. - * */ public class ComparatorChainTest extends AbstractComparatorTest { @@ -67,11 +68,8 @@ public class ComparatorChainTest extends AbstractComparatorTest chain = new ComparatorChain<>(); final Integer i1 = 4; final Integer i2 = 6; - try { - chain.compare(i1, i2); - fail("An exception should be thrown when a chain contains zero comparators."); - } catch (final UnsupportedOperationException e) { - } + + assertThrows(UnsupportedOperationException.class, () -> chain.compare(i1, i2), "An exception should be thrown when a chain contains zero comparators."); } @Test @@ -92,11 +90,8 @@ public class ComparatorChainTest extends AbstractComparatorTest chain = new ComparatorChain<>(list); final Integer i1 = 4; final Integer i2 = 6; - try { - chain.compare(i1, i2); - fail("An exception should be thrown when a chain contains zero comparators."); - } catch (final UnsupportedOperationException e) { - } + + assertThrows(UnsupportedOperationException.class, () -> chain.compare(i1, i2)); } @Test @@ -188,4 +183,5 @@ public class ComparatorChainTest extends AbstractComparatorTest closure = generateNoExceptionClosure(); - try { - closure.execute(Integer.valueOf(0)); - } catch (final RuntimeException ex) { - fail(); - } + @TestFactory + public Collection testThrowingClosure() { - closure = generateIOExceptionClosure(); - try { - closure.execute(Integer.valueOf(0)); - fail(); - } catch (final FunctorException ex) { - assertTrue(ex.getCause() instanceof IOException); - } catch (final RuntimeException ex) { - fail(); - } + return Arrays.asList( - closure = generateNullPointerExceptionClosure(); - try { - closure.execute(Integer.valueOf(0)); - fail(); - } catch (final FunctorException ex) { - fail(); - } catch (final RuntimeException ex) { - assertTrue(ex instanceof NullPointerException); - } + dynamicTest("Closure NoException", () -> { + Closure closure = generateNoExceptionClosure(); + closure.execute(Integer.valueOf(0)); + }), + + dynamicTest("Closure IOException", () -> { + Closure closure = generateIOExceptionClosure(); + final FunctorException thrown = assertThrows(FunctorException.class, () -> closure.execute(Integer.valueOf(0))); + assertTrue(thrown.getCause() instanceof IOException); + }), + + dynamicTest("Closure NullPointerException", () -> { + Closure closure = generateNullPointerExceptionClosure(); + assertThrows(NullPointerException.class, () -> closure.execute(Integer.valueOf(0))); + }) + + ); } + } diff --git a/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java index 8b4fc4c88..2f5a7143a 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ArrayListIteratorTest.java @@ -20,6 +20,7 @@ import java.util.ListIterator; import java.util.NoSuchElementException; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Test the ArrayListIterator class. @@ -104,15 +105,8 @@ public class ArrayListIteratorTest extends ArrayIteratorTest { // a call to set() before a call to next() or previous() should throw an IllegalStateException iter = makeArrayListIterator(testArray); - try { - iter.set((E) "should fail"); - 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()); - } - + ListIterator finalIter = iter; + assertThrows(IllegalStateException.class, () -> finalIter.set((E) "should fail"), "ListIterator#set should fail if next() or previous() have not yet been called."); } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapper2Test.java b/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapper2Test.java index 0f4904827..dc1fe478f 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapper2Test.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ListIteratorWrapper2Test.java @@ -23,9 +23,10 @@ import java.util.NoSuchElementException; 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. - * */ public class ListIteratorWrapper2Test extends AbstractIteratorTest { @@ -109,11 +110,7 @@ public class ListIteratorWrapper2Test extends AbstractIteratorTest { assertEquals(-1, iter.previousIndex()); assertEquals(0, iter.nextIndex()); - try { - iter.remove(); - fail("ListIteratorWrapper#remove() should fail; must be initially positioned first"); - } catch (final IllegalStateException e) { - } + assertThrows(IllegalStateException.class, () -> iter.remove(), "ListIteratorWrapper#remove() should fail; must be initially positioned first"); //no change from invalid op: assertEquals(-1, iter.previousIndex()); @@ -134,11 +131,7 @@ public class ListIteratorWrapper2Test extends AbstractIteratorTest { assertEquals(-1, iter.previousIndex()); assertEquals(0, iter.nextIndex()); - try { - iter.remove(); - fail("ListIteratorWrapper#remove() should fail; must be repositioned first"); - } catch (final IllegalStateException e) { - } + assertThrows(IllegalStateException.class, () -> iter.remove(), "ListIteratorWrapper#remove() should fail; must be repositioned first"); //no change from invalid op: assertEquals(-1, iter.previousIndex()); diff --git a/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java index 2b7960f15..500ac9085 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/ObjectArrayListIteratorTest.java @@ -20,6 +20,7 @@ import java.util.ListIterator; import java.util.NoSuchElementException; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Tests the ObjectArrayListIterator class. @@ -101,15 +102,8 @@ public class ObjectArrayListIteratorTest extends ObjectArrayIteratorTest { // a call to set() before a call to next() or previous() should throw an IllegalStateException iter = makeArrayListIterator((E[]) testArray); - try { - iter.set((E) "should fail"); - 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()); - } - + ListIterator finalIter = iter; + assertThrows(IllegalStateException.class, () -> finalIter.set((E) "should fail"), "ListIterator#set should fail if next() or previous() have not yet been called."); } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/PeekingIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/PeekingIteratorTest.java index 17e69c43d..4ce8cd85d 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/PeekingIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/PeekingIteratorTest.java @@ -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; @@ -105,12 +107,7 @@ public class PeekingIteratorTest extends AbstractIteratorTest { assertFalse(it.hasNext()); assertNull(it.peek()); - try { - it.element(); - fail(); - } catch (final NoSuchElementException e) { - // expected - } + assertThrows(NoSuchElementException.class, () -> it.element()); } @Test @@ -122,12 +119,7 @@ public class PeekingIteratorTest extends AbstractIteratorTest { assertTrue(it.hasNext()); assertEquals("b", it.peek()); - try { - it.remove(); - fail(); - } catch (final IllegalStateException e) { - // expected - } + assertThrows(IllegalStateException.class, () -> it.remove()); } private void validate(final Iterator iter, final E... items) { diff --git a/src/test/java/org/apache/commons/collections4/keyvalue/DefaultKeyValueTest.java b/src/test/java/org/apache/commons/collections4/keyvalue/DefaultKeyValueTest.java index dfbfe75f0..5aac52d5c 100644 --- a/src/test/java/org/apache/commons/collections4/keyvalue/DefaultKeyValueTest.java +++ b/src/test/java/org/apache/commons/collections4/keyvalue/DefaultKeyValueTest.java @@ -16,6 +16,8 @@ */ package org.apache.commons.collections4.keyvalue; +import static org.junit.jupiter.api.Assertions.assertThrows; + import org.junit.jupiter.api.Test; 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.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** * Test the DefaultKeyValue class. @@ -72,7 +73,6 @@ public class DefaultKeyValueTest { kv.setValue(null); assertNull(kv.getValue()); - } @SuppressWarnings("unchecked") @@ -84,25 +84,9 @@ public class DefaultKeyValueTest { final DefaultKeyValue kv = makeDefaultKeyValue(); - try { - kv.setKey((K) 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); - } - - 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); - } + assertThrows(IllegalArgumentException.class, () -> kv.setKey((K) kv)); + // check that the KVP's state has not changed + assertTrue(kv.getKey() == null && kv.getValue() == null); } /** @@ -140,7 +124,6 @@ public class DefaultKeyValueTest { // test that the KVP is independent of the Map.Entry entry.setValue(null); assertSame(value, kv.getValue()); - } @SuppressWarnings("unchecked") 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 5ff3310ce..05db8fc78 100644 --- a/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java +++ b/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java @@ -16,7 +16,9 @@ */ package org.apache.commons.collections4.keyvalue; +import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestFactory; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -24,6 +26,8 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; 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.assertNotSame; 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 static org.junit.jupiter.api.DynamicTest.dynamicTest; /** * Unit tests for {@link org.apache.commons.collections4.keyvalue.MultiKey}. - * */ public class MultiKeyTest { @@ -86,12 +90,14 @@ public class MultiKeyTest { return this; } } + Integer ONE = Integer.valueOf(1); Integer TWO = Integer.valueOf(2); Integer THREE = Integer.valueOf(3); Integer FOUR = Integer.valueOf(4); Integer FIVE = Integer.valueOf(5); + @Test public void testConstructors() throws Exception { MultiKey mk; @@ -139,21 +145,22 @@ public class MultiKeyTest { assertArrayEquals(new Object[]{THREE, FOUR, ONE, FIVE}, mk.getKeys()); } - @Test - public void testConstructorsByArrayNull() throws Exception { + @TestFactory + public Collection testConstructorsByArrayNull() { final Integer[] keys = null; - try { - new MultiKey<>(keys); - fail(); - } catch (final NullPointerException ex) {} - try { - new MultiKey<>(keys, true); - fail(); - } catch (final NullPointerException ex) {} - try { - new MultiKey<>(keys, false); - fail(); - } catch (final NullPointerException ex) {} + return Arrays.asList( + dynamicTest("Integer[] null", () -> { + assertThrows(NullPointerException.class, () -> new MultiKey<>(keys)); + }), + + dynamicTest("Integer[] null + makeClone true", () -> { + assertThrows(NullPointerException.class, () -> new MultiKey<>(keys, true)); + }), + + dynamicTest("Integer[] null + makeClone false", () -> { + assertThrows(NullPointerException.class, () -> new MultiKey<>(keys, false)); + }) + ); } @Test @@ -215,19 +222,26 @@ public class MultiKeyTest { assertEquals(mk.hashCode(), mk2.hashCode()); } - @Test - public void testGetIndexed() { + @TestFactory + public Collection testGetIndexed() { final MultiKey mk = new MultiKey<>(ONE, TWO); - assertSame(ONE, mk.getKey(0)); - assertSame(TWO, mk.getKey(1)); - try { - mk.getKey(-1); - fail(); - } catch (final IndexOutOfBoundsException ex) {} - try { - mk.getKey(2); - fail(); - } catch (final IndexOutOfBoundsException ex) {} + return Arrays.asList( + dynamicTest("0", () -> { + assertSame(ONE, mk.getKey(0)); + }), + + dynamicTest("1", () -> { + assertSame(TWO, mk.getKey(1)); + }), + + dynamicTest("-1", () -> { + assertThrows(IndexOutOfBoundsException.class, () -> mk.getKey(-1)); + }), + + dynamicTest("2", () -> { + assertThrows(IndexOutOfBoundsException.class, () -> mk.getKey(2)); + }) + ); } @Test diff --git a/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java b/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java index 000b2b5b2..3fbda3e5e 100644 --- a/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java @@ -16,6 +16,8 @@ */ package org.apache.commons.collections4.map; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -397,12 +399,9 @@ public class MultiValueMapTest extends AbstractObjectTest { final MultiValueMap map2 = MultiValueMap.multiValueMap(new HashMap(), (Class) String.class); bytes = serialize(map2); - try { - result = deserialize(bytes); - fail("unsafe clazz accepted when de-serializing MultiValueMap"); - } catch (final UnsupportedOperationException ex) { - // expected - } + + byte[] finalBytes = bytes; + assertThrows(UnsupportedOperationException.class, () -> deserialize(finalBytes)); } private byte[] serialize(final Object object) throws IOException { @@ -453,6 +452,7 @@ public class MultiValueMapTest extends AbstractObjectTest { final Map map2 = (Map) readExternalFormFromDisk(getCanonicalEmptyCollectionName(map)); assertEquals("Map is empty", 0, map2.size()); } + public void testFullMapCompatibility() throws Exception { final Map map = (Map) makeObject(); final Map map2 = (Map) readExternalFormFromDisk(getCanonicalFullCollectionName(map)); diff --git a/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java b/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java index ba6eaa284..56bf8e0de 100644 --- a/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java @@ -16,6 +16,8 @@ */ package org.apache.commons.collections4.map; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.util.HashMap; import java.util.Map; @@ -63,7 +65,6 @@ public class UnmodifiableMapTest extends AbstractIterableMapTest { return (IterableMap) UnmodifiableMap.unmodifiableMap(m); } - public void testUnmodifiable() { assertTrue(makeObject() instanceof Unmodifiable); assertTrue(makeFullMap() instanceof Unmodifiable); @@ -73,13 +74,9 @@ public class UnmodifiableMapTest extends AbstractIterableMapTest { final Map map = makeFullMap(); assertSame(map, UnmodifiableMap.unmodifiableMap(map)); - try { - UnmodifiableMap.unmodifiableMap(null); - fail(); - } catch (final NullPointerException ex) {} + assertThrows(NullPointerException.class, () -> UnmodifiableMap.unmodifiableMap(null)); } - @Override public String getCompatibilityVersion() { return "4"; diff --git a/src/test/java/org/apache/commons/collections4/map/UnmodifiableOrderedMapTest.java b/src/test/java/org/apache/commons/collections4/map/UnmodifiableOrderedMapTest.java index 4622a07bf..dc2313fd3 100644 --- a/src/test/java/org/apache/commons/collections4/map/UnmodifiableOrderedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/UnmodifiableOrderedMapTest.java @@ -16,6 +16,8 @@ */ package org.apache.commons.collections4.map; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.util.HashMap; import org.apache.commons.collections4.OrderedMap; @@ -62,7 +64,6 @@ public class UnmodifiableOrderedMapTest extends AbstractOrderedMapTest extends AbstractOrderedMapTest map = makeFullMap(); assertSame(map, UnmodifiableOrderedMap.unmodifiableOrderedMap(map)); - try { - UnmodifiableOrderedMap.unmodifiableOrderedMap(null); - fail(); - } catch (final NullPointerException ex) {} + assertThrows(NullPointerException.class, () -> UnmodifiableOrderedMap.unmodifiableOrderedMap(null)); } - @Override public String getCompatibilityVersion() { return "4"; diff --git a/src/test/java/org/apache/commons/collections4/map/UnmodifiableSortedMapTest.java b/src/test/java/org/apache/commons/collections4/map/UnmodifiableSortedMapTest.java index 3dfd504dc..0c5fccaf9 100644 --- a/src/test/java/org/apache/commons/collections4/map/UnmodifiableSortedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/UnmodifiableSortedMapTest.java @@ -16,6 +16,8 @@ */ package org.apache.commons.collections4.map; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.util.SortedMap; import java.util.TreeMap; @@ -62,7 +64,6 @@ public class UnmodifiableSortedMapTest extends AbstractSortedMapTest return UnmodifiableSortedMap.unmodifiableSortedMap(m); } - public void testUnmodifiable() { assertTrue(makeObject() instanceof Unmodifiable); assertTrue(makeFullMap() instanceof Unmodifiable); @@ -72,13 +73,9 @@ public class UnmodifiableSortedMapTest extends AbstractSortedMapTest final SortedMap map = makeFullMap(); assertSame(map, UnmodifiableSortedMap.unmodifiableSortedMap(map)); - try { - UnmodifiableSortedMap.unmodifiableSortedMap(null); - fail(); - } catch (final NullPointerException ex) {} + assertThrows(NullPointerException.class, () -> UnmodifiableSortedMap.unmodifiableSortedMap(null)); } - public void testHeadMap() { final SortedMap map = makeFullMap(); final SortedMap m = new TreeMap<>(); @@ -91,7 +88,6 @@ public class UnmodifiableSortedMapTest extends AbstractSortedMapTest assertSame(16, map.headMap((K) "we'll").size()); } - public void testTailMap() { final SortedMap map = makeFullMap(); @@ -104,7 +100,6 @@ public class UnmodifiableSortedMapTest extends AbstractSortedMapTest assertSame(18, map.tailMap((K) "again").size()); } - public void testSubMap() { final SortedMap map = makeFullMap(); @@ -119,7 +114,6 @@ public class UnmodifiableSortedMapTest extends AbstractSortedMapTest assertSame(map.headMap((K) "you").size(), map.subMap((K) "again", (K) "you").size()); } - @Override public String getCompatibilityVersion() { return "4";