Skip to content

Commit 20e8b9c

Browse files
committed
add unit tests for BaseDescription, in preparation for attacking issue 184
1 parent d4f0296 commit 20e8b9c

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.hamcrest;
2+
3+
import junit.framework.TestCase;
4+
5+
public class BaseDescriptionTest extends TestCase {
6+
7+
private final StringBuilder result = new StringBuilder();
8+
9+
private final BaseDescription baseDescription = new BaseDescription() {
10+
@Override protected void append(char c) {
11+
result.append(c);
12+
}
13+
};
14+
15+
public void testDescribesAppendedNullValue() {
16+
baseDescription.appendValue(null);
17+
assertEquals("null", result.toString());
18+
}
19+
20+
public void testQuotesAppendedStringValue() {
21+
baseDescription.appendValue("foo");
22+
assertEquals("\"foo\"", result.toString());
23+
}
24+
25+
public void testQuotesAppendedCharacterValue() {
26+
baseDescription.appendValue('f');
27+
assertEquals("\"f\"", result.toString());
28+
}
29+
30+
public void testBracketsAppendedShortValue() {
31+
baseDescription.appendValue(Short.valueOf("2"));
32+
assertEquals("<2s>", result.toString());
33+
}
34+
35+
public void testBracketsAppendedLongValue() {
36+
baseDescription.appendValue(Long.valueOf("2"));
37+
assertEquals("<2L>", result.toString());
38+
}
39+
40+
public void testBracketsAppendedFloatValue() {
41+
baseDescription.appendValue(Float.valueOf("1.2"));
42+
assertEquals("<1.2F>", result.toString());
43+
}
44+
45+
public void testDescribesAppendedArrayValue() {
46+
baseDescription.appendValue(new String[] {"2", "3"});
47+
assertEquals("[\"2\", \"3\"]", result.toString());
48+
}
49+
50+
public void testBracketsAppendedObjectValue() {
51+
final Object value = new Object();
52+
baseDescription.appendValue(value);
53+
assertEquals("<" + value.toString() + ">", result.toString());
54+
}
55+
}

0 commit comments

Comments
 (0)