Skip to content

Commit 7be9ef9

Browse files
committed
Reuse LangAssertions
1 parent 8cc6363 commit 7be9ef9

File tree

7 files changed

+36
-37
lines changed

7 files changed

+36
-37
lines changed

src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6704,7 +6704,7 @@ void testToPrimitive_byte() {
67046704
assertArrayEquals(new byte[]{Byte.MIN_VALUE, Byte.MAX_VALUE, (byte) 9999999}, ArrayUtils.toPrimitive(new Byte[]{Byte.valueOf(Byte.MIN_VALUE),
67056705
Byte.valueOf(Byte.MAX_VALUE), Byte.valueOf((byte) 9999999)}));
67066706

6707-
assertThrows(NullPointerException.class,
6707+
assertNullPointerException(
67086708
() -> ArrayUtils.toPrimitive(new Byte[]{Byte.valueOf(Byte.MIN_VALUE), null}));
67096709
}
67106710

@@ -6735,7 +6735,7 @@ void testToPrimitive_char() {
67356735
assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{Character.valueOf(Character.MIN_VALUE),
67366736
Character.valueOf(Character.MAX_VALUE), Character.valueOf('0')}));
67376737

6738-
assertThrows(NullPointerException.class,
6738+
assertNullPointerException(
67396739
() -> ArrayUtils.toPrimitive(new Character[]{Character.valueOf(Character.MIN_VALUE), null}));
67406740
}
67416741

@@ -6767,7 +6767,7 @@ void testToPrimitive_double() {
67676767
assertArrayEquals(new double[]{Double.MIN_VALUE, Double.MAX_VALUE, 9999999}, ArrayUtils.toPrimitive(new Double[]{Double.valueOf(Double.MIN_VALUE),
67686768
Double.valueOf(Double.MAX_VALUE), Double.valueOf(9999999)}));
67696769

6770-
assertThrows(NullPointerException.class,
6770+
assertNullPointerException(
67716771
() -> ArrayUtils.toPrimitive(new Float[]{Float.valueOf(Float.MIN_VALUE), null}));
67726772
}
67736773

@@ -6798,7 +6798,7 @@ void testToPrimitive_float() {
67986798
assertArrayEquals(new float[]{Float.MIN_VALUE, Float.MAX_VALUE, 9999999}, ArrayUtils.toPrimitive(new Float[]{Float.valueOf(Float.MIN_VALUE),
67996799
Float.valueOf(Float.MAX_VALUE), Float.valueOf(9999999)}));
68006800

6801-
assertThrows(NullPointerException.class,
6801+
assertNullPointerException(
68026802
() -> ArrayUtils.toPrimitive(new Float[]{Float.valueOf(Float.MIN_VALUE), null}));
68036803
}
68046804

@@ -6826,7 +6826,7 @@ void testToPrimitive_int() {
68266826
assertArrayEquals(new int[]{Integer.MIN_VALUE, Integer.MAX_VALUE, 9999999}, ArrayUtils.toPrimitive(new Integer[]{Integer.valueOf(Integer.MIN_VALUE),
68276827
Integer.valueOf(Integer.MAX_VALUE), Integer.valueOf(9999999)}));
68286828

6829-
assertThrows(NullPointerException.class,
6829+
assertNullPointerException(
68306830
() -> ArrayUtils.toPrimitive(new Integer[]{Integer.valueOf(Integer.MIN_VALUE), null}));
68316831
}
68326832

@@ -6860,7 +6860,7 @@ void testToPrimitive_long() {
68606860
assertArrayEquals(new long[]{Long.MIN_VALUE, Long.MAX_VALUE, 9999999}, ArrayUtils.toPrimitive(new Long[]{Long.valueOf(Long.MIN_VALUE),
68616861
Long.valueOf(Long.MAX_VALUE), Long.valueOf(9999999)}));
68626862

6863-
assertThrows(NullPointerException.class,
6863+
assertNullPointerException(
68646864
() -> ArrayUtils.toPrimitive(new Long[]{Long.valueOf(Long.MIN_VALUE), null}));
68656865
}
68666866

@@ -6890,7 +6890,7 @@ void testToPrimitive_short() {
68906890
assertArrayEquals(new short[]{Short.MIN_VALUE, Short.MAX_VALUE, (short) 9999999}, ArrayUtils.toPrimitive(new Short[]{Short.valueOf(Short.MIN_VALUE),
68916891
Short.valueOf(Short.MAX_VALUE), Short.valueOf((short) 9999999)}));
68926892

6893-
assertThrows(NullPointerException.class,
6893+
assertNullPointerException(
68946894
() -> ArrayUtils.toPrimitive(new Short[]{Short.valueOf(Short.MIN_VALUE), null}));
68956895
}
68966896

src/test/java/org/apache/commons/lang3/ClassPathUtilsTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.junit.jupiter.api.Assertions.assertEquals;
2121
import static org.junit.jupiter.api.Assertions.assertFalse;
2222
import static org.junit.jupiter.api.Assertions.assertNotNull;
23-
import static org.junit.jupiter.api.Assertions.assertThrows;
2423
import static org.junit.jupiter.api.Assertions.assertTrue;
2524

2625
import java.lang.reflect.Constructor;
@@ -71,19 +70,19 @@ void testToFullyQualifiedNameClassString() {
7170

7271
@Test
7372
void testToFullyQualifiedNameNullClassString() {
74-
assertThrows(NullPointerException.class,
73+
assertNullPointerException(
7574
() -> ClassPathUtils.toFullyQualifiedName((Class<?>) null, "Test.properties"));
7675
}
7776

7877
@Test
7978
void testToFullyQualifiedNameNullPackageString() {
80-
assertThrows(NullPointerException.class,
79+
assertNullPointerException(
8180
() -> ClassPathUtils.toFullyQualifiedName((Package) null, "Test.properties"));
8281
}
8382

8483
@Test
8584
void testToFullyQualifiedNamePackageNull() {
86-
assertThrows(NullPointerException.class,
85+
assertNullPointerException(
8786
() -> ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), null));
8887
}
8988

@@ -110,7 +109,7 @@ void testToFullyQualifiedPathClassNull() {
110109

111110
@Test
112111
void testToFullyQualifiedPathClassNullString() {
113-
assertThrows(NullPointerException.class,
112+
assertNullPointerException(
114113
() -> ClassPathUtils.toFullyQualifiedPath((Class<?>) null, "Test.properties"));
115114
}
116115

@@ -124,13 +123,13 @@ void testToFullyQualifiedPathPackage() {
124123

125124
@Test
126125
void testToFullyQualifiedPathPackageNull() {
127-
assertThrows(NullPointerException.class,
126+
assertNullPointerException(
128127
() -> ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), null));
129128
}
130129

131130
@Test
132131
void testToFullyQualifiedPathPackageNullString() {
133-
assertThrows(NullPointerException.class,
132+
assertNullPointerException(
134133
() -> ClassPathUtils.toFullyQualifiedPath((Package) null, "Test.properties"));
135134
}
136135
}

src/test/java/org/apache/commons/lang3/EnumUtilsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ void testGenerateBitVector_nullClassWithArray() {
129129

130130
@Test
131131
void testGenerateBitVector_nullElement() {
132-
assertThrows(NullPointerException.class,
132+
assertNullPointerException(
133133
() -> EnumUtils.generateBitVector(Traffic.class, Arrays.asList(Traffic.RED, null)));
134134
}
135135

136136
@Test
137137
void testGenerateBitVector_nullIterable() {
138-
assertThrows(NullPointerException.class,
138+
assertNullPointerException(
139139
() -> EnumUtils.generateBitVector(Traffic.class, (Iterable<Traffic>) null));
140140
}
141141

@@ -225,7 +225,7 @@ void testGenerateBitVectors_nullClassWithArray() {
225225

226226
@Test
227227
void testGenerateBitVectors_nullElement() {
228-
assertThrows(NullPointerException.class,
228+
assertNullPointerException(
229229
() -> EnumUtils.generateBitVectors(Traffic.class, Arrays.asList(Traffic.RED, null)));
230230
}
231231

src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,13 @@ void testComparatorMedian_emptyItems() {
315315

316316
@Test
317317
void testComparatorMedian_nullComparator() {
318-
assertThrows(NullPointerException.class,
318+
assertNullPointerException(
319319
() -> ObjectUtils.median((Comparator<CharSequence>) null, new NonComparableCharSequence("foo")));
320320
}
321321

322322
@Test
323323
void testComparatorMedian_nullItems() {
324-
assertThrows(NullPointerException.class,
324+
assertNullPointerException(
325325
() -> ObjectUtils.median(new CharSequenceComparator(), (CharSequence[]) null));
326326
}
327327

src/test/java/org/apache/commons/lang3/builder/DiffResultTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void testNoDifferencesString() {
117117

118118
@Test
119119
void testNullLhs() {
120-
assertThrows(NullPointerException.class,
120+
assertNullPointerException(
121121
() -> new DiffResult<>(null, SIMPLE_FALSE, SIMPLE_TRUE.diff(SIMPLE_FALSE).getDiffs(), SHORT_STYLE, DiffBuilder.TO_STRING_FORMAT));
122122
}
123123

@@ -128,7 +128,7 @@ void testNullList() {
128128

129129
@Test
130130
void testNullRhs() {
131-
assertThrows(NullPointerException.class,
131+
assertNullPointerException(
132132
() -> new DiffResult<>(SIMPLE_TRUE, null, SIMPLE_TRUE.diff(SIMPLE_FALSE).getDiffs(), SHORT_STYLE, DiffBuilder.TO_STRING_FORMAT));
133133
}
134134

src/test/java/org/apache/commons/lang3/function/FailableFunctionsTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,9 @@ void testBiPredicateAnd() throws Throwable {
734734
assertFalse(FailableBiPredicate.FALSE.and(FailableBiPredicate.TRUE).test(null, null));
735735
assertFalse(FailableBiPredicate.FALSE.and(FailableBiPredicate.FALSE).test(null, null));
736736
// null tests
737-
assertThrows(NullPointerException.class,
737+
assertNullPointerException(
738738
() -> assertFalse(FailableBiPredicate.falsePredicate().and(null).test(null, null)));
739-
assertThrows(NullPointerException.class,
739+
assertNullPointerException(
740740
() -> assertTrue(FailableBiPredicate.truePredicate().and(null).test(null, null)));
741741
}
742742

@@ -755,9 +755,9 @@ void testBiPredicateOr() throws Throwable {
755755
assertTrue(FailableBiPredicate.FALSE.or(FailableBiPredicate.TRUE).test(null, null));
756756
assertFalse(FailableBiPredicate.FALSE.or(FailableBiPredicate.FALSE).test(null, null));
757757
// null tests
758-
assertThrows(NullPointerException.class,
758+
assertNullPointerException(
759759
() -> assertFalse(FailableBiPredicate.falsePredicate().or(null).test(null, null)));
760-
assertThrows(NullPointerException.class,
760+
assertNullPointerException(
761761
() -> assertTrue(FailableBiPredicate.truePredicate().or(null).test(null, null)));
762762
}
763763

@@ -823,9 +823,9 @@ void testDoublePredicateAnd() throws Throwable {
823823
assertFalse(FailableDoublePredicate.FALSE.and(FailableDoublePredicate.TRUE).test(0));
824824
assertFalse(FailableDoublePredicate.FALSE.and(FailableDoublePredicate.FALSE).test(0));
825825
// null tests
826-
assertThrows(NullPointerException.class,
826+
assertNullPointerException(
827827
() -> assertFalse(FailableDoublePredicate.falsePredicate().and(null).test(0)));
828-
assertThrows(NullPointerException.class,
828+
assertNullPointerException(
829829
() -> assertTrue(FailableDoublePredicate.truePredicate().and(null).test(0)));
830830
}
831831

@@ -844,9 +844,9 @@ void testDoublePredicateOr() throws Throwable {
844844
assertTrue(FailableDoublePredicate.FALSE.or(FailableDoublePredicate.TRUE).test(0));
845845
assertFalse(FailableDoublePredicate.FALSE.or(FailableDoublePredicate.FALSE).test(0));
846846
// null tests
847-
assertThrows(NullPointerException.class,
847+
assertNullPointerException(
848848
() -> assertFalse(FailableDoublePredicate.falsePredicate().or(null).test(0)));
849-
assertThrows(NullPointerException.class,
849+
assertNullPointerException(
850850
() -> assertTrue(FailableDoublePredicate.truePredicate().or(null).test(0)));
851851
}
852852

@@ -1270,9 +1270,9 @@ void testIntPredicateAnd() throws Throwable {
12701270
assertFalse(FailableIntPredicate.FALSE.and(FailableIntPredicate.TRUE).test(0));
12711271
assertFalse(FailableIntPredicate.FALSE.and(FailableIntPredicate.FALSE).test(0));
12721272
// null tests
1273-
assertThrows(NullPointerException.class,
1273+
assertNullPointerException(
12741274
() -> assertFalse(FailableIntPredicate.falsePredicate().and(null).test(0)));
1275-
assertThrows(NullPointerException.class,
1275+
assertNullPointerException(
12761276
() -> assertTrue(FailableIntPredicate.truePredicate().and(null).test(0)));
12771277
}
12781278

@@ -1291,9 +1291,9 @@ void testIntPredicateOr() throws Throwable {
12911291
assertTrue(FailableIntPredicate.FALSE.or(FailableIntPredicate.TRUE).test(0));
12921292
assertFalse(FailableIntPredicate.FALSE.or(FailableIntPredicate.FALSE).test(0));
12931293
// null tests
1294-
assertThrows(NullPointerException.class,
1294+
assertNullPointerException(
12951295
() -> assertFalse(FailableIntPredicate.falsePredicate().or(null).test(0)));
1296-
assertThrows(NullPointerException.class,
1296+
assertNullPointerException(
12971297
() -> assertTrue(FailableIntPredicate.truePredicate().or(null).test(0)));
12981298
}
12991299

src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ void testGetAccessiblePublicMethodFromDescription() {
508508

509509
@Test
510510
void testGetAnnotationIllegalArgumentException1() {
511-
assertThrows(NullPointerException.class,
511+
assertNullPointerException(
512512
() -> MethodUtils.getAnnotation(FieldUtilsTest.class.getDeclaredMethods()[0], null, true, true));
513513
}
514514

@@ -668,7 +668,7 @@ void testGetMatchingMethod() throws NoSuchMethodException {
668668
assertEquals(GetMatchingMethodImpl.class.getMethod("testMethod6"),
669669
MethodUtils.getMatchingMethod(GetMatchingMethodImpl.class, "testMethod6"));
670670

671-
assertThrows(NullPointerException.class,
671+
assertNullPointerException(
672672
() -> MethodUtils.getMatchingMethod(null, "testMethod5", RuntimeException.class));
673673
}
674674

@@ -1032,9 +1032,9 @@ void testInvokeMethodForceAccessWithArgs() throws Exception {
10321032
assertEquals("privateStringStuff(String)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", "Hi There"));
10331033
assertEquals("privateStringStuff(Object)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", new Date()));
10341034

1035-
assertThrows(NullPointerException.class,
1035+
assertNullPointerException(
10361036
() -> MethodUtils.invokeMethod(null, true, "privateStringStuff", "Hi There"));
1037-
assertThrows(NullPointerException.class,
1037+
assertNullPointerException(
10381038
() -> MethodUtils.invokeMethod(testBean, true, null, "Hi There"));
10391039
}
10401040

0 commit comments

Comments
 (0)