Skip to content

Commit

Permalink
Extract isAnyExceptionExpected().
Browse files Browse the repository at this point in the history
Improve readability and avoid duplicate code.
  • Loading branch information
stefanbirkner committed Oct 16, 2013
1 parent bb13b31 commit 8b35f0c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/junit/rules/ExpectedException.java
Expand Up @@ -232,20 +232,24 @@ public void evaluate() throws Throwable {
handleException(e);
return;
}
if (fMatcherBuilder.expectsThrowable()) {
if (isAnyExceptionExpected()) {
failDueToMissingException();
}
}
}

private void handleException(Throwable e) throws Throwable {
if (fMatcherBuilder.expectsThrowable()) {
if (isAnyExceptionExpected()) {
assertThat(e, fMatcherBuilder.build());
} else {
throw e;
}
}

private boolean isAnyExceptionExpected() {
return fMatcherBuilder.expectsThrowable();
}

private void failDueToMissingException() throws AssertionError {
fail(missingExceptionMessage());
}
Expand Down

0 comments on commit 8b35f0c

Please sign in to comment.