Skip to content

Commit 5146880

Browse files
author
joeretro
committed
Introduced Description interface that acts as a domain centric abstraction over StringBuffer
1 parent 5ad93aa commit 5146880

49 files changed

Lines changed: 120 additions & 883 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGES.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Packages moved from org.jmock.core.matcher to org.hamcrest.
1010
* Merged SelfDescribing into Matcher interface.
1111
* SelfDescribing.describe() no longer returns a StringBuffer. Simpler for users to implement.
12+
* Introduced Description interface that acts as a domain centric abstraction over StringBuffer.
1213

1314
[Library Changes]
1415
* Matchers categorised and broken into subpackages (core, collection, number, object, text).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.hamcrest;
2+
3+
public interface Description {
4+
Description append(String text);
5+
Description append(Object object);
6+
}

‎src/api/org/hamcrest/Matcher.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public interface Matcher {
1717
boolean match(Object o);
1818

1919
/**
20-
* Appends the description of this object to the buffer.
21-
*
22-
* @param buffer The buffer that the description is appended to.
20+
* Describes this matcher.
2321
*/
24-
void describeTo(StringBuffer buffer);
22+
void describeTo(Description description);
2523
}

‎src/integration/org/hamcrest/junit/MatcherAssert.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
package org.hamcrest.junit;
44

55
import org.hamcrest.Matcher;
6+
import org.hamcrest.Description;
7+
import org.hamcrest.internal.StringDescription;
68
import junit.framework.Assert;
79

810
public class MatcherAssert extends Assert {
911

1012
public void assertThat(Object actual, Matcher matcher) {
1113
if (!matcher.match(actual)) {
12-
StringBuffer message = new StringBuffer("\nExpected: ");
13-
matcher.describeTo(message);
14-
message.append("\n got : ").append(actual).append('\n');
15-
fail(message.toString());
14+
Description description = new StringDescription();
15+
description.append("\nExpected: ");
16+
matcher.describeTo(description);
17+
description.append("\n got : ").append(actual).append('\n');
18+
fail(description.toString());
1619
}
1720
}
1821

‎src/library/org/hamcrest/Formatting.java‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
*/
33
package org.hamcrest;
44

5+
import org.hamcrest.internal.StringDescription;
6+
57
import java.lang.reflect.Array;
68
import java.util.Collection;
79

@@ -23,9 +25,9 @@ public static String toReadableString(Object element) {
2325
} else if (element instanceof Float) {
2426
return "<" + element.toString() + "F>";
2527
} else if (element.getClass().isArray()) {
26-
StringBuffer buffer = new StringBuffer();
27-
join(element, buffer);
28-
return buffer.toString();
28+
Description description = new StringDescription();
29+
join(element, description);
30+
return description.toString();
2931
} else {
3032
return "<" + element.toString() + ">";
3133
}
@@ -61,24 +63,24 @@ private static String toJavaSyntax(char ch) {
6163
}
6264
}
6365

64-
public static void join(Object array, StringBuffer buf) {
66+
public static void join(Object array, Description buf) {
6567
join(array, buf, "[", "]");
6668
}
6769

68-
public static void join(Collection collection, StringBuffer buf, String prefix, String postfix) {
70+
public static void join(Collection collection, Description buf, String prefix, String postfix) {
6971
join(collection.toArray(), buf, prefix, postfix);
7072
}
7173

72-
public static void join(Collection collection, StringBuffer buf,
74+
public static void join(Collection collection, Description buf,
7375
String prefix, String separator, String postfix) {
7476
join(collection.toArray(), buf, prefix, separator, postfix);
7577
}
7678

77-
private static void join(Object array, StringBuffer buf, String prefix, String postfix) {
79+
private static void join(Object array, Description buf, String prefix, String postfix) {
7880
join(array, buf, prefix, ", ", postfix);
7981
}
8082

81-
public static void join(Object array, StringBuffer buf,
83+
public static void join(Object array, Description buf,
8284
String prefix, String separator, String postfix) {
8385
buf.append(prefix);
8486

‎src/library/org/hamcrest/collection/IsArrayContaining.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.hamcrest.collection;
22

33
import org.hamcrest.Matcher;
4+
import org.hamcrest.Description;
45

56
import java.lang.reflect.Array;
67

@@ -25,8 +26,8 @@ private boolean arrayContainsMatchingElement(Object array) {
2526
return false;
2627
}
2728

28-
public void describeTo(StringBuffer buffer) {
29-
buffer.append("an array containing ");
30-
elementMatcher.describeTo(buffer);
29+
public void describeTo(Description description) {
30+
description.append("an array containing ");
31+
elementMatcher.describeTo(description);
3132
}
3233
}

‎src/library/org/hamcrest/collection/IsCollectionContaining.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.hamcrest.collection;
22

33
import org.hamcrest.Matcher;
4+
import org.hamcrest.Description;
45

56
import java.util.Collection;
67
import java.util.Iterator;
@@ -26,8 +27,8 @@ private boolean collectionContainsMatchingElement(Collection collection) {
2627
return false;
2728
}
2829

29-
public void describeTo(StringBuffer buffer) {
30-
buffer.append("a collection containing ");
31-
elementMatcher.describeTo(buffer);
30+
public void describeTo(Description description) {
31+
description.append("a collection containing ");
32+
elementMatcher.describeTo(description);
3233
}
3334
}

‎src/library/org/hamcrest/collection/IsMapContaining.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.hamcrest.collection;
22

33
import org.hamcrest.Matcher;
4+
import org.hamcrest.Description;
45

56
import java.util.Iterator;
67
import java.util.Map;
@@ -31,11 +32,11 @@ public boolean match(Object o) {
3132
return false;
3233
}
3334

34-
public void describeTo(StringBuffer buffer) {
35-
buffer.append("map containing [");
36-
keyMatcher.describeTo(buffer);
37-
buffer.append("->");
38-
valueMatcher.describeTo(buffer);
39-
buffer.append("]");
35+
public void describeTo(Description description) {
36+
description.append("map containing [");
37+
keyMatcher.describeTo(description);
38+
description.append("->");
39+
valueMatcher.describeTo(description);
40+
description.append("]");
4041
}
4142
}

‎src/library/org/hamcrest/core/Always.java‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎src/library/org/hamcrest/core/And.java‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)