Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented the change now on org.junit.Assert.assertThat() as I think

that's a better place and has cleaner code than the original. Included
tests for both scenario's (assertThat as well as the ExpectedException).
  • Loading branch information...
commit 53929101b4d9606d92dfd8d52e87f5dda467d51a 1 parent 126b8eb
@arjenw authored
View
8 src/main/java/org/junit/Assert.java
@@ -787,7 +787,11 @@ public static void assertEquals(Object[] expecteds, Object[] actuals) {
description.appendText("\n got: ");
description.appendValue(actual);
description.appendText("\n");
- throw new java.lang.AssertionError(description.toString());
- }
+ java.lang.AssertionError assertionError= new java.lang.AssertionError(
+ description.toString());
+ if (actual instanceof Throwable)
+ assertionError.initCause((Throwable) actual);
+ throw assertionError;
+ }
}
}
View
10 src/main/java/org/junit/rules/ExpectedException.java
@@ -111,14 +111,8 @@ public void evaluate() throws Throwable {
} catch (Throwable e) {
if (fMatcher == null)
throw e;
- try {
- Assert.assertThat(e, fMatcher);
- } catch (AssertionError ae) {
- // add e as cause to have a complete error message in the
- // results
- ae.initCause(e);
- throw ae;
- }
+
+ Assert.assertThat(e, fMatcher);
return;
}
if (fMatcher != null)
View
11 src/test/java/org/junit/tests/assertion/AssertionTest.java
@@ -465,6 +465,17 @@ public void arraysDeclaredAsObjectAreComparedAsObjects() {
}
}
+ @Test public void assertThatIncludesActualException() {
+ Exception actual= new IllegalArgumentException();
+ Exception expected= new NullPointerException();
+
+ try {
+ assertThat(actual, equalTo(expected));
+ } catch (AssertionError e) {
+ assertEquals(actual, e.getCause());
+ }
+ }
+
@Test public void nullAndStringNullPrintCorrectError() {
try {
assertEquals(null, "null");
Please sign in to comment.
Something went wrong with that request. Please try again.