Skip to content

Commit b9017fc

Browse files
committed
Remove hard references to OpenTest4J in AbstractCompilersProvider.java
This removes the hard requirement on the opentest4j module at runtime for users making use of junit5 functionality. Signed-off-by: Ashley <73482956+ascopes@users.noreply.github.com>
1 parent 506eb27 commit b9017fc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.junit.jupiter.params.provider.Arguments;
3434
import org.junit.jupiter.params.provider.ArgumentsProvider;
3535
import org.junit.jupiter.params.support.AnnotationConsumer;
36-
import org.opentest4j.TestAbortedException;
3736

3837
/**
3938
* Base for defining a compiler-supplying arguments-provider for JUnit Jupiter parameterised test
@@ -252,9 +251,10 @@ private void applyConfigurers(JctCompiler compiler) {
252251

253252
try {
254253
configurer.configure(compiler);
254+
255255
} catch (Exception ex) {
256256
if (isTestAbortedException(ex)) {
257-
throw (TestAbortedException) ex;
257+
throw (RuntimeException) ex;
258258
}
259259

260260
throw new JctJunitConfigurerException(
@@ -272,6 +272,7 @@ private JctCompilerConfigurer<?> initializeConfigurer(
272272

273273
try {
274274
constructor = configurerClass.getDeclaredConstructor();
275+
275276
} catch (NoSuchMethodException ex) {
276277
throw new JctJunitConfigurerException(
277278
"No no-args constructor was found for configurer class " + configurerClass.getName(),
@@ -285,6 +286,7 @@ private JctCompilerConfigurer<?> initializeConfigurer(
285286
// If the module is not open to JCT, then we will get an InaccessibleObjectException that
286287
// we should wrap and rethrow.
287288
constructor.setAccessible(true);
289+
288290
} catch (InaccessibleObjectException ex) {
289291

290292
throw new JctJunitConfigurerException(
@@ -304,13 +306,13 @@ private JctCompilerConfigurer<?> initializeConfigurer(
304306

305307
try {
306308
return constructor.newInstance();
309+
307310
} catch (ReflectiveOperationException ex) {
308311
if (ex instanceof InvocationTargetException) {
309312
var target = ((InvocationTargetException) ex).getTargetException();
310313
if (isTestAbortedException(target)) {
311-
// XXX: Creates a circular reference, do we care? JVM should handle this for us.
312314
target.addSuppressed(ex);
313-
throw (TestAbortedException) target;
315+
throw (RuntimeException) target;
314316
}
315317
}
316318

@@ -327,9 +329,9 @@ private static <T> Class<T>[] emptyArray() {
327329
}
328330

329331
private static boolean isTestAbortedException(Throwable ex) {
330-
// Use string-based reflective lookup to prevent needing the modules loaded at runtime.
331-
// We don't actually need to cover junit4 or testng here since this package specifically deals
332-
// with JUnit5 only.
332+
// Use string-based reflective lookup to prevent needing the OpenTest4J modules loaded at
333+
// runtime. We don't need to cover JUnit4 or TestNG here since this package specifically
334+
// deals with JUnit5 only.
333335
return ex.getClass().getName().equals("org.opentest4j.TestAbortedException");
334336
}
335337
}

0 commit comments

Comments
 (0)