Skip to content

Commit 1c92047

Browse files
Remove usage of assertDoesNotThrow()
1 parent 423ca0e commit 1c92047

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

src/test/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImplTestCase.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import org.junit.jupiter.api.Test;
2323

24-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
25-
2624
public class JXPathContextReferenceImplTestCase {
2725

2826
/**
@@ -31,10 +29,12 @@ public class JXPathContextReferenceImplTestCase {
3129
@Test
3230
public void testInit() {
3331
final ContainerPointerFactory factory = new ContainerPointerFactory();
34-
assertDoesNotThrow(() -> JXPathContextReferenceImpl.addNodePointerFactory(factory));
35-
36-
while (JXPathContextReferenceImpl.removeNodePointerFactory(factory)) {
37-
// NOP
32+
try {
33+
JXPathContextReferenceImpl.addNodePointerFactory(factory);
34+
} finally {
35+
while (JXPathContextReferenceImpl.removeNodePointerFactory(factory)) {
36+
// NOP
37+
}
3838
}
3939
}
4040
}

src/test/java/org/apache/commons/jxpath/ri/StressTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import org.junit.jupiter.api.Test;
2222

23-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2423
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.fail;
2525

2626
/**
2727
* Test thread safety.
@@ -32,6 +32,7 @@ public class StressTest {
3232
private static final int THREAD_DURATION = 1000;
3333
private static JXPathContext context;
3434
private static int count;
35+
private static Throwable exception;
3536

3637
@Test
3738
public void testThreads() throws Throwable {
@@ -46,16 +47,25 @@ public void testThreads() throws Throwable {
4647
}
4748

4849
for (final Thread element : threadArray) {
49-
assertDoesNotThrow(() -> element.join(), "Interrupted");
50+
try {
51+
element.join();
52+
}
53+
catch (final InterruptedException e) {
54+
fail("Interrupted");
55+
}
56+
}
57+
58+
if (exception != null) {
59+
throw exception;
5060
}
5161
assertEquals(THREAD_COUNT * THREAD_DURATION, count, "Test count");
5262
}
5363

5464
private static final class StressRunnable implements Runnable {
5565
@Override
5666
public void run() {
57-
for (int j = 0; j < THREAD_DURATION; j++) {
58-
assertDoesNotThrow(() -> {
67+
for (int j = 0; j < THREAD_DURATION && exception == null; j++) {
68+
try {
5969
final double random = 1 + Math.random();
6070
final double sum =
6171
((Double) context.getValue("/ + " + random))
@@ -64,7 +74,10 @@ public void run() {
6474
synchronized (context) {
6575
count++;
6676
}
67-
});
77+
}
78+
catch (final Throwable t) {
79+
exception = t;
80+
}
6881
}
6982
}
7083
}

src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.junit.jupiter.api.BeforeEach;
3131
import org.junit.jupiter.api.Test;
3232

33-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
3433
import static org.junit.jupiter.api.Assertions.assertEquals;
3534
import static org.junit.jupiter.api.Assertions.assertThrows;
3635
import static org.junit.jupiter.api.Assertions.fail;
@@ -125,8 +124,13 @@ public static void callExampleMessageMethodAndAssertClassNotFoundJXPathException
125124
*/
126125
public static void callExampleMessageMethodAndAssertSuccess() {
127126
final JXPathContext context = JXPathContext.newContext(new Object());
128-
Object value = assertDoesNotThrow(() -> context.selectSingleNode(EXAMPLE_CLASS_NAME+".getMessage()"));
129-
assertEquals("an example class", value);
127+
Object value;
128+
try {
129+
value = context.selectSingleNode(EXAMPLE_CLASS_NAME+".getMessage()");
130+
assertEquals("an example class", value);
131+
} catch ( final Exception e ) {
132+
fail(e.getMessage());
133+
}
130134
}
131135

132136
/**
@@ -138,8 +142,18 @@ public static void callExampleMessageMethodAndAssertSuccess() {
138142
* to invoke.
139143
*/
140144
private void executeTestMethodUnderClassLoader(final ClassLoader cl, final String methodName) {
141-
Class testClass = assertDoesNotThrow(() -> cl.loadClass(TEST_CASE_CLASS_NAME));
142-
Method testMethod = assertDoesNotThrow(() -> testClass.getMethod(methodName, null));
145+
Class testClass = null;
146+
try {
147+
testClass = cl.loadClass(TEST_CASE_CLASS_NAME);
148+
} catch (final ClassNotFoundException e) {
149+
fail(e.getMessage());
150+
}
151+
Method testMethod = null;
152+
try {
153+
testMethod = testClass.getMethod(methodName, null);
154+
} catch (final SecurityException | NoSuchMethodException e) {
155+
fail(e.getMessage());
156+
}
143157

144158
try {
145159
testMethod.invoke(null, null);

0 commit comments

Comments
 (0)