Skip to content
Browse files

Reused HasWrongExpectedException instead of own defined class

(they were the same) and relocated the changes to a better location
in the file which is more inline with the rest of the file. And,
of course, removed the superfluous brackets.
  • Loading branch information...
2 parents 2cd3988 + 9995466 commit bd6dc3aff19a3d8e8e555d16a05a42557a755e0a @arjenw committed Jan 4, 2012
Showing with 12 additions and 25 deletions.
  1. +12 −25 src/test/java/org/junit/tests/experimental/rules/ExpectedExceptionRuleTest.java
View
37 src/test/java/org/junit/tests/experimental/rules/ExpectedExceptionRuleTest.java
@@ -57,50 +57,37 @@ public void throwsNullPointerException() {
}
}
- public static class ExpectedExceptionClause {
- @Rule
- public ExpectedException thrown= ExpectedException.none();
-
- @Test
- public void throwsNullPointerException() {
- thrown.expect(NullPointerException.class);
- throw new IllegalArgumentException();
- }
+ @Test
+ public void unExpectedExceptionFails() {
+ assertThat(
+ testResult(HasWrongExpectedException.class),
+ hasSingleFailureContaining("Expected: an instance of java.lang.NullPointerException"));
}
-
+
public static class CauseMatcher extends TypeSafeMatcher<Result> {
private final Class<? extends Throwable> causeClass;
- public CauseMatcher(final Class<? extends Throwable> causeClass) {
+ public CauseMatcher(Class<? extends Throwable> causeClass) {
this.causeClass= causeClass;
}
- public void describeTo(final Description description) {
- description.appendText("cause an instanceof ").appendText(causeClass.getName());
+ public void describeTo(Description description) {
+ description.appendText("cause being an instanceof ").appendText(causeClass.getName());
}
@Override
- public boolean matchesSafely(final Result item) {
+ public boolean matchesSafely(Result item) {
for(Failure f: item.getFailures())
- {
return CoreMatchers.instanceOf(causeClass).matches(f.getException().getCause());
- }
return false;
}
}
@Test
public void expectedExceptionClauseExists() {
- assertThat(new JUnitCore().run(ExpectedExceptionClause.class),
+ assertThat(new JUnitCore().run(HasWrongExpectedException.class),
new CauseMatcher(IllegalArgumentException.class));
- }
-
- @Test
- public void unExpectedExceptionFails() {
- assertThat(
- testResult(HasWrongExpectedException.class),
- hasSingleFailureContaining("Expected: an instance of java.lang.NullPointerException"));
- }
+ }
public static class HasWrongMessage {
@Rule

0 comments on commit bd6dc3a

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