77 * @see Matcher#describeTo(Description)
88 */
99public interface Description {
10-
10+ /**
11+ * A description that consumes input but does nothing.
12+ */
13+ static final Description NONE = new NullDescription ();
14+
1115 /**
1216 * Appends some plain text to the description.
1317 */
1418 Description appendText (String text );
15-
19+
1620 /**
1721 * Appends the description of a {@link SelfDescribing} value to this description.
1822 */
1923 Description appendDescriptionOf (SelfDescribing value );
20-
24+
2125 /**
2226 * Appends an arbitary value to the description.
2327 */
2428 Description appendValue (Object value );
25-
29+
2630 /**
2731 * Appends a list of values to the description.
2832 */
@@ -34,11 +38,46 @@ <T> Description appendValueList(String start, String separator, String end,
3438 */
3539 <T > Description appendValueList (String start , String separator , String end ,
3640 Iterable <T > values );
37-
38- /**
41+
42+ /**
3943 * Appends a list of {@link org.hamcrest.SelfDescribing} objects
40- * to the description.
44+ * to the description.
4145 */
42- Description appendList (String start , String separator , String end ,
46+ Description appendList (String start , String separator , String end ,
4347 Iterable <? extends SelfDescribing > values );
48+
49+
50+ public static final class NullDescription implements Description {
51+ public Description appendDescriptionOf (SelfDescribing value ) {
52+ return this ;
53+ }
54+
55+ public Description appendList (String start , String separator ,
56+ String end , Iterable <? extends SelfDescribing > values ) {
57+ return this ;
58+ }
59+
60+ public Description appendText (String text ) {
61+ return this ;
62+ }
63+
64+ public Description appendValue (Object value ) {
65+ return this ;
66+ }
67+
68+ public <T > Description appendValueList (String start , String separator ,
69+ String end , T ... values ) {
70+ return this ;
71+ }
72+
73+ public <T > Description appendValueList (String start , String separator ,
74+ String end , Iterable <T > values ) {
75+ return this ;
76+ }
77+
78+ @ Override
79+ public String toString () {
80+ return "" ;
81+ }
82+ }
4483}
0 commit comments