Skip to content

Commit 6b01407

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
When falling back to plain AssertionError, still include the "expected" and "but was" lines.
I have no idea what I was thinking when I went out of my way to omit them in CL 353141904. And I think it had crossed my mind at one point to test the contents of the AssertionError, but I did not.... This CL does *not* address the main discussion of the day from #333 (comment); it's just *another* bug I noticed along the way. Sigh. RELNOTES=When JUnit 4 is excluded from the classpath, the `AssertionError` Truth generates as a substitute for `ComparisonFailure` now includes the expected and actual values that were missing in 1.1.1. PiperOrigin-RevId: 353319232
1 parent 2d65326 commit 6b01407

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

core/src/main/java/com/google/common/truth/FailureMetadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void failEqualityCheck(
193193
if (!isLinkageError(probablyJunitNotOnClasspath)) {
194194
throw probablyJunitNotOnClasspath;
195195
}
196-
failure = new AssertionErrorWithFacts(messages, concat(headFacts, tailFacts), cause);
196+
failure = new AssertionErrorWithFacts(messages, facts, cause);
197197
}
198198
doFail(failure);
199199
}

core/src/test/java/com/google/common/truth/NoJUnitTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020

21+
import com.google.common.collect.ImmutableList;
22+
2123
/** Truth-using binary to be run without JUnit on the classpath to verify that it still works. */
2224
public final class NoJUnitTest {
2325
public static void main(String[] args) {
2426
try {
2527
assertThat("a").isEqualTo("b");
2628
throw new Error("assertion should have failed");
2729
} catch (AssertionError expected) {
30+
ImmutableList<Fact> facts = ((AssertionErrorWithFacts) expected).facts();
31+
assertThat(facts.get(0).key).isEqualTo("expected");
32+
assertThat(facts.get(0).value).isEqualTo("b");
33+
assertThat(facts.get(1).key).isEqualTo("but was");
34+
assertThat(facts.get(1).value).isEqualTo("a");
2835
}
2936
}
3037

0 commit comments

Comments
 (0)