From 68c2a772720dbe8e926ab6b663566cb434769b98 Mon Sep 17 00:00:00 2001 From: Jens Nyman Date: Wed, 17 Jan 2024 10:25:48 +0000 Subject: TestParameterValuesProvider: Allow provideValues(Context) to throw any exception. This avoids the need for a try-catch when calling testClass.getDeclaredConstructor().newInstance() https://github.com/google/TestParameterInjector/issues/44 --- .../google/testing/junit/testparameterinjector/TestParameter.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameter.java') diff --git a/junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameter.java b/junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameter.java index 6272e44..992c259 100644 --- a/junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameter.java +++ b/junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameter.java @@ -244,6 +244,13 @@ public @interface TestParameter { } } catch (ReflectiveOperationException e) { throw new IllegalStateException(e); + } catch (Exception e) { + // Catch any unchecked exception that may come from `provideValues(Context)` + if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } else { + throw new IllegalStateException(e); + } } } } -- cgit v1.2.3