Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit bd6dc3aff19a3d8e8e555d16a05a42557a755e0a 2 parents 2cd3988 + 9995466
@arjenw authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.