Skip to content

Commit 868ddb5

Browse files
author
nat.pryce
committed
added appendDescriptionOf method to Description interface and added implementation to BaseDescription class, for issue 13
1 parent a4c0db1 commit 868ddb5

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ public Description appendText(String text) {
1616
append(text);
1717
return this;
1818
}
19-
19+
20+
public Description appendDescriptionOf(SelfDescribing value) {
21+
value.describeTo(this);
22+
return this;
23+
}
24+
2025
public Description appendValue(Object value) {
2126
if (value == null) {
2227
append("null");
@@ -66,14 +71,15 @@ public Description appendList(String start, String separator, String end, Iterab
6671

6772
private Description appendList(String start, String separator, String end, Iterator<? extends SelfDescribing> i) {
6873
boolean separate = false;
74+
6975
append(start);
7076
while (i.hasNext()) {
7177
if (separate) append(separator);
72-
i.next().describeTo(this);
78+
appendDescriptionOf(i.next());
7379
separate = true;
7480
}
7581
append(end);
76-
82+
7783
return this;
7884
}
7985

@@ -87,7 +93,7 @@ protected void append(String str) {
8793
append(str.charAt(i));
8894
}
8995
}
90-
96+
9197
protected abstract void append(char c);
9298

9399
private void toJavaSyntax(String unformatted) {

‎hamcrest-core/src/main/java/org/hamcrest/Description.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public interface Description {
1313
*/
1414
Description appendText(String text);
1515

16+
/**
17+
* Appends the description of a {@link SelfDescribing} value to this description.
18+
*/
19+
Description appendDescriptionOf(SelfDescribing value);
20+
1621
/**
1722
* Appends an arbitary value to the description.
1823
*/

0 commit comments

Comments
 (0)