Skip to content

Commit c0fc3b7

Browse files
committed
Declutter unit test code
1 parent 3e22618 commit c0fc3b7

24 files changed

+252
-484
lines changed

src/test/java/org/apache/commons/collections4/BagUtilsTest.java

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
package org.apache.commons.collections4;
1819

19-
import static org.junit.jupiter.api.Assertions.assertAll;
2020
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
2121
import static org.junit.jupiter.api.Assertions.assertSame;
2222
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -46,82 +46,63 @@ public class BagUtilsTest {
4646
public void testPredicatedBag() {
4747
final Bag<Object> bag = BagUtils.predicatedBag(new HashBag<>(), truePredicate);
4848
assertInstanceOf(PredicatedBag.class, bag, "Returned object should be a PredicatedBag.");
49-
assertAll(
50-
() -> assertThrows(NullPointerException.class, () -> BagUtils.predicatedBag(null, truePredicate),
51-
"Expecting NullPointerException for null bag."),
52-
() -> assertThrows(NullPointerException.class, () -> BagUtils.predicatedBag(new HashBag<>(), null),
53-
"Expecting NullPointerException for null predicate.")
54-
);
49+
assertThrows(NullPointerException.class, () -> BagUtils.predicatedBag(null, truePredicate), "Expecting NullPointerException for null bag.");
50+
assertThrows(NullPointerException.class, () -> BagUtils.predicatedBag(new HashBag<>(), null), "Expecting NullPointerException for null predicate.");
5551
}
5652

5753
@Test
5854
public void testPredicatedSortedBag() {
5955
final Bag<Object> bag = BagUtils.predicatedSortedBag(new TreeBag<>(), truePredicate);
6056
assertInstanceOf(PredicatedSortedBag.class, bag, "Returned object should be a PredicatedSortedBag.");
61-
assertAll(
62-
() -> assertThrows(NullPointerException.class, () -> BagUtils.predicatedSortedBag(null, truePredicate),
63-
"Expecting NullPointerException for null bag."),
64-
() -> assertThrows(NullPointerException.class, () -> BagUtils.predicatedSortedBag(new TreeBag<>(), null),
65-
"Expecting NullPointerException for null predicate.")
66-
);
57+
assertThrows(NullPointerException.class, () -> BagUtils.predicatedSortedBag(null, truePredicate), "Expecting NullPointerException for null bag.");
58+
assertThrows(NullPointerException.class, () -> BagUtils.predicatedSortedBag(new TreeBag<>(), null),
59+
"Expecting NullPointerException for null predicate.");
6760
}
6861

6962
@Test
7063
public void testSynchronizedBag() {
7164
final Bag<Object> bag = BagUtils.synchronizedBag(new HashBag<>());
7265
assertInstanceOf(SynchronizedBag.class, bag, "Returned object should be a SynchronizedBag.");
73-
assertThrows(NullPointerException.class, () -> BagUtils.synchronizedBag(null),
74-
"Expecting NullPointerException for null bag.");
66+
assertThrows(NullPointerException.class, () -> BagUtils.synchronizedBag(null), "Expecting NullPointerException for null bag.");
7567
}
7668

7769
@Test
7870
public void testSynchronizedSortedBag() {
7971
final Bag<Object> bag = BagUtils.synchronizedSortedBag(new TreeBag<>());
8072
assertInstanceOf(SynchronizedSortedBag.class, bag, "Returned object should be a SynchronizedSortedBag.");
81-
assertThrows(NullPointerException.class, () -> BagUtils.synchronizedSortedBag(null),
82-
"Expecting NullPointerException for null bag.");
73+
assertThrows(NullPointerException.class, () -> BagUtils.synchronizedSortedBag(null), "Expecting NullPointerException for null bag.");
8374
}
8475

8576
@Test
8677
public void testTransformedBag() {
8778
final Bag<Object> bag = BagUtils.transformingBag(new HashBag<>(), nopTransformer);
8879
assertInstanceOf(TransformedBag.class, bag, "Returned object should be an TransformedBag.");
89-
assertAll(
90-
() -> assertThrows(NullPointerException.class, () -> BagUtils.transformingBag(null, nopTransformer),
91-
"Expecting NullPointerException for null bag."),
92-
() -> assertThrows(NullPointerException.class, () -> BagUtils.transformingBag(new HashBag<>(), null),
93-
"Expecting NullPointerException for null transformer.")
94-
);
80+
assertThrows(NullPointerException.class, () -> BagUtils.transformingBag(null, nopTransformer), "Expecting NullPointerException for null bag.");
81+
assertThrows(NullPointerException.class, () -> BagUtils.transformingBag(new HashBag<>(), null), "Expecting NullPointerException for null transformer.");
9582
}
9683

9784
@Test
9885
public void testTransformedSortedBag() {
9986
final Bag<Object> bag = BagUtils.transformingSortedBag(new TreeBag<>(), nopTransformer);
10087
assertInstanceOf(TransformedSortedBag.class, bag, "Returned object should be an TransformedSortedBag");
101-
assertAll(
102-
() -> assertThrows(NullPointerException.class, () -> BagUtils.transformingSortedBag(null, nopTransformer),
103-
"Expecting NullPointerException for null bag."),
104-
() -> assertThrows(NullPointerException.class, () -> BagUtils.transformingSortedBag(new TreeBag<>(), null),
105-
"Expecting NullPointerException for null transformer.")
106-
);
88+
assertThrows(NullPointerException.class, () -> BagUtils.transformingSortedBag(null, nopTransformer), "Expecting NullPointerException for null bag.");
89+
assertThrows(NullPointerException.class, () -> BagUtils.transformingSortedBag(new TreeBag<>(), null),
90+
"Expecting NullPointerException for null transformer.");
10791
}
10892

10993
@Test
11094
public void testUnmodifiableBag() {
11195
final Bag<Object> bag = BagUtils.unmodifiableBag(new HashBag<>());
11296
assertInstanceOf(UnmodifiableBag.class, bag, "Returned object should be an UnmodifiableBag.");
113-
assertThrows(NullPointerException.class, () -> BagUtils.unmodifiableBag(null),
114-
"Expecting NullPointerException for null bag.");
97+
assertThrows(NullPointerException.class, () -> BagUtils.unmodifiableBag(null), "Expecting NullPointerException for null bag.");
11598
assertSame(bag, BagUtils.unmodifiableBag(bag), "UnmodifiableBag shall not be decorated");
11699
}
117100

118101
@Test
119102
public void testUnmodifiableSortedBag() {
120103
final SortedBag<Object> bag = BagUtils.unmodifiableSortedBag(new TreeBag<>());
121104
assertInstanceOf(UnmodifiableSortedBag.class, bag, "Returned object should be an UnmodifiableSortedBag.");
122-
assertThrows(NullPointerException.class, () -> BagUtils.unmodifiableSortedBag(null),
123-
"Expecting NullPointerException for null bag.");
105+
assertThrows(NullPointerException.class, () -> BagUtils.unmodifiableSortedBag(null), "Expecting NullPointerException for null bag.");
124106
assertSame(bag, BagUtils.unmodifiableSortedBag(bag), "UnmodifiableSortedBag shall not be decorated");
125107
}
126-
127108
}

src/test/java/org/apache/commons/collections4/ClosureUtilsTest.java

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.commons.collections4;
1818

19-
import static org.junit.jupiter.api.Assertions.assertAll;
2019
import static org.junit.jupiter.api.Assertions.assertEquals;
2120
import static org.junit.jupiter.api.Assertions.assertNotNull;
2221
import static org.junit.jupiter.api.Assertions.assertSame;
@@ -93,18 +92,15 @@ public void testChainedClosure() {
9392

9493
assertSame(NOPClosure.INSTANCE, ClosureUtils.<Object>chainedClosure());
9594
assertSame(NOPClosure.INSTANCE, ClosureUtils.<Object>chainedClosure(Collections.<Closure<Object>>emptyList()));
96-
assertAll(
97-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.chainedClosure(null, null)),
98-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.<Object>chainedClosure((Closure[]) null)),
99-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.<Object>chainedClosure((Collection<Closure<Object>>) null)),
100-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.<Object>chainedClosure(null, null)),
101-
() -> {
102-
final Collection<Closure<Object>> finalColl = new ArrayList<>();
103-
finalColl.add(null);
104-
finalColl.add(null);
105-
assertThrows(NullPointerException.class, () -> ClosureUtils.chainedClosure(finalColl));
106-
}
107-
);
95+
96+
assertThrows(NullPointerException.class, () -> ClosureUtils.chainedClosure(null, null));
97+
assertThrows(NullPointerException.class, () -> ClosureUtils.<Object>chainedClosure((Closure[]) null));
98+
assertThrows(NullPointerException.class, () -> ClosureUtils.<Object>chainedClosure((Collection<Closure<Object>>) null));
99+
assertThrows(NullPointerException.class, () -> ClosureUtils.<Object>chainedClosure(null, null));
100+
final Collection<Closure<Object>> finalColl = new ArrayList<>();
101+
finalColl.add(null);
102+
finalColl.add(null);
103+
assertThrows(NullPointerException.class, () -> ClosureUtils.chainedClosure(finalColl));
108104
}
109105

110106
@Test
@@ -124,10 +120,9 @@ public void testDoWhileClosure() {
124120
public void testExceptionClosure() {
125121
assertNotNull(ClosureUtils.exceptionClosure());
126122
assertSame(ClosureUtils.exceptionClosure(), ClosureUtils.exceptionClosure());
127-
assertAll(
128-
() -> assertThrows(FunctorException.class, () -> ClosureUtils.exceptionClosure().execute(null)),
129-
() -> assertThrows(FunctorException.class, () -> ClosureUtils.exceptionClosure().execute(cString))
130-
);
123+
124+
assertThrows(FunctorException.class, () -> ClosureUtils.exceptionClosure().execute(null));
125+
assertThrows(FunctorException.class, () -> ClosureUtils.exceptionClosure().execute(cString));
131126
}
132127

133128
@Test
@@ -268,15 +263,13 @@ public void testSwitchClosure() {
268263
map.clear();
269264
map.put(null, null);
270265
assertEquals(NOPClosure.INSTANCE, ClosureUtils.switchClosure(map));
271-
assertAll(
272-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.switchClosure(null, null)),
273-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.<String>switchClosure((Predicate<String>[]) null, (Closure<String>[]) null)),
274-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.<String>switchClosure((Map<Predicate<String>, Closure<String>>) null)),
275-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.<String>switchClosure(new Predicate[2], new Closure[2])),
276-
() -> assertThrows(IllegalArgumentException.class, () -> ClosureUtils.<String>switchClosure(
277-
new Predicate[]{TruePredicate.<String>truePredicate()},
278-
new Closure[]{a, b}))
279-
);
266+
267+
assertThrows(NullPointerException.class, () -> ClosureUtils.switchClosure(null, null));
268+
assertThrows(NullPointerException.class, () -> ClosureUtils.<String>switchClosure((Predicate<String>[]) null, (Closure<String>[]) null));
269+
assertThrows(NullPointerException.class, () -> ClosureUtils.<String>switchClosure((Map<Predicate<String>, Closure<String>>) null));
270+
assertThrows(NullPointerException.class, () -> ClosureUtils.<String>switchClosure(new Predicate[2], new Closure[2]));
271+
assertThrows(IllegalArgumentException.class,
272+
() -> ClosureUtils.<String>switchClosure(new Predicate[] { TruePredicate.<String>truePredicate() }, new Closure[] { a, b }));
280273
}
281274

282275
@Test
@@ -337,11 +330,10 @@ public void testWhileClosure() {
337330
cmd = new MockClosure<>();
338331
ClosureUtils.whileClosure(PredicateUtils.uniquePredicate(), cmd).execute(null);
339332
assertEquals(1, cmd.count);
340-
assertAll(
341-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.whileClosure(null, ClosureUtils.nopClosure())),
342-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.whileClosure(FalsePredicate.falsePredicate(), null)),
343-
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.whileClosure(null, null))
344-
);
333+
334+
assertThrows(NullPointerException.class, () -> ClosureUtils.whileClosure(null, ClosureUtils.nopClosure()));
335+
assertThrows(NullPointerException.class, () -> ClosureUtils.whileClosure(FalsePredicate.falsePredicate(), null));
336+
assertThrows(NullPointerException.class, () -> ClosureUtils.whileClosure(null, null));
345337
}
346338

347339
}

0 commit comments

Comments
 (0)