Skip to content
Browse files

Linear control flow in ExpectedExceptionStatement (refactoring)

  • Loading branch information...
1 parent ec1a5c3 commit e77e1c45e873aa9bc1e15db632180eb81d62d5e2 @marcphilipp marcphilipp committed Jul 20, 2012
Showing with 9 additions and 6 deletions.
  1. +9 −6 src/main/java/org/junit/rules/ExpectedException.java
View
15 src/main/java/org/junit/rules/ExpectedException.java
@@ -1,10 +1,12 @@
package org.junit.rules;
+import static junit.framework.Assert.fail;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.junit.internal.matchers.ThrowableCauseMatcher.hasCause;
import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
+import junit.framework.Assert;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.junit.internal.AssumptionViolatedException;
@@ -163,22 +165,23 @@ public ExpectedExceptionStatement(Statement base) {
public void evaluate() throws Throwable {
try {
fNext.evaluate();
+ if (fMatcherBuilder.expectsThrowable())
+ failDueToMissingException();
} catch (AssumptionViolatedException e) {
optionallyHandleException(e, handleAssumptionViolatedExceptions);
- return;
} catch (AssertionError e) {
optionallyHandleException(e, handleAssertionErrors);
- return;
} catch (Throwable e) {
handleException(e);
- return;
}
- if (fMatcherBuilder.expectsThrowable())
- throw new AssertionError("Expected test to throw "
- + StringDescription.toString(fMatcherBuilder.build()));
}
}
+ private void failDueToMissingException() throws AssertionError {
+ String expectation= StringDescription.toString(fMatcherBuilder.build());
+ fail("Expected test to throw " + expectation);
+ }
+
private void optionallyHandleException(Throwable e, boolean handleException)
throws Throwable {
if (handleException)

0 comments on commit e77e1c4

Please sign in to comment.
Something went wrong with that request. Please try again.