From f45cc7926f8005b4ec7bd7abbaa54b46474a877c Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 23 Jan 2020 10:18:40 +1100 Subject: [PATCH] Fix test exception handling --- .../src/main/java/io/quarkus/test/QuarkusUnitTest.java | 7 ++++++- .../java/io/quarkus/test/junit/QuarkusTestExtension.java | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java index 622d1898dc261..05d45ae4e1e63 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusUnitTest.java @@ -275,7 +275,12 @@ private void runExtensionMethod(ReflectiveInvocationContext invocationCo try { newMethod.setAccessible(true); newMethod.invoke(actualTestInstance, invocationContext.getArguments().toArray()); - } catch (IllegalAccessException | InvocationTargetException e) { + } catch (InvocationTargetException e) { + if (e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } + throw new RuntimeException(e.getCause()); + } catch (IllegalAccessException e) { throw new RuntimeException(e); } } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java index aa8901e03a242..2b2213a41ceb5 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java @@ -351,7 +351,12 @@ private void runExtensionMethod(ReflectiveInvocationContext invocationCo } newMethod.setAccessible(true); newMethod.invoke(actualTestInstance, invocationContext.getArguments().toArray()); - } catch (Exception e) { + } catch (InvocationTargetException e) { + if (e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } + throw new RuntimeException(e.getCause()); + } catch (IllegalAccessException | ClassNotFoundException e) { throw new RuntimeException(e); } }