diff options
author | Jens Nyman <jnyman@google.com> | 2024-01-17 10:25:48 +0000 |
---|---|---|
committer | Jens Nyman <jnyman@google.com> | 2024-01-17 10:25:48 +0000 |
commit | 68c2a772720dbe8e926ab6b663566cb434769b98 (patch) | |
tree | 825825d4551a3e82be1af3428397e1f6317f08d4 /junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameter.java | |
parent | 616afa4d030631062a0f3c8854b44204f64a1d13 (diff) | |
download | TestParameterInjector-68c2a772720dbe8e926ab6b663566cb434769b98.tar.gz |
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
Diffstat (limited to 'junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameter.java')
-rw-r--r-- | junit4/src/main/java/com/google/testing/junit/testparameterinjector/TestParameter.java | 7 |
1 files changed, 7 insertions, 0 deletions
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); + } } } } |