Skip to content

Commit

Permalink
Print all arguments in the invokeAndCheck's exception
Browse files Browse the repository at this point in the history
  • Loading branch information
lepestock committed Sep 30, 2020
1 parent 803cd35 commit e6fb6d0
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,19 @@ private void invokeAndCompareArrays(Method m, boolean expectedResult, Object arg
* returned value equals 'expectedResult'.
*/
private void invokeAndCheck(Method m, Object expectedResult, Object... args) throws Exception {
Object result = m.invoke(null, args);
if (!result.equals(expectedResult)) {
String message = "Result of '" + m.getName() + "' not equal to expected value.";
System.err.println(message);
System.err.println("Expected: " + Format.asLiteral(expectedResult));
System.err.println("Result: " + Format.asLiteral(result));
Object actualResult = m.invoke(null, args);
if (!actualResult.equals(expectedResult)) {
var nl = System.lineSeparator();
String message =
"Actual result of '" + m.getName() + "' is not equal to expected value." + nl +
"Expected: " + Format.asLiteral(expectedResult) + nl +
"Actual: " + Format.asLiteral(actualResult);

for (int i = 0; i < args.length; i++) {
System.err.println("Arg" + i + ": " + Format.asLiteral(args[i]));
message += nl + " Arg" + i + ": " + Format.asLiteral(args[i]);
}

System.err.println(message);
throw new RuntimeException(message);
}
}
Expand Down

0 comments on commit e6fb6d0

Please sign in to comment.