Skip to content

Commit 670fc9f

Browse files
author
smgfreeman
committed
Cleaned up test failure message for MatcherAsert
1 parent 6ffcf36 commit 670fc9f

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

‎hamcrest-integration/src/main/java/org/hamcrest/MatcherAssert.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public static <T> void assertThat(String reason, T actual, Matcher<? super T> ma
1414
description.appendText(reason)
1515
.appendText("\nExpected: ")
1616
.appendDescriptionOf(matcher)
17-
.appendText("\n got: ")
18-
.appendValue(actual)
19-
.appendText("\nmismatch: ");
17+
.appendText("\n but: ");
2018
matcher.describeMismatch(actual, description);
2119

2220
throw new AssertionError(description.toString());

‎hamcrest-unit-test/src/main/java/org/hamcrest/MatcherAssertTest.java‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,48 @@ public class MatcherAssertTest extends TestCase {
99
public void testIncludesDescriptionOfTestedValueInErrorMessage() {
1010
String expected = "expected";
1111
String actual = "actual";
12-
13-
String expectedMessage = "identifier\nExpected: \"expected\"\n got: \"actual\"\n";
14-
12+
13+
String expectedMessage = "identifier\nExpected: \"expected\"\n but: was \"actual\"";
14+
1515
try {
1616
assertThat("identifier", actual, equalTo(expected));
1717
}
1818
catch (AssertionError e) {
1919
assertTrue(e.getMessage().startsWith(expectedMessage));
2020
return;
2121
}
22-
22+
2323
fail("should have failed");
2424
}
2525

2626
public void testDescriptionCanBeElided() {
2727
String expected = "expected";
2828
String actual = "actual";
29-
30-
String expectedMessage = "\nExpected: \"expected\"\n got: \"actual\"\n";
31-
29+
30+
String expectedMessage = "\nExpected: \"expected\"\n but: was \"actual\"";
31+
3232
try {
3333
assertThat(actual, equalTo(expected));
3434
}
3535
catch (AssertionError e) {
3636
assertTrue(e.getMessage().startsWith(expectedMessage));
3737
return;
3838
}
39-
39+
4040
fail("should have failed");
4141
}
42-
42+
4343
public void testCanTestBooleanDirectly() {
4444
assertThat("success reason message", true);
45-
45+
4646
try {
4747
assertThat("failing reason message", false);
4848
}
4949
catch (AssertionError e) {
5050
assertEquals("failing reason message", e.getMessage());
5151
return;
5252
}
53-
53+
5454
fail("should have failed");
5555
}
5656

0 commit comments

Comments
 (0)