diff --git a/tests/edu/caltech/cs2/helpers/Reflection.java b/tests/edu/caltech/cs2/helpers/Reflection.java index b8f4b24b4aced2de62dbd982bca025955900f73a..c52d4463bc63e871649b2af44e36b6be29fb21df 100644 --- a/tests/edu/caltech/cs2/helpers/Reflection.java +++ b/tests/edu/caltech/cs2/helpers/Reflection.java @@ -61,7 +61,13 @@ public class Reflection { try { result = (T) m.invoke(args[0], Arrays.copyOfRange(args, 1, args.length)); } catch (IllegalAccessException | InvocationTargetException e) { - fail(e.getCause()); + Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) { + throw (RuntimeException)e.getCause(); + } + else { + fail(cause); + } } return result; } @@ -72,7 +78,13 @@ public class Reflection { try { result = (T) m.invoke(null, args); } catch (IllegalAccessException | InvocationTargetException e) { - fail(e.getCause()); + Throwable cause = e.getCause(); + if (cause instanceof RuntimeException) { + throw (RuntimeException)e.getCause(); + } + else { + fail(cause); + } } return result; } @@ -98,16 +110,16 @@ public class Reflection { } private static int stringToIntModifier(String modifier) { - switch (modifier.toLowerCase()) { - case "private": return Modifier.PRIVATE; - case "public": return Modifier.PUBLIC; - case "protected": return Modifier.PROTECTED; - case "static": return Modifier.STATIC; - case "final": return Modifier.FINAL; - default: fail("Unknown modifier test."); - } - /* Should never reach here... */ - return -1; + switch (modifier.toLowerCase()) { + case "private": return Modifier.PRIVATE; + case "public": return Modifier.PUBLIC; + case "protected": return Modifier.PROTECTED; + case "static": return Modifier.STATIC; + case "final": return Modifier.FINAL; + default: fail("Unknown modifier test."); + } + /* Should never reach here... */ + return -1; } public static Predicate<Member> hasModifier(String modifier) { @@ -184,7 +196,7 @@ public class Reflection { } - public static void assertFieldsEqualTo(Class clazz, Class FieldType, int x) { + public static void assertFieldsEqualTo(Class clazz, Class FieldType, int x) { assertFieldsEqualTo(clazz, null, FieldType, x ); } public static void assertFieldsEqualTo(Class clazz, String modifier, int x) { @@ -338,4 +350,4 @@ public class Reflection { fail("You should be overriding the " + method + "method, but your signature wasn't correct."); } } -} +} \ No newline at end of file