diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/bag/mutable/primitive/AbstractMutableBooleanBagTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/bag/mutable/primitive/AbstractMutableBooleanBagTestCase.java index c710d632c9..4618edae96 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/bag/mutable/primitive/AbstractMutableBooleanBagTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/bag/mutable/primitive/AbstractMutableBooleanBagTestCase.java @@ -95,10 +95,10 @@ public void addOccurrences() assertEquals(BooleanHashBag.newBagWith(false, false, false, false, false, true), bag); } - @Test(expected = IllegalArgumentException.class) + @Test public void addOccurrences_throws() { - this.newWith().addOccurrences(true, -1); + assertThrows(IllegalArgumentException.class, () -> this.newWith().addOccurrences(true, -1)); } @Test @@ -129,10 +129,10 @@ public void removeOccurrences() assertEquals(new BooleanHashBag(), bag2); } - @Test(expected = IllegalArgumentException.class) + @Test public void removeOccurrences_throws() { - this.newWith().removeOccurrences(true, -1); + assertThrows(IllegalArgumentException.class, () -> this.newWith().removeOccurrences(true, -1)); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/bag/sorted/immutable/AbstractImmutableSortedBagTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/bag/sorted/immutable/AbstractImmutableSortedBagTestCase.java index 645786569e..ac9227f3be 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/bag/sorted/immutable/AbstractImmutableSortedBagTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/bag/sorted/immutable/AbstractImmutableSortedBagTestCase.java @@ -113,10 +113,10 @@ protected ImmutableSortedBag newWithOccurrences(ObjectIntPair... eleme protected abstract ImmutableSortedBag newWith(Comparator comparator, T... elements); - @Test(expected = NullPointerException.class) + @Test public void noSupportForNull() { - this.classUnderTest().newWith(null); + assertThrows(NullPointerException.class, () -> this.classUnderTest().newWith(null)); } @Test @@ -717,10 +717,10 @@ public void zipWithIndex() } @Override - @Test(expected = IllegalArgumentException.class) + @Test public void chunk_zero_throws() { - this.classUnderTest().chunk(0); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().chunk(0)); } @Test @@ -1514,10 +1514,10 @@ public void take() assertSame(integers2, integers2.take(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void take_throws() { - this.classUnderTest().take(-1); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().take(-1)); } @Test @@ -1532,10 +1532,10 @@ public void drop() assertEquals(SortedBags.immutable.empty(integers1.comparator()), integers1.drop(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void drop_throws() { - this.classUnderTest().drop(-1); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().drop(-1)); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapEntrySetTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapEntrySetTest.java index 0409e265b2..564c9552bc 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapEntrySetTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapEntrySetTest.java @@ -178,20 +178,20 @@ public void entrySet_containsAll() assertTrue(entries.containsAll(FastList.newListWith(ImmutableEntry.of(1, "One"), ImmutableEntry.of(3, "Three")))); } - @Test(expected = UnsupportedOperationException.class) + @Test public void entrySet_add() { MutableBiMap biMap = this.newMapWithKeyValue(1, "One"); Set> entries = biMap.entrySet(); - entries.add(ImmutableEntry.of(2, "Two")); + assertThrows(UnsupportedOperationException.class, () -> entries.add(ImmutableEntry.of(2, "Two"))); } - @Test(expected = UnsupportedOperationException.class) + @Test public void entrySet_addAll() { MutableBiMap biMap = this.newMapWithKeyValue(1, "One"); Set> entries = biMap.entrySet(); - entries.addAll(FastList.newListWith(ImmutableEntry.of(2, "Two"))); + assertThrows(UnsupportedOperationException.class, () -> entries.addAll(FastList.newListWith(ImmutableEntry.of(2, "Two")))); } @Test @@ -208,13 +208,13 @@ public void entrySet_equals() assertEquals(expected, biMap.entrySet()); } - @Test(expected = NoSuchElementException.class) + @Test public void entrySet_Iterator_incrementPastEnd() { MutableBiMap biMap = this.newMapWithKeyValue(1, "One"); Iterator> iterator = biMap.entrySet().iterator(); iterator.next(); - iterator.next(); + assertThrows(NoSuchElementException.class, () -> iterator.next()); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapKeySetTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapKeySetTestCase.java index b7d864eb83..efbf00c19e 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapKeySetTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapKeySetTestCase.java @@ -33,16 +33,16 @@ public abstract class AbstractMutableBiMapKeySetTestCase protected abstract MutableBiMap newMapWithKeysValues(String key1, int value1, String key2, int value2, String key3, int value3, String key4, int value4); - @Test(expected = UnsupportedOperationException.class) + @Test public void add() { - this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3).keySet().add("Four"); + assertThrows(UnsupportedOperationException.class, () -> this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3).keySet().add("Four")); } - @Test(expected = UnsupportedOperationException.class) + @Test public void addAll() { - this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3).keySet().addAll(FastList.newListWith("Four")); + assertThrows(UnsupportedOperationException.class, () -> this.newMapWithKeysValues("One", 1, "Two", 2, "Three", 3).keySet().addAll(FastList.newListWith("Four"))); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapValuesTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapValuesTestCase.java index b4c7578e09..fd866ab6b9 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapValuesTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/bimap/mutable/AbstractMutableBiMapValuesTestCase.java @@ -35,16 +35,16 @@ public abstract class AbstractMutableBiMapValuesTestCase protected abstract MutableBiMap newMapWithKeysValues(float key1, Integer value1, float key2, Integer value2, float key3, Integer value3, float key4, Integer value4); - @Test(expected = UnsupportedOperationException.class) + @Test public void add() { - this.newMapWithKeysValues(1.0f, 1, 2.0f, 2, 3.0f, 3).values().add(4); + assertThrows(UnsupportedOperationException.class, () -> this.newMapWithKeysValues(1.0f, 1, 2.0f, 2, 3.0f, 3).values().add(4)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void addAll() { - this.newMapWithKeysValues(1.0f, 1, 2.0f, 2, 3.0f, 3).values().addAll(FastList.newListWith(4)); + assertThrows(UnsupportedOperationException.class, () -> this.newMapWithKeysValues(1.0f, 1, 2.0f, 2, 3.0f, 3).values().addAll(FastList.newListWith(4))); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/collection/immutable/AbstractImmutableCollectionTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/collection/immutable/AbstractImmutableCollectionTestCase.java index ae3305add8..1f71c36241 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/collection/immutable/AbstractImmutableCollectionTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/collection/immutable/AbstractImmutableCollectionTestCase.java @@ -154,10 +154,10 @@ public void parallelStream() /** * @since 9.0 */ - @Test(expected = UnsupportedOperationException.class) + @Test public void castToCollection() { - this.classUnderTest().castToCollection().add(0); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().castToCollection().add(0)); } /** @@ -612,10 +612,10 @@ public void flatCollectWith() assertEquals(expected, actual); } - @Test(expected = IllegalArgumentException.class) + @Test public void chunk_zero_throws() { - this.classUnderTest().chunk(0); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().chunk(0)); } @Test @@ -817,21 +817,21 @@ public void forLoop() } } - private ImmutableCollection classUnderTestWithNull() + protected ImmutableCollection classUnderTestWithNull() { return this.classUnderTest().reject(Integer.valueOf(1)::equals).newWith(null); } - @Test(expected = NullPointerException.class) + @Test public void min_null_throws() { - this.classUnderTestWithNull().min(Integer::compareTo); + assertThrows(NullPointerException.class, () -> this.classUnderTestWithNull().min(Integer::compareTo)); } - @Test(expected = NullPointerException.class) + @Test public void max_null_throws() { - this.classUnderTestWithNull().max(Integer::compareTo); + assertThrows(NullPointerException.class, () -> this.classUnderTestWithNull().max(Integer::compareTo)); } @Test @@ -846,16 +846,16 @@ public void max() assertEquals(Integer.valueOf(1), this.classUnderTest().max(Comparators.reverse(Integer::compareTo))); } - @Test(expected = NullPointerException.class) + @Test public void min_null_throws_without_comparator() { - this.classUnderTestWithNull().min(); + assertThrows(NullPointerException.class, () -> this.classUnderTestWithNull().min()); } - @Test(expected = NullPointerException.class) + @Test public void max_null_throws_without_comparator() { - this.classUnderTestWithNull().max(); + assertThrows(NullPointerException.class, () -> this.classUnderTestWithNull().max()); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/AbstractLazyIterableTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/AbstractLazyIterableTestCase.java index 89a5ededb2..48cc964191 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/AbstractLazyIterableTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/AbstractLazyIterableTestCase.java @@ -76,6 +76,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; public abstract class AbstractLazyIterableTestCase @@ -360,10 +361,10 @@ public void take() assertEquals(FastList.newListWith(1, 2, 3, 4, 5, 6, 7), lazyIterable.take(Integer.MAX_VALUE).toList()); } - @Test(expected = IllegalArgumentException.class) + @Test public void take_negative_throws() { - this.lazyIterable.take(-1); + assertThrows(IllegalArgumentException.class, () -> this.lazyIterable.take(-1)); } @Test @@ -378,10 +379,10 @@ public void drop() assertEquals(FastList.newList(), lazyIterable.drop(Integer.MAX_VALUE).toList()); } - @Test(expected = IllegalArgumentException.class) + @Test public void drop_negative_throws() { - this.lazyIterable.drop(-1); + assertThrows(IllegalArgumentException.class, () -> this.lazyIterable.drop(-1)); } @Test @@ -396,10 +397,10 @@ public void takeWhile() assertEquals(FastList.newListWith(1, 2, 3, 4, 5, 6, 7), lazyIterable.takeWhile(Predicates.alwaysTrue()).toList()); } - @Test(expected = IllegalStateException.class) + @Test public void takeWhile_null_throws() { - this.lazyIterable.takeWhile(null); + assertThrows(IllegalStateException.class, () -> this.lazyIterable.takeWhile(null)); } @Test @@ -413,10 +414,10 @@ public void dropWhile() assertEquals(FastList.newList(), lazyIterable.dropWhile(Predicates.alwaysTrue()).toList()); } - @Test(expected = IllegalStateException.class) + @Test public void dropWhile_null_throws() { - this.lazyIterable.dropWhile(null); + assertThrows(IllegalStateException.class, () -> this.lazyIterable.dropWhile(null)); } @Test @@ -455,28 +456,28 @@ public void detectWithIfNone() assertEquals(Integer.valueOf(1000), this.lazyIterable.detectWithIfNone(Object::equals, Integer.valueOf(8), function)); } - @Test(expected = NoSuchElementException.class) + @Test public void min_empty_throws() { - this.newWith().min(Integer::compareTo); + assertThrows(NoSuchElementException.class, () -> this.newWith().min(Integer::compareTo)); } - @Test(expected = NoSuchElementException.class) + @Test public void max_empty_throws() { - this.newWith().max(Integer::compareTo); + assertThrows(NoSuchElementException.class, () -> this.newWith().max(Integer::compareTo)); } - @Test(expected = NullPointerException.class) + @Test public void min_null_throws() { - this.newWith(1, null, 2).min(Integer::compareTo); + assertThrows(NullPointerException.class, () -> this.newWith(1, null, 2).min(Integer::compareTo)); } - @Test(expected = NullPointerException.class) + @Test public void max_null_throws() { - this.newWith(1, null, 2).max(Integer::compareTo); + assertThrows(NullPointerException.class, () -> this.newWith(1, null, 2).max(Integer::compareTo)); } @Test @@ -503,28 +504,28 @@ public void maxBy() assertEquals(Integer.valueOf(3), this.newWith(1, 3, 2).maxBy(String::valueOf)); } - @Test(expected = NoSuchElementException.class) + @Test public void min_empty_throws_without_comparator() { - this.newWith().min(); + assertThrows(NoSuchElementException.class, () -> this.newWith().min()); } - @Test(expected = NoSuchElementException.class) + @Test public void max_empty_throws_without_comparator() { - this.newWith().max(); + assertThrows(NoSuchElementException.class, () -> this.newWith().max()); } - @Test(expected = NullPointerException.class) + @Test public void min_null_throws_without_comparator() { - this.newWith(1, null, 2).min(); + assertThrows(NullPointerException.class, () -> this.newWith(1, null, 2).min()); } - @Test(expected = NullPointerException.class) + @Test public void max_null_throws_without_comparator() { - this.newWith(1, null, 2).max(); + assertThrows(NullPointerException.class, () -> this.newWith(1, null, 2).max()); } @Test @@ -636,16 +637,16 @@ public void getOnly() assertEquals(Integer.valueOf(1), this.newWith(1).getOnly()); } - @Test(expected = IllegalStateException.class) + @Test public void getOnly_throws_when_empty() { - this.newWith().getOnly(); + assertThrows(IllegalStateException.class, () -> this.newWith().getOnly()); } - @Test(expected = IllegalStateException.class) + @Test public void getOnly_throws_when_multiple_values() { - this.newWith(1, 2, 3).getOnly(); + assertThrows(IllegalStateException.class, () -> this.newWith(1, 2, 3).getOnly()); } @Test @@ -827,10 +828,10 @@ public void groupByUniqueKey() assertEquals(UnifiedMap.newWithKeysValues(1, 1, 2, 2, 3, 3), this.newWith(1, 2, 3).groupByUniqueKey(id -> id)); } - @Test(expected = IllegalStateException.class) + @Test public void groupByUniqueKey_throws() { - this.newWith(1, 2, 3).groupByUniqueKey(Functions.getFixedValue(1)); + assertThrows(IllegalStateException.class, () -> this.newWith(1, 2, 3).groupByUniqueKey(Functions.getFixedValue(1))); } @Test @@ -840,10 +841,10 @@ public void groupByUniqueKey_target() assertEquals(UnifiedMap.newWithKeysValues(0, 0, 1, 1, 2, 2, 3, 3), integers); } - @Test(expected = IllegalStateException.class) + @Test public void groupByUniqueKey_target_throws() { - this.newWith(1, 2, 3).groupByUniqueKey(id -> id, UnifiedMap.newWithKeysValues(2, 2)); + assertThrows(IllegalStateException.class, () -> this.newWith(1, 2, 3).groupByUniqueKey(id -> id, UnifiedMap.newWithKeysValues(2, 2))); } @Test @@ -901,10 +902,10 @@ public void chunk() assertEquals(Bags.mutable.of(2, 2, 2, 1), sizes.toBag()); } - @Test(expected = IllegalArgumentException.class) + @Test public void chunk_zero_throws() { - this.lazyIterable.chunk(0); + assertThrows(IllegalArgumentException.class, () -> this.lazyIterable.chunk(0)); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/SelectInstancesOfIterableTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/SelectInstancesOfIterableTest.java index 34547d7181..0c5f33a07f 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/SelectInstancesOfIterableTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/SelectInstancesOfIterableTest.java @@ -82,7 +82,6 @@ public void forEachWith() public void min_null_throws() { // Impossible for SelectInstancesOfIterable to contain null - super.min_null_throws(); } @Override @@ -90,7 +89,6 @@ public void min_null_throws() public void max_null_throws() { // Impossible for SelectInstancesOfIterable to contain null - super.max_null_throws(); } @Override @@ -98,7 +96,6 @@ public void max_null_throws() public void min_null_throws_without_comparator() { // Impossible for SelectInstancesOfIterable to contain null - super.min_null_throws_without_comparator(); } @Override @@ -106,7 +103,6 @@ public void min_null_throws_without_comparator() public void max_null_throws_without_comparator() { // Impossible for SelectInstancesOfIterable to contain null - super.max_null_throws_without_comparator(); } @Override diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/iterator/FlatCollectIteratorTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/iterator/FlatCollectIteratorTest.java index cb68e8a832..b50135c8bf 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/iterator/FlatCollectIteratorTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/lazy/iterator/FlatCollectIteratorTest.java @@ -18,19 +18,20 @@ import org.junit.Test; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; public class FlatCollectIteratorTest { - @Test(expected = NoSuchElementException.class) + @Test public void nextIfDoesntHaveAnything() { - new FlatCollectIterator<>(Lists.immutable.of(), object -> null).next(); + assertThrows(NoSuchElementException.class, () -> new FlatCollectIterator<>(Lists.immutable.of(), object -> null).next()); } - @Test(expected = UnsupportedOperationException.class) + @Test public void removeIsUnsupported() { - new FlatCollectIterator<>(Lists.immutable.of().iterator(), object -> null).remove(); + assertThrows(UnsupportedOperationException.class, () -> new FlatCollectIterator<>(Lists.immutable.of().iterator(), object -> null).remove()); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableArrayListTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableArrayListTest.java index 58fb70f9b6..36c2cf26b2 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableArrayListTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableArrayListTest.java @@ -170,18 +170,18 @@ public void serialization() Verify.assertEqualsAndHashCode(collection, deserializedCollection); } - @Test(expected = IndexOutOfBoundsException.class) + @Test public void forEachWithIndexIllegalFrom() { MutableList result = Lists.mutable.of(); - this.newList(1, 2).forEachWithIndex(-1, 2, new AddToList(result)); + assertThrows(IndexOutOfBoundsException.class, () -> this.newList(1, 2).forEachWithIndex(-1, 2, new AddToList(result))); } - @Test(expected = IndexOutOfBoundsException.class) + @Test public void forEachWithIndexIllegalTo() { MutableList result = Lists.mutable.of(); - this.newList(1, 2).forEachWithIndex(1, -2, new AddToList(result)); + assertThrows(IndexOutOfBoundsException.class, () -> this.newList(1, 2).forEachWithIndex(1, -2, new AddToList(result))); } @Test @@ -216,10 +216,10 @@ public void groupByUniqueKey() this.classUnderTest().groupByUniqueKey(id -> id)); } - @Test(expected = IllegalStateException.class) + @Test public void groupByUniqueKey_throws() { - this.classUnderTest().groupByUniqueKey(Functions.getFixedValue(1)); + assertThrows(IllegalStateException.class, () -> this.classUnderTest().groupByUniqueKey(Functions.getFixedValue(1))); } @Test @@ -230,10 +230,10 @@ public void groupByUniqueKey_target() assertEquals(UnifiedMap.newWithKeysValues(0, 0, 1, 1, 2, 2, 3, 3), integers); } - @Test(expected = IllegalStateException.class) + @Test public void groupByUniqueKey_target_throws() { - this.classUnderTest().groupByUniqueKey(id -> id, UnifiedMap.newWithKeysValues(2, 2)); + assertThrows(IllegalStateException.class, () -> this.classUnderTest().groupByUniqueKey(id -> id, UnifiedMap.newWithKeysValues(2, 2))); } @Test @@ -243,17 +243,17 @@ public void getOnly() assertEquals(Integer.valueOf(2), list.getOnly()); } - @Test(expected = IllegalStateException.class) + @Test public void getOnly_exception_when_empty() { ImmutableList list = this.newList(); - list.getOnly(); + assertThrows(IllegalStateException.class, () -> list.getOnly()); } - @Test(expected = IllegalStateException.class) + @Test public void getOnly_exception_when_multiple_items() { ImmutableList list = this.newList(1, 2, 3); - list.getOnly(); + assertThrows(IllegalStateException.class, () -> list.getOnly()); } } diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableEmptyListTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableEmptyListTest.java index 64a24f2446..6855c2eeea 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableEmptyListTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableEmptyListTest.java @@ -229,11 +229,11 @@ public void getLast() assertNull(integers.getLast()); } - @Test(expected = IllegalStateException.class) + @Test public void getOnly() { ImmutableList list = this.classUnderTest(); - list.getOnly(); + assertThrows(IllegalStateException.class, () -> list.getOnly()); } @Override @@ -246,17 +246,17 @@ public void isEmpty() } @Override - @Test(expected = NoSuchElementException.class) + @Test public void min() { - this.classUnderTest().min(Integer::compareTo); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().min(Integer::compareTo)); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void max() { - this.classUnderTest().max(Integer::compareTo); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().max(Integer::compareTo)); } @Test @@ -264,7 +264,6 @@ public void max() public void min_null_throws() { // Not applicable for empty collections - super.min_null_throws(); } @Test @@ -272,21 +271,20 @@ public void min_null_throws() public void max_null_throws() { // Not applicable for empty collections - super.max_null_throws(); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void min_without_comparator() { - this.classUnderTest().min(); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().min()); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void max_without_comparator() { - this.classUnderTest().max(); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().max()); } @Test @@ -294,7 +292,6 @@ public void max_without_comparator() public void min_null_throws_without_comparator() { // Not applicable for empty collections - super.min_null_throws_without_comparator(); } @Test @@ -302,28 +299,27 @@ public void min_null_throws_without_comparator() public void max_null_throws_without_comparator() { // Not applicable for empty collections - super.max_null_throws_without_comparator(); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void minBy() { - this.classUnderTest().minBy(String::valueOf); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().minBy(String::valueOf)); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void maxBy() { - this.classUnderTest().maxBy(String::valueOf); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().maxBy(String::valueOf)); } @Override - @Test(expected = IndexOutOfBoundsException.class) + @Test public void subList() { - this.classUnderTest().subList(0, 1); + assertThrows(IndexOutOfBoundsException.class, () -> this.classUnderTest().subList(0, 1)); } @Override @@ -365,10 +361,10 @@ public void chunk() } @Override - @Test(expected = IllegalArgumentException.class) + @Test public void chunk_zero_throws() { - this.classUnderTest().chunk(0); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().chunk(0)); } @Override diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableSingletonListTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableSingletonListTest.java index 18f4c1c3d7..cffb3a89c2 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableSingletonListTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/list/immutable/ImmutableSingletonListTest.java @@ -14,6 +14,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; public class ImmutableSingletonListTest extends AbstractImmutableListTestCase { @@ -28,7 +29,7 @@ protected ImmutableList classUnderTest() public void min_null_throws() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.min_null_throws(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().min(Integer::compareTo)); } @Test @@ -36,7 +37,7 @@ public void min_null_throws() public void max_null_throws() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.max_null_throws(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().max(Integer::compareTo)); } @Test @@ -44,7 +45,7 @@ public void max_null_throws() public void min_null_throws_without_comparator() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.min_null_throws_without_comparator(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().min()); } @Test @@ -52,7 +53,7 @@ public void min_null_throws_without_comparator() public void max_null_throws_without_comparator() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.max_null_throws_without_comparator(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().max()); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/list/mutable/FastListTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/list/mutable/FastListTest.java index 44309b7eed..3df57d7a38 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/list/mutable/FastListTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/list/mutable/FastListTest.java @@ -1223,21 +1223,21 @@ public void unoptimizedListToImmutable() Verify.assertIterablesEqual(immutableList, list); } - @Test(expected = NoSuchElementException.class) + @Test public void min_empty_throws_without_comparator() { - this.newWith().min(); + assertThrows(NoSuchElementException.class, () -> this.newWith().min()); } - @Test(expected = NoSuchElementException.class) + @Test public void max_empty_throws_without_comparator() { - this.newWith().max(); + assertThrows(NoSuchElementException.class, () -> this.newWith().max()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testNegativeInitialCapacity() { - new FastList<>(-1); + assertThrows(IllegalArgumentException.class, () -> new FastList<>(-1)); } } diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/map/fixed/AbstractMemoryEfficientMutableMapTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/map/fixed/AbstractMemoryEfficientMutableMapTest.java index 2eec8c553b..fcffa2c2ca 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/map/fixed/AbstractMemoryEfficientMutableMapTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/map/fixed/AbstractMemoryEfficientMutableMapTest.java @@ -61,6 +61,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -75,64 +76,64 @@ public abstract class AbstractMemoryEfficientMutableMapTest public abstract void containsValue(); - @Test(expected = UnsupportedOperationException.class) + @Test public void put_throws() { - this.classUnderTest().put(null, null); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().put(null, null)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void remove_throws() { - this.classUnderTest().remove(null); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().remove(null)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void putAll_throws() { - this.classUnderTest().putAll(null); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().putAll(null)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void clear_throws() { - this.classUnderTest().clear(); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().clear()); } - @Test(expected = UnsupportedOperationException.class) + @Test public void removeKey_throws() { - this.classUnderTest().removeKey(null); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().removeKey(null)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void removeAllKeys_throws() { - this.classUnderTest().removeAllKeys(null); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().removeAllKeys(null)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void removeIf_throws() { - this.classUnderTest().removeIf(null); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().removeIf(null)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void collectKeysAndValues_throws() { - this.classUnderTest().collectKeysAndValues(null, null, null); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().collectKeysAndValues(null, null, null)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void updateValue() { - this.classUnderTest().updateValue("1", () -> "", object -> object + object); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().updateValue("1", () -> "", object -> object + object)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void updateValueWith() { - this.classUnderTest().updateValueWith("1", () -> "", String::concat, "!"); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().updateValueWith("1", () -> "", String::concat, "!")); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/map/mutable/primitive/AbstractObjectBooleanMapKeyValuesViewTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/map/mutable/primitive/AbstractObjectBooleanMapKeyValuesViewTestCase.java index 25a37ee98d..64b609b6ed 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/map/mutable/primitive/AbstractObjectBooleanMapKeyValuesViewTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/map/mutable/primitive/AbstractObjectBooleanMapKeyValuesViewTestCase.java @@ -236,16 +236,16 @@ public void detect() assertNull(this.newWith(1, true, 2, false, 3, true).detect(PrimitiveTuples.pair(true, Integer.valueOf(4))::equals)); } - @Test(expected = NoSuchElementException.class) + @Test public void min_empty_throws() { - this.newWith().min(ObjectBooleanPair::compareTo); + assertThrows(NoSuchElementException.class, () -> this.newWith().min(ObjectBooleanPair::compareTo)); } - @Test(expected = NoSuchElementException.class) + @Test public void max_empty_throws() { - this.newWith().max(ObjectBooleanPair::compareTo); + assertThrows(NoSuchElementException.class, () -> this.newWith().max(ObjectBooleanPair::compareTo)); } @Test @@ -450,7 +450,7 @@ public void iterator() assertEquals(objects.toBag(), actual); } - @Test(expected = NoSuchElementException.class) + @Test public void iterator_throws() { RichIterable> objects = this.newWith(1, true, 2, false, 3, true); @@ -461,7 +461,7 @@ public void iterator_throws() iterator.next(); } assertFalse(iterator.hasNext()); - iterator.next(); + assertThrows(NoSuchElementException.class, iterator::next); } @Test @@ -806,11 +806,11 @@ public void chunk() collection.chunk(1).toBag()); } - @Test(expected = IllegalArgumentException.class) + @Test public void chunk_zero_throws() { RichIterable> collection = this.newWith(1, true, 2, false, 3, true); - collection.chunk(0); + assertThrows(IllegalArgumentException.class, () -> collection.chunk(0)); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/multimap/AbstractMutableMultimapTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/multimap/AbstractMutableMultimapTestCase.java index e7217b5211..7a715b3eca 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/multimap/AbstractMutableMultimapTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/multimap/AbstractMutableMultimapTestCase.java @@ -153,10 +153,10 @@ public void withKeyMultiValues() assertEquals(expected, multimap); } - @Test (expected = NullPointerException.class) + @Test public void withKeyMultiValuesNullValueHandling() { - this.newMultimap().withKeyMultiValues(1, null); + assertThrows(NullPointerException.class, () -> this.newMultimap().withKeyMultiValues(1, null)); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/AbstractMemoryEfficientMutableSetTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/AbstractMemoryEfficientMutableSetTestCase.java index 3606991c9a..c9febe983c 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/AbstractMemoryEfficientMutableSetTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/AbstractMemoryEfficientMutableSetTestCase.java @@ -67,88 +67,88 @@ public void asSynchronized() Verify.assertInstanceOf(SynchronizedMutableSet.class, this.classUnderTest().asSynchronized()); } - @Test(expected = UnsupportedOperationException.class) + @Test public void remove_throws() { MutableSet set = this.classUnderTest(); - set.remove("1"); + assertThrows(UnsupportedOperationException.class, () -> set.remove("1")); } - @Test(expected = UnsupportedOperationException.class) + @Test public void addAll_throws() { MutableSet set = this.classUnderTest(); - set.addAll(null); + assertThrows(UnsupportedOperationException.class, () -> set.addAll(null)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void addAllIterable_throws() { MutableSet set = this.classUnderTest(); - set.addAllIterable(null); + assertThrows(UnsupportedOperationException.class, () -> set.addAllIterable(null)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void add_duplicate_throws() { MutableSet set = this.classUnderTest(); - set.add("1"); + assertThrows(UnsupportedOperationException.class, () -> set.add("1")); } - @Test(expected = UnsupportedOperationException.class) + @Test public void add_throws() { MutableSet set = this.classUnderTest(); - set.add(null); + assertThrows(UnsupportedOperationException.class, () -> set.add(null)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void removeAll_throws() { MutableSet set = this.classUnderTest(); - set.removeAll(mList("1", "2")); + assertThrows(UnsupportedOperationException.class, () -> set.removeAll(mList("1", "2"))); } - @Test(expected = UnsupportedOperationException.class) + @Test public void removeAllIterable_throws() { MutableSet set = this.classUnderTest(); - set.removeAllIterable(mList("1", "2")); + assertThrows(UnsupportedOperationException.class, () -> set.removeAllIterable(mList("1", "2"))); } - @Test(expected = UnsupportedOperationException.class) + @Test public void retainAll_throws() { MutableSet set = this.classUnderTest(); - set.retainAll(mList("1", "2")); + assertThrows(UnsupportedOperationException.class, () -> set.retainAll(mList("1", "2"))); } - @Test(expected = UnsupportedOperationException.class) + @Test public void retainAllIterable_throws() { MutableSet set = this.classUnderTest(); - set.retainAllIterable(mList("1", "2")); + assertThrows(UnsupportedOperationException.class, () -> set.retainAllIterable(mList("1", "2"))); } - @Test(expected = UnsupportedOperationException.class) + @Test public void clear_throws() { MutableSet set = this.classUnderTest(); - set.clear(); + assertThrows(UnsupportedOperationException.class, () -> set.clear()); } - @Test(expected = UnsupportedOperationException.class) + @Test public void removeIf_throws() { MutableSet set = this.classUnderTest(); - set.removeIf(Predicates.equal("1")); + assertThrows(UnsupportedOperationException.class, () -> set.removeIf(Predicates.equal("1"))); } - @Test(expected = UnsupportedOperationException.class) + @Test public void removeIfWith_throws() { MutableSet set = this.classUnderTest(); - set.removeIfWith(Object::equals, "1"); + assertThrows(UnsupportedOperationException.class, () -> set.removeIfWith(Object::equals, "1")); } @Test @@ -167,35 +167,35 @@ public void iterator() assertThrows(NoSuchElementException.class, iterator::next); } - @Test(expected = UnsupportedOperationException.class) + @Test public void iteratorRemove_throws() { MutableSet set = this.classUnderTest(); - set.iterator().remove(); + assertThrows(UnsupportedOperationException.class, () -> set.iterator().remove()); } - @Test(expected = NullPointerException.class) + @Test public void min_null_throws() { - this.classUnderTestWithNull().min(String::compareTo); + assertThrows(NullPointerException.class, () -> this.classUnderTestWithNull().min(String::compareTo)); } - @Test(expected = NullPointerException.class) + @Test public void max_null_throws() { - this.classUnderTestWithNull().max(String::compareTo); + assertThrows(NullPointerException.class, () -> this.classUnderTestWithNull().max(String::compareTo)); } - @Test(expected = NullPointerException.class) + @Test public void min_null_throws_without_comparator() { - this.classUnderTestWithNull().min(); + assertThrows(NullPointerException.class, () -> this.classUnderTestWithNull().min()); } - @Test(expected = NullPointerException.class) + @Test public void max_null_throws_without_comparator() { - this.classUnderTestWithNull().max(); + assertThrows(NullPointerException.class, () -> this.classUnderTestWithNull().max()); } protected abstract MutableSet classUnderTestWithNull(); @@ -210,14 +210,15 @@ public void iterationWithIterator() } } - @Test(expected = NoSuchElementException.class) + @Test public void iteratorWillGetUpsetIfYouPushItTooFar() { Iterator iterator = this.classUnderTest().iterator(); - for (int i = 0; i < this.classUnderTest().size() + 1; i++) + for (int i = 0; i < this.classUnderTest().size(); i++) { iterator.next(); } + assertThrows(NoSuchElementException.class, iterator::next); } @Test @@ -372,10 +373,10 @@ public void chunk() assertEquals(hashBag, sizes.toBag()); } - @Test(expected = IllegalArgumentException.class) + @Test public void chunk_zero_throws() { - this.classUnderTest().chunk(0); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().chunk(0)); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/EmptySetTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/EmptySetTest.java index 8b7ee7c33f..b77b2f8efe 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/EmptySetTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/EmptySetTest.java @@ -139,18 +139,18 @@ public void groupBy() assertEquals(this.classUnderTest(), multimap.get(String.class)); } - @Test(expected = NoSuchElementException.class) + @Test @Override public void min() { - this.classUnderTest().min(String::compareTo); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().min(String::compareTo)); } - @Test(expected = NoSuchElementException.class) + @Test @Override public void max() { - this.classUnderTest().max(String::compareTo); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().max(String::compareTo)); } @Test @@ -167,18 +167,18 @@ public void max_null_throws() // Not applicable for empty collections } - @Test(expected = NoSuchElementException.class) + @Test @Override public void min_without_comparator() { - this.classUnderTest().min(); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().min()); } - @Test(expected = NoSuchElementException.class) + @Test @Override public void max_without_comparator() { - this.classUnderTest().max(); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().max()); } @Test @@ -196,17 +196,17 @@ public void max_null_throws_without_comparator() } @Override - @Test(expected = NoSuchElementException.class) + @Test public void minBy() { - this.classUnderTest().minBy(String::valueOf); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().minBy(String::valueOf)); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void maxBy() { - this.classUnderTest().maxBy(String::valueOf); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().maxBy(String::valueOf)); } @Override diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/SingletonSetTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/SingletonSetTest.java index fddc5d0550..1780144f75 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/SingletonSetTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/set/fixed/SingletonSetTest.java @@ -46,6 +46,7 @@ import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; /** * JUnit test for {@link SingletonSet}. @@ -558,7 +559,7 @@ public void newEmpty() public void min_null_throws() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.min_null_throws(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().min(String::compareTo)); } @Test @@ -566,7 +567,7 @@ public void min_null_throws() public void max_null_throws() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.max_null_throws(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().max(String::compareTo)); } @Test @@ -574,7 +575,7 @@ public void max_null_throws() public void min_null_throws_without_comparator() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.min_null_throws_without_comparator(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().min()); } @Test @@ -582,6 +583,6 @@ public void min_null_throws_without_comparator() public void max_null_throws_without_comparator() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.max_null_throws_without_comparator(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().max()); } } diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/AbstractImmutableEmptySetTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/AbstractImmutableEmptySetTestCase.java index 9ca6da26ab..f1901c3889 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/AbstractImmutableEmptySetTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/AbstractImmutableEmptySetTestCase.java @@ -144,17 +144,17 @@ public void isEmpty() } @Override - @Test(expected = NoSuchElementException.class) + @Test public void min() { - this.classUnderTest().min(Integer::compareTo); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().min(Integer::compareTo)); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void max() { - this.classUnderTest().max(Integer::compareTo); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().max(Integer::compareTo)); } @Test @@ -162,7 +162,6 @@ public void max() public void min_null_throws() { // Not applicable for empty collections - super.min_null_throws(); } @Test @@ -170,21 +169,20 @@ public void min_null_throws() public void max_null_throws() { // Not applicable for empty collections - super.max_null_throws(); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void min_without_comparator() { - this.classUnderTest().min(); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().min()); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void max_without_comparator() { - this.classUnderTest().max(); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().max()); } @Test @@ -192,7 +190,6 @@ public void max_without_comparator() public void min_null_throws_without_comparator() { // Not applicable for empty collections - super.min_null_throws_without_comparator(); } @Test @@ -200,21 +197,20 @@ public void min_null_throws_without_comparator() public void max_null_throws_without_comparator() { // Not applicable for empty collections - super.max_null_throws_without_comparator(); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void minBy() { - this.classUnderTest().minBy(String::valueOf); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().minBy(String::valueOf)); } @Override - @Test(expected = NoSuchElementException.class) + @Test public void maxBy() { - this.classUnderTest().maxBy(String::valueOf); + assertThrows(NoSuchElementException.class, () -> this.classUnderTest().maxBy(String::valueOf)); } @Override @@ -260,10 +256,10 @@ public void chunk() } @Override - @Test(expected = IllegalArgumentException.class) + @Test public void chunk_zero_throws() { - this.classUnderTest().chunk(0); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().chunk(0)); } @Override diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/AbstractImmutableUnifiedSetTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/AbstractImmutableUnifiedSetTestCase.java index d8904d00b7..eff8e995c6 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/AbstractImmutableUnifiedSetTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/AbstractImmutableUnifiedSetTestCase.java @@ -43,6 +43,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; public abstract class AbstractImmutableUnifiedSetTestCase @@ -245,16 +246,16 @@ public void getOnly() assertEquals(Integer.valueOf(1), this.newSetWith(1).getOnly()); } - @Test(expected = IllegalStateException.class) + @Test public void getOnly_throws_when_empty() { - this.newSet().getOnly(); + assertThrows(IllegalStateException.class, () -> this.newSet().getOnly()); } - @Test(expected = IllegalStateException.class) + @Test public void getOnly_throws_when_multiple_values() { - this.newSetWith(1, 2, 3).getOnly(); + assertThrows(IllegalStateException.class, () -> this.newSetWith(1, 2, 3).getOnly()); } @Test @@ -483,10 +484,10 @@ public void groupByUniqueKey() assertEquals(UnifiedMap.newWithKeysValues(1, 1, 2, 2, 3, 3), this.newSetWith(1, 2, 3).groupByUniqueKey(id -> id)); } - @Test(expected = IllegalStateException.class) + @Test public void groupByUniqueKey_throws() { - this.newSetWith(1, 2, 3).groupByUniqueKey(Functions.getFixedValue(1)); + assertThrows(IllegalStateException.class, () -> this.newSetWith(1, 2, 3).groupByUniqueKey(Functions.getFixedValue(1))); } @Test @@ -496,9 +497,9 @@ public void groupByUniqueKey_target() assertEquals(UnifiedMap.newWithKeysValues(0, 0, 1, 1, 2, 2, 3, 3), integers); } - @Test(expected = IllegalStateException.class) + @Test public void groupByUniqueKey_target_throws() { - this.newSetWith(1, 2, 3).groupByUniqueKey(id -> id, UnifiedMap.newWithKeysValues(2, 2)); + assertThrows(IllegalStateException.class, () -> this.newSetWith(1, 2, 3).groupByUniqueKey(id -> id, UnifiedMap.newWithKeysValues(2, 2))); } } diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/ImmutableSingletonSetTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/ImmutableSingletonSetTest.java index 589b87ae9f..1799500b81 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/ImmutableSingletonSetTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/ImmutableSingletonSetTest.java @@ -15,6 +15,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; public class ImmutableSingletonSetTest extends AbstractImmutableSetTestCase @@ -30,7 +31,7 @@ protected ImmutableSet classUnderTest() public void min_null_throws() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.min_null_throws(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().min(Integer::compareTo)); } @Test @@ -38,7 +39,7 @@ public void min_null_throws() public void max_null_throws() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.max_null_throws(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().max(Integer::compareTo)); } @Test @@ -46,7 +47,7 @@ public void max_null_throws() public void min_null_throws_without_comparator() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.min_null_throws_without_comparator(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().min()); } @Test @@ -54,7 +55,7 @@ public void min_null_throws_without_comparator() public void max_null_throws_without_comparator() { // Collections with one element should not throw to emulate the JDK Collections behavior - super.max_null_throws_without_comparator(); + assertDoesNotThrow(() -> this.classUnderTestWithNull().max()); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/primitive/AbstractImmutableByteHashSetTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/primitive/AbstractImmutableByteHashSetTestCase.java index a605b6a5e4..f3a4613585 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/primitive/AbstractImmutableByteHashSetTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/set/immutable/primitive/AbstractImmutableByteHashSetTestCase.java @@ -108,7 +108,7 @@ public void byteIterator() } @Override - @Test(expected = NoSuchElementException.class) + @Test public void byteIterator_throws() { ImmutableByteSet set = this.newWith((byte) 0, (byte) 1, (byte) 31); @@ -117,8 +117,7 @@ public void byteIterator_throws() { iterator.next(); } - - iterator.next(); + assertThrows(NoSuchElementException.class, iterator::next); } @Override diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/set/mutable/AbstractMutableSetTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/set/mutable/AbstractMutableSetTestCase.java index 70e14945ed..010b42a95e 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/set/mutable/AbstractMutableSetTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/set/mutable/AbstractMutableSetTestCase.java @@ -50,6 +50,7 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; /** @@ -830,20 +831,19 @@ public void detect() } } - @Test(expected = NoSuchElementException.class) + @Test public void iterator_increment_past_end() { MutableSet set = this.newWith(); Iterator iterator = set.iterator(); - iterator.next(); - iterator.next(); + assertThrows(NoSuchElementException.class, iterator::next); } - @Test(expected = IllegalStateException.class) + @Test public void iterator_remove_without_next() { Iterator iterator = this.newWith().iterator(); - iterator.remove(); + assertThrows(IllegalStateException.class, () -> iterator.remove()); } @Override @@ -889,10 +889,10 @@ public void toImmutableSortedBag_with_comparator() } @Override - @Test(expected = NullPointerException.class) + @Test public void toSortedBag_with_null() { - this.newWith(3, 4, null, 1, 2).toSortedBag(); + assertThrows(NullPointerException.class, () -> this.newWith(3, 4, null, 1, 2).toSortedBag()); } @Override diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/set/sorted/immutable/AbstractImmutableSortedSetTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/set/sorted/immutable/AbstractImmutableSortedSetTestCase.java index 9b609c1710..3de8d9801f 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/set/sorted/immutable/AbstractImmutableSortedSetTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/set/sorted/immutable/AbstractImmutableSortedSetTestCase.java @@ -71,10 +71,10 @@ public abstract class AbstractImmutableSortedSetTestCase protected abstract ImmutableSortedSet classUnderTest(Comparator comparator); - @Test(expected = NullPointerException.class) + @Test public void noSupportForNull() { - this.classUnderTest().newWith(null); + assertThrows(NullPointerException.class, () -> this.classUnderTest().newWith(null)); } @Test @@ -509,10 +509,10 @@ public void zipWithIndex() pairs.collect((Function, Integer>) Pair::getOne).toList()); } - @Test(expected = IllegalArgumentException.class) + @Test public void chunk_zero_throws() { - this.classUnderTest().chunk(0); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().chunk(0)); } @Test @@ -793,46 +793,46 @@ public void forLoop() } } - @Test(expected = UnsupportedOperationException.class) + @Test public void iteratorRemove() { - this.classUnderTest().iterator().remove(); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().iterator().remove()); } - @Test(expected = UnsupportedOperationException.class) + @Test public void add() { - this.classUnderTest().castToSortedSet().add(1); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().castToSortedSet().add(1)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void remove() { - this.classUnderTest().castToSortedSet().remove(Integer.valueOf(1)); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().castToSortedSet().remove(Integer.valueOf(1))); } - @Test(expected = UnsupportedOperationException.class) + @Test public void clear() { - this.classUnderTest().castToSortedSet().clear(); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().castToSortedSet().clear()); } - @Test(expected = UnsupportedOperationException.class) + @Test public void removeAll() { - this.classUnderTest().castToSortedSet().removeAll(Lists.fixedSize.of()); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().castToSortedSet().removeAll(Lists.fixedSize.of())); } - @Test(expected = UnsupportedOperationException.class) + @Test public void retainAll() { - this.classUnderTest().castToSortedSet().retainAll(Lists.fixedSize.of()); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().castToSortedSet().retainAll(Lists.fixedSize.of())); } - @Test(expected = UnsupportedOperationException.class) + @Test public void addAll() { - this.classUnderTest().castToSortedSet().addAll(Lists.fixedSize.of()); + assertThrows(UnsupportedOperationException.class, () -> this.classUnderTest().castToSortedSet().addAll(Lists.fixedSize.of())); } @Test @@ -917,10 +917,10 @@ public void groupByUniqueKey() this.classUnderTest().groupByUniqueKey(id -> id)); } - @Test(expected = IllegalStateException.class) + @Test public void groupByUniqueKey_throws() { - this.classUnderTest(Collections.reverseOrder()).groupByUniqueKey(Functions.getFixedValue(1)); + assertThrows(IllegalStateException.class, () -> this.classUnderTest(Collections.reverseOrder()).groupByUniqueKey(Functions.getFixedValue(1))); } @Test @@ -929,10 +929,10 @@ public void groupByUniqueKey_target() assertEquals(this.classUnderTest().groupByUniqueKey(id -> id), this.classUnderTest().groupByUniqueKey(id -> id, UnifiedMap.newMap())); } - @Test(expected = IllegalStateException.class) + @Test public void groupByUniqueKey_target_throws() { - this.classUnderTest(Collections.reverseOrder()).groupByUniqueKey(id -> id, UnifiedMap.newWithKeysValues(2, 2)); + assertThrows(IllegalStateException.class, () -> this.classUnderTest(Collections.reverseOrder()).groupByUniqueKey(id -> id, UnifiedMap.newWithKeysValues(2, 2))); } @Test @@ -1138,10 +1138,10 @@ public void take() assertSame(integers2, integers2.take(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void take_throws() { - this.classUnderTest().take(-1); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().take(-1)); } @Test @@ -1161,10 +1161,10 @@ public void drop() assertEquals(expectedSet, integers2.drop(Integer.MAX_VALUE)); } - @Test(expected = IllegalArgumentException.class) + @Test public void drop_throws() { - this.classUnderTest().drop(-1); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().drop(-1)); } @Test diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/set/sorted/immutable/ImmutableEmptySortedSetTest.java b/unit-tests/src/test/java/org/eclipse/collections/impl/set/sorted/immutable/ImmutableEmptySortedSetTest.java index 30a8ef3eb1..8ec2b9b474 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/set/sorted/immutable/ImmutableEmptySortedSetTest.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/set/sorted/immutable/ImmutableEmptySortedSetTest.java @@ -42,7 +42,6 @@ import org.eclipse.collections.impl.list.mutable.primitive.IntArrayList; import org.eclipse.collections.impl.list.mutable.primitive.LongArrayList; import org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList; -import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.set.sorted.mutable.TreeSortedSet; @@ -838,16 +837,14 @@ public void collectShort() @Test public void groupByUniqueKey_throws() { - super.groupByUniqueKey_throws(); - assertEquals(UnifiedMap.newMap().toImmutable(), this.classUnderTest().groupByUniqueKey(id -> id)); + // Not applicable for empty* } @Override @Test public void groupByUniqueKey_target_throws() { - super.groupByUniqueKey_target_throws(); - assertEquals(UnifiedMap.newMap(), this.classUnderTest().groupByUniqueKey(id -> id, UnifiedMap.newMap())); + // Not applicable for empty* } @Override diff --git a/unit-tests/src/test/java/org/eclipse/collections/impl/stack/immutable/primitive/AbstractImmutableBooleanStackTestCase.java b/unit-tests/src/test/java/org/eclipse/collections/impl/stack/immutable/primitive/AbstractImmutableBooleanStackTestCase.java index 0956fbc89a..4bef48e4fa 100644 --- a/unit-tests/src/test/java/org/eclipse/collections/impl/stack/immutable/primitive/AbstractImmutableBooleanStackTestCase.java +++ b/unit-tests/src/test/java/org/eclipse/collections/impl/stack/immutable/primitive/AbstractImmutableBooleanStackTestCase.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; /** @@ -103,16 +104,16 @@ public void popWithCount() assertEquals(this.classUnderTest(), stack); } - @Test(expected = IllegalArgumentException.class) + @Test public void pop_with_negative_count_throws_exception() { - this.classUnderTest().pop(-1); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().pop(-1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void pop_with_count_greater_than_stack_size_throws_exception() { - this.classUnderTest().pop(this.classUnderTest().size() + 1); + assertThrows(IllegalArgumentException.class, () -> this.classUnderTest().pop(this.classUnderTest().size() + 1)); } @Override