2
2
3
3
import org .junit .Test ;
4
4
5
+ import java .util .Arrays ;
6
+ import java .util .Iterator ;
7
+
5
8
import static org .junit .Assert .assertEquals ;
6
9
7
10
public final class BaseDescriptionTest {
@@ -14,63 +17,75 @@ public final class BaseDescriptionTest {
14
17
}
15
18
};
16
19
17
- @ Test public void
20
+ @ Test public void
18
21
describesAppendedNullValue () {
19
22
baseDescription .appendValue (null );
20
23
assertEquals ("null" , result .toString ());
21
24
}
22
25
23
- @ Test public void
26
+ @ Test public void
24
27
quotesAppendedStringValue () {
25
28
baseDescription .appendValue ("foo" );
26
29
assertEquals ("\" foo\" " , result .toString ());
27
30
}
28
31
29
- @ Test public void
32
+ @ Test public void
30
33
quotesAppendedCharacterValue () {
31
34
baseDescription .appendValue ('f' );
32
35
assertEquals ("\" f\" " , result .toString ());
33
36
}
34
37
35
- @ Test public void
38
+ @ Test public void
36
39
bracketsAppendedShortValue () {
37
40
baseDescription .appendValue (Short .valueOf ("2" ));
38
41
assertEquals ("<2s>" , result .toString ());
39
42
}
40
43
41
- @ Test public void
44
+ @ Test public void
42
45
bracketsAppendedLongValue () {
43
46
baseDescription .appendValue (Long .valueOf ("2" ));
44
47
assertEquals ("<2L>" , result .toString ());
45
48
}
46
49
47
- @ Test public void
50
+ @ Test public void
48
51
bracketsAppendedFloatValue () {
49
52
baseDescription .appendValue (Float .valueOf ("1.2" ));
50
53
assertEquals ("<1.2F>" , result .toString ());
51
54
}
52
55
53
- @ Test public void
56
+ @ Test public void
54
57
describesAppendedArrayValue () {
55
58
baseDescription .appendValue (new String [] {"2" , "3" });
56
59
assertEquals ("[\" 2\" , \" 3\" ]" , result .toString ());
57
60
}
58
61
59
- @ Test public void
62
+ @ Test
63
+ public void
64
+ describesAppendedIterableValue () {
65
+ baseDescription .appendValue (new Iterable <String >() {
66
+ @ Override
67
+ public Iterator <String > iterator () {
68
+ return Arrays .asList ("2" , "3" ).iterator ();
69
+ }
70
+ });
71
+ assertEquals ("<[\" 2\" , \" 3\" ]>" , result .toString ());
72
+ }
73
+
74
+ @ Test public void
60
75
bracketsAppendedObjectValue () {
61
76
final Object value = new Object ();
62
77
baseDescription .appendValue (value );
63
78
assertEquals ("<" + value .toString () + ">" , result .toString ());
64
79
}
65
-
66
- @ Test public void
80
+
81
+ @ Test public void
67
82
safelyDescribesAppendedValueOfObjectWhoseToStringThrowsAnException () {
68
83
final Object value = new Object () {
69
84
@ Override public String toString () {
70
85
throw new UnsupportedOperationException ();
71
86
}
72
87
};
73
-
88
+
74
89
final String expected = value .getClass ().getName () + "@" + Integer .toHexString (value .hashCode ());
75
90
baseDescription .appendValue (value );
76
91
assertEquals ("<" + expected + ">" , result .toString ());
0 commit comments