Fix NPE when using assertFailedWith with an exception that does not have a message (such as an NPE or a TimeoutException)
@@ -37,9 +37,17 @@ public class AssertionHelper {
failure, expectedFailureType, getStackTrace(failure));
}
- if (expectedMessage != null && !failure.getMessage().contains(expectedMessage)) {
+ if (expectedMessage != null) {
+ final String msg = failure.getMessage();
+ if (msg == null) {
fail("%nReceived a failure event, but expecting:%n <%s>%nto contain:%n <%s>%nbut was:%n <%s>",
- failure.getMessage(), expectedMessage, getStackTrace(failure));
+ msg, expectedMessage, getStackTrace(failure));
+ } else {
+ if (!msg.contains(expectedMessage)) {
+ fail("%nReceived a failure event, but expecting:%n <%s>%nto contain:%n <%s>%nbut was:%n <%s>",
+ msg, expectedMessage, getStackTrace(failure));
+ }
+ }
}
}
