Skip to content

Commit

Permalink
Output "<no message>" instead of "null"
Browse files Browse the repository at this point in the history
... for AssertionErrors without a message.
  • Loading branch information
marcphilipp committed Dec 4, 2015
1 parent 2391a44 commit 856c132
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Expand Up @@ -48,12 +48,16 @@ public String getMessage() {
messageBuilder.append(String.format("%s%n", name));
int lastIndex = failures.size() - 1;
for (AssertionError failure : failures.subList(0, lastIndex)) {
messageBuilder.append(String.format("\t%s%n", failure.getMessage()));
messageBuilder.append(String.format("\t%s%n", nullSafeMessage(failure)));
}
messageBuilder.append('\t').append(failures.get(lastIndex).getMessage());
messageBuilder.append('\t').append(nullSafeMessage(failures.get(lastIndex)));
return messageBuilder.toString();
}

private String nullSafeMessage(AssertionError failure) {
return failure.getMessage() == null ? "<no message>" : failure.getMessage();
}

public List<AssertionError> getFailures() {
return Collections.unmodifiableList(failures);
}
Expand Down
Expand Up @@ -43,4 +43,13 @@ public void exceptionWithFailures() {
assertTrue(exception.hasFailures());
assertEquals(String.format("%s%n\t%s%n\t%s", "a name", "failure 1", "failure 2"), exception.getMessage());
}

@Test
public void exceptionWithNullMessageFailures() throws Exception {
MultipleFailuresException exception = new MultipleFailuresException("a name");
exception.addFailure(new AssertionError());
exception.addFailure(new AssertionError());

assertEquals(String.format("%s%n\t%s%n\t%s", "a name", "<no message>", "<no message>"), exception.getMessage());
}
}

0 comments on commit 856c132

Please sign in to comment.