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<String> 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<String> 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<Object> 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<E> 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<Object> 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 NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 72),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, number of items, size of
filter, and number of functions fails.
*/
@Test
public void constructor_nmk_noName() {
- try {
- new Shape(null, 5, 72, 17);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 72,
17),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, number of items, and
probability fails.
*/
@Test
public void constructor_np_noName() {
- try {
- new Shape(null, 5, 0.1);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 0.1),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, probability, size of
filter, and number of functions fails.
*/
@Test
public void constructor_pmk_noName() {
- try {
- new Shape(null, 0.1, 72, 17);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 0.1,
72, 17),
+ "Should throw NullPointerException");
}
/**
* Tests that if the number of bits is less than 1 an exception is thrown
*/
@Test
public void constructor_probability_bits_hash_BadNumberOfBitsTest() {
- try {
- new Shape(testFunction, 0.5, 0, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.5, 0, 1),
+ "Should have thrown IllegalArgumentException");
}
/**
* Tests that if the number of functions is less than 1 an exception is
thrown
*/
@Test
public void
constructor_probability_bits_hash_BadNumberOfHashFunctionsTest() {
- try {
- new Shape(testFunction, 0.5, 24, 0);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.5, 24, 0),
+ "Should have thrown IllegalArgumentException");
}
/**
* Tests that invalid probability values cause and
IllegalArgumentException to be thrown.
*/
@Test
public void constructor_probability_bits_hash_BadProbabilityTest() {
- // probability should not be 0
- try {
- new Shape(testFunction, 0.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be = -1
- try {
- new Shape(testFunction, -1.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be < -1
- try {
- new Shape(testFunction, -1.5, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be = 1
- try {
- new Shape(testFunction, 1.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be > 1
- try {
- new Shape(testFunction, 2.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertAll(
+ // probability should not be 0
+ () -> assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.0, 24, 1),
+ "Should have thrown IllegalArgumentException"),
+
Review comment:
No need for an extra blank line to separate method arguments.
##########
File path: src/test/java/org/apache/commons/collections4/IterableUtilsTest.java
##########
@@ -274,12 +265,9 @@ public void find() {
test = IterableUtils.find(iterableA, testPredicate);
assertNull(test);
assertNull(IterableUtils.find(null, testPredicate));
- try {
- IterableUtils.find(iterableA, null);
- fail("expecting NullPointerException");
- } catch (final NullPointerException npe) {
- // expected
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
##########
@@ -2225,12 +2195,9 @@ public void testSubtractWithPredicate() {
public void testSynchronizedCollection() {
final Collection<Object> col =
CollectionUtils.synchronizedCollection(new ArrayList<>());
assertTrue(col instanceof SynchronizedCollection, "Returned object
should be a SynchronizedCollection.");
- try {
- CollectionUtils.synchronizedCollection(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/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 NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 72),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, number of items, size of
filter, and number of functions fails.
*/
@Test
public void constructor_nmk_noName() {
- try {
- new Shape(null, 5, 72, 17);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 72,
17),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, number of items, and
probability fails.
*/
@Test
public void constructor_np_noName() {
- try {
- new Shape(null, 5, 0.1);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 0.1),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, probability, size of
filter, and number of functions fails.
*/
@Test
public void constructor_pmk_noName() {
- try {
- new Shape(null, 0.1, 72, 17);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 0.1,
72, 17),
+ "Should throw NullPointerException");
}
/**
* Tests that if the number of bits is less than 1 an exception is thrown
*/
@Test
public void constructor_probability_bits_hash_BadNumberOfBitsTest() {
- try {
- new Shape(testFunction, 0.5, 0, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.5, 0, 1),
+ "Should have thrown IllegalArgumentException");
}
/**
* Tests that if the number of functions is less than 1 an exception is
thrown
*/
@Test
public void
constructor_probability_bits_hash_BadNumberOfHashFunctionsTest() {
- try {
- new Shape(testFunction, 0.5, 24, 0);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.5, 24, 0),
+ "Should have thrown IllegalArgumentException");
}
/**
* Tests that invalid probability values cause and
IllegalArgumentException to be thrown.
*/
@Test
public void constructor_probability_bits_hash_BadProbabilityTest() {
- // probability should not be 0
- try {
- new Shape(testFunction, 0.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be = -1
- try {
- new Shape(testFunction, -1.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be < -1
- try {
- new Shape(testFunction, -1.5, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be = 1
- try {
- new Shape(testFunction, 1.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be > 1
- try {
- new Shape(testFunction, 2.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertAll(
+ // probability should not be 0
+ () -> assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.0, 24, 1),
+ "Should have thrown IllegalArgumentException"),
+
+ // probability should not be = -1
+ () -> assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, -1.0, 24, 1),
+ "Should have thrown IllegalArgumentException"),
+
Review comment:
No need for an extra blank line to separate method arguments.
##########
File path: src/test/java/org/apache/commons/collections4/IterableUtilsTest.java
##########
@@ -350,19 +319,11 @@ public void matchesAny() {
@Test
public void matchesAll() {
- try {
- assertFalse(IterableUtils.matchesAll(null, null));
- fail("predicate must not be null");
- } catch (final NullPointerException ex) {
- // expected
- }
-
- try {
- assertFalse(IterableUtils.matchesAll(iterableA, null));
- fail("predicate must not be null");
- } catch (final NullPointerException ex) {
- // expected
- }
+ assertThrows(NullPointerException.class, () ->
assertFalse(IterableUtils.matchesAll(null, null)),
+ "predicate must not be null");
+
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 NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 72),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, number of items, size of
filter, and number of functions fails.
*/
@Test
public void constructor_nmk_noName() {
- try {
- new Shape(null, 5, 72, 17);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 72,
17),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, number of items, and
probability fails.
*/
@Test
public void constructor_np_noName() {
- try {
- new Shape(null, 5, 0.1);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 0.1),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, probability, size of
filter, and number of functions fails.
*/
@Test
public void constructor_pmk_noName() {
- try {
- new Shape(null, 0.1, 72, 17);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 0.1,
72, 17),
+ "Should throw NullPointerException");
}
/**
* Tests that if the number of bits is less than 1 an exception is thrown
*/
@Test
public void constructor_probability_bits_hash_BadNumberOfBitsTest() {
- try {
- new Shape(testFunction, 0.5, 0, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.5, 0, 1),
+ "Should have thrown IllegalArgumentException");
}
/**
* Tests that if the number of functions is less than 1 an exception is
thrown
*/
@Test
public void
constructor_probability_bits_hash_BadNumberOfHashFunctionsTest() {
- try {
- new Shape(testFunction, 0.5, 24, 0);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.5, 24, 0),
+ "Should have thrown IllegalArgumentException");
}
/**
* Tests that invalid probability values cause and
IllegalArgumentException to be thrown.
*/
@Test
public void constructor_probability_bits_hash_BadProbabilityTest() {
- // probability should not be 0
- try {
- new Shape(testFunction, 0.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be = -1
- try {
- new Shape(testFunction, -1.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be < -1
- try {
- new Shape(testFunction, -1.5, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be = 1
- try {
- new Shape(testFunction, 1.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be > 1
- try {
- new Shape(testFunction, 2.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertAll(
+ // probability should not be 0
+ () -> assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.0, 24, 1),
+ "Should have thrown IllegalArgumentException"),
+
+ // probability should not be = -1
+ () -> assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, -1.0, 24, 1),
+ "Should have thrown IllegalArgumentException"),
+
+ // probability should not be < -1
+ () -> assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, -1.5, 24, 1),
+ "Should have thrown IllegalArgumentException"),
+
Review comment:
No need for an extra blank line to separate method arguments.
##########
File path:
src/test/java/org/apache/commons/collections4/bloomfilter/hasher/StaticHasherTest.java
##########
@@ -220,12 +215,9 @@ public void testConstructor_Iterator_ValueTooSmall() {
final int[] values = {-1, 3, 5, 7, 9, 3, 5, 1};
final Iterator<Integer> iter = Arrays.stream(values).iterator();
- try {
- new StaticHasher(iter, shape);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // do nothing
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/bloomfilter/hasher/StaticHasherTest.java
##########
@@ -203,12 +201,9 @@ public void testConstructor_Iterator_ValueTooBig() {
final int[] values = {shape.getNumberOfBits(), 3, 5, 7, 9, 3, 5, 1};
final Iterator<Integer> iter = Arrays.stream(values).iterator();
- try {
- new StaticHasher(iter, shape);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // do nothing
- }
+
Review comment:
No need for an extra blank line.
##########
File path: src/test/java/org/apache/commons/collections4/IterableUtilsTest.java
##########
@@ -291,51 +279,32 @@ public void indexOf() {
index = IterableUtils.indexOf(iterableA, testPredicate);
assertEquals(-1, index);
assertEquals(-1, IterableUtils.indexOf(null, testPredicate));
- try {
- IterableUtils.indexOf(iterableA, null);
- fail("expecting NullPointerException");
- } catch (final NullPointerException npe) {
- // expected
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java
##########
@@ -303,11 +278,8 @@ public void testRemoveMiddle() {
assertEquals("f", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java
##########
@@ -130,11 +130,8 @@ public void testSameAsDecorated() {
public void testEmptyBounded() {
final Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 3,
0);
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java
##########
@@ -81,11 +86,9 @@ public void testBounded() {
assertEquals("f", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java
##########
@@ -271,11 +249,8 @@ public void testRemoveFirst() {
assertEquals("f", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java
##########
@@ -331,21 +303,17 @@ public void testRemoveLast() {
assertEquals("f", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path: src/test/java/org/apache/commons/collections4/IterableUtilsTest.java
##########
@@ -111,12 +112,9 @@ public void forEach() {
col.add(listB);
IterableUtils.forEach(col, testClosure);
assertTrue(listA.isEmpty() && listB.isEmpty());
- try {
- IterableUtils.forEach(col, null);
- fail("expecting NullPointerException");
- } catch (final NullPointerException npe) {
- // expected
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java
##########
@@ -331,21 +303,17 @@ public void testRemoveLast() {
assertEquals("f", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
+ final NoSuchElementException thrown =
assertThrows(NoSuchElementException.class, () -> iter.next());
+ assertThat(thrown.getMessage(), is(nullValue()));
iter.remove();
assertFalse(testListCopy.contains("f"));
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java
##########
@@ -203,11 +191,8 @@ public void testMaxGreaterThanSize() {
assertEquals("g", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java
##########
@@ -172,11 +163,8 @@ public void testNegativeMax() {
public void testOffsetGreaterThanSize() {
final Iterator<E> iter = new BoundedIterator<>(testList.iterator(),
10, 4);
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
##########
@@ -501,26 +499,29 @@ public void exists() {
@Test
public void extractSingleton() {
- ArrayList<String> 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<String> collNull = null;
+ assertThrows(NullPointerException.class, () ->
CollectionUtils.extractSingleton(collNull),
+ "expected NullPointerException from
extractSingleton(null)");
+ },
+
+ () -> {
+ ArrayList<String> collEmpty = new ArrayList<>();
+ assertThrows(IllegalArgumentException.class, () ->
CollectionUtils.extractSingleton(collEmpty),
+ "expected IllegalArgumentException from
extractSingleton(empty)");
+ },
+
Review comment:
No need for an extra blank line to separate method arguments.
##########
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 NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 72),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, number of items, size of
filter, and number of functions fails.
*/
@Test
public void constructor_nmk_noName() {
- try {
- new Shape(null, 5, 72, 17);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 72,
17),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, number of items, and
probability fails.
*/
@Test
public void constructor_np_noName() {
- try {
- new Shape(null, 5, 0.1);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 5, 0.1),
+ "Should throw NullPointerException");
}
/**
* Tests that the constructor with a null name, probability, size of
filter, and number of functions fails.
*/
@Test
public void constructor_pmk_noName() {
- try {
- new Shape(null, 0.1, 72, 17);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException expected) {
- // do nothing
- }
+ assertThrows(NullPointerException.class, () -> new Shape(null, 0.1,
72, 17),
+ "Should throw NullPointerException");
}
/**
* Tests that if the number of bits is less than 1 an exception is thrown
*/
@Test
public void constructor_probability_bits_hash_BadNumberOfBitsTest() {
- try {
- new Shape(testFunction, 0.5, 0, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.5, 0, 1),
+ "Should have thrown IllegalArgumentException");
}
/**
* Tests that if the number of functions is less than 1 an exception is
thrown
*/
@Test
public void
constructor_probability_bits_hash_BadNumberOfHashFunctionsTest() {
- try {
- new Shape(testFunction, 0.5, 24, 0);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.5, 24, 0),
+ "Should have thrown IllegalArgumentException");
}
/**
* Tests that invalid probability values cause and
IllegalArgumentException to be thrown.
*/
@Test
public void constructor_probability_bits_hash_BadProbabilityTest() {
- // probability should not be 0
- try {
- new Shape(testFunction, 0.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be = -1
- try {
- new Shape(testFunction, -1.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be < -1
- try {
- new Shape(testFunction, -1.5, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be = 1
- try {
- new Shape(testFunction, 1.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
-
- // probability should not be > 1
- try {
- new Shape(testFunction, 2.0, 24, 1);
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
+ assertAll(
+ // probability should not be 0
+ () -> assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 0.0, 24, 1),
+ "Should have thrown IllegalArgumentException"),
+
+ // probability should not be = -1
+ () -> assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, -1.0, 24, 1),
+ "Should have thrown IllegalArgumentException"),
+
+ // probability should not be < -1
+ () -> assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, -1.5, 24, 1),
+ "Should have thrown IllegalArgumentException"),
+
+ // probability should not be = 1
+ () -> assertThrows(IllegalArgumentException.class, () -> new
Shape(testFunction, 1.0, 24, 1),
+ "Should have thrown IllegalArgumentException"),
+
Review comment:
No need for an extra blank line to separate method arguments.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/SkippingIteratorTest.java
##########
@@ -238,11 +222,9 @@ public void testRemoveMiddle() {
assertEquals("g", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/LoopingIteratorTest.java
##########
@@ -152,19 +136,16 @@ public void testRemoving1() throws Exception {
assertEquals(0, list.size(), "list should have 0 elements.");
assertFalse(loop.hasNext(), "4th hasNext should return false");
- try {
- loop.next();
- fail("Expected NoSuchElementException to be thrown.");
- } catch (final NoSuchElementException ex) {
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/SkippingIteratorTest.java
##########
@@ -208,11 +194,9 @@ public void testRemoveFirst() {
assertEquals("g", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/LoopingListIteratorTest.java
##########
@@ -193,11 +181,8 @@ public void testRemovingElementsAndIteratingForward() {
assertEquals(0, list.size());
assertFalse(loop.hasNext());
- try {
- loop.next();
- fail();
- } catch (final NoSuchElementException ex) {
- }
+
Review comment:
No need for an extra blank line.
##########
File path: src/test/java/org/apache/commons/collections4/MapUtilsTest.java
##########
@@ -871,11 +840,9 @@ public void testPopulateMultiMap() {
@Test
public void testIterableMap() {
- try {
- MapUtils.iterableMap(null);
- fail("Should throw NullPointerException");
- } catch (final NullPointerException e) {
- }
+ assertThrows(NullPointerException.class, () ->
MapUtils.iterableMap(null),
+ "Should throw NullPointerException");
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/LoopingListIteratorTest.java
##########
@@ -224,11 +209,8 @@ public void testRemovingElementsAndIteratingBackwards() {
assertEquals(0, list.size());
assertFalse(loop.hasPrevious());
- try {
- loop.previous();
- fail();
- } catch (final NoSuchElementException ex) {
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/BoundedIteratorTest.java
##########
@@ -114,11 +117,8 @@ public void testSameAsDecorated() {
assertEquals("g", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* 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<Object> 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());
+
+ assertThrows(IllegalStateException.class, () -> it.remove());
}
public void testIteratorConstructor_null_next() {
final Iterator<Object> it = new ObjectGraphIterator<>(null);
- try {
- it.next();
- fail();
- } catch (final NoSuchElementException ex) {
- }
+ assertThrows(NoSuchElementException.class, () -> it.next());
}
public void testIteratorConstructor_null_remove() {
final Iterator<Object> it = new ObjectGraphIterator<>(null);
- try {
- it.remove();
- fail();
- } catch (final IllegalStateException ex) {
- }
+ assertThrows(IllegalStateException.class, () -> it.remove());
}
public void testIteratorConstructorIteration_Empty() {
final List<Iterator<Object>> iteratorList = new ArrayList<>();
final Iterator<Object> it = new
ObjectGraphIterator<>(iteratorList.iterator());
assertFalse(it.hasNext());
- try {
- it.next();
- fail();
- } catch (final NoSuchElementException ex) {
- }
- try {
- it.remove();
- fail();
- } catch (final IllegalStateException ex) {
- }
+
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<Object> it = new ObjectGraphIterator<>(null);
assertFalse(it.hasNext());
- try {
- it.next();
- fail();
- } catch (final NoSuchElementException ex) {
- }
- try {
- it.remove();
- fail();
- } catch (final IllegalStateException ex) {
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/ObjectGraphIteratorTest.java
##########
@@ -132,11 +113,8 @@ public void testIteratorConstructorIteration_Simple() {
assertEquals(testArray[i], 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/iterators/ObjectGraphIteratorTest.java
##########
@@ -251,11 +217,8 @@ public void testIteration_RootNoTransformer() {
assertTrue(it.hasNext());
assertSame(forest, 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/iterators/ObjectGraphIteratorTest.java
##########
@@ -232,16 +204,10 @@ public void testIteration_RootNull() {
final Iterator<Object> it = new ObjectGraphIterator<>(null, 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
##########
@@ -266,11 +229,8 @@ public void testIteration_Transformed1() {
assertTrue(it.hasNext());
assertSame(l1, 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/iterators/ObjectGraphIteratorTest.java
##########
@@ -73,51 +74,31 @@ public void testIteratorConstructor_null1() {
final Iterator<Object> 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());
+
+ assertThrows(IllegalStateException.class, () -> it.remove());
}
public void testIteratorConstructor_null_next() {
final Iterator<Object> it = new ObjectGraphIterator<>(null);
- try {
- it.next();
- fail();
- } catch (final NoSuchElementException ex) {
- }
+ assertThrows(NoSuchElementException.class, () -> it.next());
}
public void testIteratorConstructor_null_remove() {
final Iterator<Object> it = new ObjectGraphIterator<>(null);
- try {
- it.remove();
- fail();
- } catch (final IllegalStateException ex) {
- }
+ assertThrows(IllegalStateException.class, () -> it.remove());
}
public void testIteratorConstructorIteration_Empty() {
final List<Iterator<Object>> iteratorList = new ArrayList<>();
final Iterator<Object> it = new
ObjectGraphIterator<>(iteratorList.iterator());
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/SkippingIteratorTest.java
##########
@@ -115,11 +114,9 @@ public void testSameAsDecorated() {
assertEquals("g", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/ObjectGraphIteratorTest.java
##########
@@ -232,16 +204,10 @@ public void testIteration_RootNull() {
final Iterator<Object> it = new ObjectGraphIterator<>(null, null);
assertFalse(it.hasNext());
- try {
- it.next();
- fail();
- } catch (final NoSuchElementException ex) {
- }
- try {
- it.remove();
- fail();
- } catch (final IllegalStateException ex) {
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/ObjectGraphIteratorTest.java
##########
@@ -302,11 +262,8 @@ public void testIteration_Transformed2() {
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/iterators/ReverseListIteratorTest.java
##########
@@ -106,11 +104,9 @@ public void testWalkForwardAndBack() {
// check state at start
assertTrue(it.hasNext());
assertFalse(it.hasPrevious());
- try {
- it.previous();
- fail("NoSuchElementException must be thrown from previous at start
of ListIterator");
- } catch (final NoSuchElementException e) {
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/ObjectGraphIteratorTest.java
##########
@@ -172,11 +147,8 @@ public void
testIteratorConstructorIteration_WithEmptyIterators() {
assertEquals(testArray[i], 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/iterators/ObjectGraphIteratorTest.java
##########
@@ -149,11 +127,8 @@ public void
testIteratorConstructorIteration_SimpleNoHasNext() {
for (int i = 0; i < 6; i++) {
assertEquals(testArray[i], it.next());
}
- 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/iterators/SkippingIteratorTest.java
##########
@@ -83,11 +84,9 @@ public void testSkipping() {
assertEquals("g", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/SkippingIteratorTest.java
##########
@@ -131,11 +128,9 @@ public void testSameAsDecorated() {
public void testOffsetGreaterThanSize() {
final Iterator<E> iter = new SkippingIterator<>(testList.iterator(),
10);
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/SkippingIteratorTest.java
##########
@@ -260,21 +242,17 @@ public void testRemoveLast() {
assertEquals("g", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/list/CursorableLinkedListTest.java
##########
@@ -246,12 +249,9 @@ public void testCursorRemove() {
list.add((E) "5");
final CursorableLinkedList.Cursor<E> it = list.cursor();
- try {
- it.remove();
- fail();
- } catch (final IllegalStateException e) {
- // expected
- }
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/SkippingIteratorTest.java
##########
@@ -293,10 +271,9 @@ public void remove() {
final Iterator<E> iter = new SkippingIterator<>(mockIterator, 1);
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/list/CursorableLinkedListTest.java
##########
@@ -246,12 +249,9 @@ public void testCursorRemove() {
list.add((E) "5");
final CursorableLinkedList.Cursor<E> it = list.cursor();
- try {
- it.remove();
- fail();
- } catch (final IllegalStateException e) {
- // expected
- }
+
+ assertThrows(IllegalStateException.class, () -> it.remove());
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/list/CursorableLinkedListTest.java
##########
@@ -531,10 +519,8 @@ public void
testInternalState_CursorNextNextRemoveIndex1ByList() {
assertEquals("[A, C]", list.toString());
c1.remove(); // works ok
assertEquals("[A, C]", list.toString());
- try {
- c1.remove();
- fail();
- } catch (final IllegalStateException ex) {}
+
Review comment:
I'll stop here.
##########
File path:
src/test/java/org/apache/commons/collections4/list/CursorableLinkedListTest.java
##########
@@ -478,10 +470,8 @@ public void
testInternalState_CursorNextNextPreviousRemoveIndex1ByList() {
assertEquals("[A, C]", list.toString());
c1.remove(); // works ok
assertEquals("[A, C]", list.toString());
- try {
- c1.remove();
- fail();
- } catch (final IllegalStateException ex) {}
+
Review comment:
No need for an extra blank line.
##########
File path:
src/test/java/org/apache/commons/collections4/iterators/SkippingIteratorTest.java
##########
@@ -260,21 +242,17 @@ public void testRemoveLast() {
assertEquals("g", iter.next());
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
+ assertThrows(NoSuchElementException.class, () -> iter.next(),
+ "Expected NoSuchElementException.");
iter.remove();
assertFalse(testListCopy.contains("g"));
assertFalse(iter.hasNext());
- try {
- iter.next();
- fail("Expected NoSuchElementException.");
- } catch (final NoSuchElementException nsee) { /* Success case */
- }
+
Review comment:
No need for an extra blank line.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]