Skip to content

Commit 237b808

Browse files
author
nat.pryce
committed
applied the appendDescriptionOf method all over the place
1 parent 868ddb5 commit 237b808

File tree

17 files changed

+44
-70
lines changed

17 files changed

+44
-70
lines changed

hamcrest-core/src/main/java/org/hamcrest/BaseDescription.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private Description appendList(String start, String separator, String end, Itera
8484
}
8585

8686

87-
/** Append the <var>str</var> to the description.
87+
/** Append the String <var>str</var> to the description.
8888
* The default implementation passes every character to {@link #append(char)}.
8989
* Override in subclasses to provide an efficient implementation.
9090
*/
@@ -94,6 +94,8 @@ protected void append(String str) {
9494
}
9595
}
9696

97+
/** Append the char <var>c</var> to the description.
98+
*/
9799
protected abstract void append(char c);
98100

99101
private void toJavaSyntax(String unformatted) {

hamcrest-core/src/main/java/org/hamcrest/StringDescription.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ public StringDescription(Appendable out) {
2424
* @return
2525
* The description of the object.
2626
*/
27-
public static String toString(SelfDescribing selfDescribing) {
28-
StringDescription description = new StringDescription();
29-
selfDescribing.describeTo(description);
30-
return description.toString();
27+
public static String toString(SelfDescribing value) {
28+
return new StringDescription().appendDescriptionOf(value).toString();
3129
}
3230

3331
/**
@@ -37,7 +35,6 @@ public static String asString(SelfDescribing selfDescribing) {
3735
return toString(selfDescribing);
3836
}
3937

40-
4138
protected void append(String str) {
4239
try {
4340
out.append(str);

hamcrest-core/src/main/java/org/hamcrest/core/AllOf.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,7 @@ public boolean matches(Object o) {
2929
}
3030

3131
public void describeTo(Description description) {
32-
description.appendText("(");
33-
boolean seenFirst = false;
34-
for (Matcher<? extends T> matcher : matchers) {
35-
if (seenFirst) {
36-
description.appendText(" and ");
37-
} else {
38-
seenFirst = true;
39-
}
40-
matcher.describeTo(description);
41-
}
42-
description.appendText(")");
32+
description.appendList("(", " and ", ")", matchers);
4333
}
4434

4535
/**

hamcrest-core/src/main/java/org/hamcrest/core/AnyOf.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,7 @@ public boolean matches(Object o) {
3030
}
3131

3232
public void describeTo(Description description) {
33-
description.appendText("(");
34-
boolean seenFirst = false;
35-
for (Matcher<? extends T> matcher : matchers) {
36-
if (seenFirst) {
37-
description.appendText(" or ");
38-
} else {
39-
seenFirst = true;
40-
}
41-
matcher.describeTo(description);
42-
}
43-
description.appendText(")");
33+
description.appendList("(", " or ", ")", matchers);
4434
}
4535

4636
/**

hamcrest-core/src/main/java/org/hamcrest/core/Is.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ public boolean matches(Object arg) {
2727
}
2828

2929
public void describeTo(Description description) {
30-
description.appendText("is ");
31-
matcher.describeTo(description);
30+
description.appendText("is ").appendDescriptionOf(matcher);
3231
}
33-
32+
3433
/**
3534
* Decorates another Matcher, retaining the behavior but allowing tests
3635
* to be slightly more expressive.

hamcrest-core/src/main/java/org/hamcrest/core/IsNot.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public boolean matches(Object arg) {
2424
}
2525

2626
public void describeTo(Description description) {
27-
description.appendText("not ");
28-
matcher.describeTo(description);
27+
description.appendText("not ").appendDescriptionOf(matcher);
2928
}
3029

3130
/**

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ public static <T> void assertThat(T actual, Matcher<T> matcher) {
1111
public static <T> void assertThat(String reason, T actual, Matcher<T> matcher) {
1212
if (!matcher.matches(actual)) {
1313
Description description = new StringDescription();
14-
description.appendText(reason);
15-
description.appendText("\nExpected: ");
16-
matcher.describeTo(description);
17-
description.appendText("\n got: ").appendValue(actual).appendText("\n");
14+
description.appendText(reason)
15+
.appendText("\nExpected: ")
16+
.appendDescriptionOf(matcher)
17+
.appendText("\n got: ")
18+
.appendValue(actual)
19+
.appendText("\n");
20+
1821
throw new java.lang.AssertionError(description.toString());
1922
}
2023
}

hamcrest-integration/src/main/java/org/hamcrest/integration/EasyMock2Adapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,4 @@ public boolean matches(Object argument) {
3939
public void appendTo(StringBuffer buffer) {
4040
hamcrestMatcher.describeTo(new StringDescription(buffer));
4141
}
42-
4342
}

hamcrest-library/src/main/java/org/hamcrest/beans/HasPropertyWithValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void describeTo(Description description) {
102102
description.appendText("hasProperty(");
103103
description.appendValue(propertyName);
104104
description.appendText(", ");
105-
value.describeTo(description);
105+
description.appendDescriptionOf(value);
106106
description.appendText(")");
107107
}
108108

hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContaining.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ public boolean matchesSafely(T[] array) {
2424
}
2525

2626
public void describeTo(Description description) {
27-
description.appendText("an array containing ");
28-
elementMatcher.describeTo(description);
27+
description
28+
.appendText("an array containing ")
29+
.appendDescriptionOf(elementMatcher);
2930
}
3031

3132
@Factory

0 commit comments

Comments
 (0)