better error message in assumeSuccessful+assertSuccessful

This commit is contained in:
Michael Hoennig 2022-09-07 10:24:51 +02:00
parent 2afdb3c3d7
commit 18a3718c75
1 changed files with 2 additions and 6 deletions

View File

@ -133,19 +133,15 @@ public class JpaAttempt {
}
public JpaResult<T> assumeSuccessful() {
assumeThat(exception).as(getSensibleMessage(exception)).isNull();
assumeThat(exception).as(firstRootCauseMessageLineOf(exception)).isNull();
return this;
}
public JpaResult<T> assertSuccessful() {
assertThat(exception).as(getSensibleMessage(exception)).isNull();
assertThat(exception).as(firstRootCauseMessageLineOf(exception)).isNull();
return this;
}
private String getSensibleMessage(final RuntimeException exception) {
return exception != null ? NestedExceptionUtils.getRootCause(exception).getMessage() : null;
}
private String firstRootCauseMessageLineOf(final RuntimeException exception) {
final var rootCause = NestedExceptionUtils.getRootCause(exception);
return Optional.ofNullable(rootCause)