garydgregory commented on a change in pull request #287:
URL:
https://github.com/apache/commons-collections/pull/287#discussion_r820275806
##
File path:
src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
##
@@ -501,26 +499,29 @@ public void exists() {
@Test
public void extractSingleton() {
-ArrayList coll = null;
-try {
-CollectionUtils.extractSingleton(coll);
-fail("expected NullPointerException from extractSingleton(null)");
-} catch (final NullPointerException e) {
-}
-coll = new ArrayList<>();
-try {
-CollectionUtils.extractSingleton(coll);
-fail("expected IllegalArgumentException from
extractSingleton(empty)");
-} catch (final IllegalArgumentException e) {
-}
-coll.add("foo");
-assertEquals("foo", CollectionUtils.extractSingleton(coll));
-coll.add("bar");
-try {
-CollectionUtils.extractSingleton(coll);
-fail("expected IllegalArgumentException from extractSingleton(size
== 2)");
-} catch (final IllegalArgumentException e) {
-}
+assertAll(
+() -> {
+ArrayList collNull = null;
+assertThrows(NullPointerException.class, () ->
CollectionUtils.extractSingleton(collNull),
+"expected NullPointerException from
extractSingleton(null)");
+},
+
Review comment:
No need for an extra blank line to separate method arguments.
##
File path:
src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
##
@@ -2284,12 +2251,9 @@ public void testUnionNullColl2() {
public void testUnmodifiableCollection() {
final Collection col =
CollectionUtils.unmodifiableCollection(new ArrayList<>());
assertTrue(col instanceof UnmodifiableCollection, "Returned object
should be a UnmodifiableCollection.");
-try {
-CollectionUtils.unmodifiableCollection(null);
-fail("Expecting NullPointerException for null collection.");
-} catch (final NullPointerException ex) {
-// expected
-}
+
Review comment:
No need for an extra blank line.
##
File path: src/test/java/org/apache/commons/collections4/MapUtilsTest.java
##
@@ -889,11 +856,9 @@ public void testIterableMap() {
@Test
public void testIterableSortedMap() {
-try {
-MapUtils.iterableSortedMap(null);
-fail("Should throw NullPointerException");
-} catch (final NullPointerException e) {
-}
+assertThrows(NullPointerException.class, () ->
MapUtils.iterableSortedMap(null),
+"Should throw NullPointerException");
+
Review comment:
No need for an extra blank line.
##
File path:
src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java
##
@@ -364,10 +332,9 @@ public void remove() {
final Iterator iter = new BoundedIterator<>(mockIterator, 1, 5);
assertTrue(iter.hasNext());
assertEquals("b", iter.next());
-try {
-iter.remove();
-fail("Expected UnsupportedOperationException.");
-} catch (final UnsupportedOperationException usoe) { /* Success case */
-}
+
Review comment:
No need for an extra blank line.
##
File path:
src/test/java/org/apache/commons/collections4/iterators/ObjectGraphIteratorTest.java
##
@@ -73,51 +74,31 @@ public void testIteratorConstructor_null1() {
final Iterator it = new ObjectGraphIterator<>(null);
assertFalse(it.hasNext());
-try {
-it.next();
-fail();
-} catch (final NoSuchElementException ex) {
-}
-try {
-it.remove();
-fail();
-} catch (final IllegalStateException ex) {
-}
+
+assertThrows(NoSuchElementException.class, () -> it.next());
+
Review comment:
No need for an extra blank line.
##
File path:
src/test/java/org/apache/commons/collections4/iterators/ObjectGraphIteratorTest.java
##
@@ -338,14 +295,12 @@ public void testIteration_Transformed3() {
assertTrue(it.hasNext());
assertSame(l5, it.next());
assertFalse(it.hasNext());
-try {
-it.next();
-fail();
-} catch (final NoSuchElementException ex) {
-}
+
Review comment:
No need for an extra blank line.
##
File path:
src/test/java/org/apache/commons/collections4/bloomfilter/hasher/ShapeTest.java
##
@@ -266,123 +222,81 @@ public void constructor_items_probability_Test() {
*/
@Test
public void constructor_nm_noName() {
-try {
-new Shape(null, 5, 72);
-fail("Should throw NullPointerException");
-} catch (final NullPoint