mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-15 00:14:28 -04:00
Use the correct information when throwing Exceptions for failed tests. (#1927)
* Use the correct information when throwing Exceptions for failed tests. * Re-throw the exception if it is already a RuntimeException * Use pattern matching instead of casting
This commit is contained in:
parent
9481101883
commit
c5d03bcd0e
1 changed files with 8 additions and 2 deletions
|
@ -102,8 +102,14 @@ public final class FabricGameTestHelper {
|
|||
public static void invokeTestMethod(TestContext testContext, Method method, Object testObject) {
|
||||
try {
|
||||
method.invoke(testObject, testContext);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException("Failed to invoke test method (%s) in (%s)".formatted(method.getName(), method.getDeclaringClass().getCanonicalName()), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException("Failed to invoke test method (%s) in (%s) because %s".formatted(method.getName(), method.getDeclaringClass().getCanonicalName(), e.getMessage()), e);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof RuntimeException runtimeException) {
|
||||
throw runtimeException;
|
||||
} else {
|
||||
throw new RuntimeException(e.getCause());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue