1
1
package org .hamcrest ;
2
2
3
- import static org .hamcrest .AbstractMatcherTest .*;
4
- import static org .hamcrest .Matchers .equalTo ;
3
+ import static org .hamcrest .AbstractMatcherTest .assertDescription ;
4
+ import static org .hamcrest .AbstractMatcherTest .assertMatches ;
5
+ import static org .hamcrest .AbstractMatcherTest .assertMismatchDescription ;
5
6
import junit .framework .TestCase ;
6
7
8
+ import org .hamcrest .core .IsEqual ;
9
+
7
10
public class FeatureMatcherTest extends TestCase {
8
11
private final FeatureMatcher <Thingy , String > resultMatcher = resultMatcher ();
9
12
10
- public void testMatchesPartOfAnObject () {
11
- assertMatches ("feature" , resultMatcher , new Thingy ("bar" ));
12
- assertDescription ("Thingy with result \" bar\" " , resultMatcher );
13
- }
13
+ public void testMatchesPartOfAnObject () {
14
+ assertMatches ("feature" , resultMatcher , new Thingy ("bar" ));
15
+ assertDescription ("Thingy with result \" bar\" " , resultMatcher );
16
+ }
17
+
18
+ public void testMismatchesPartOfAnObject () {
19
+ assertMismatchDescription ("result was mismatch-description" , resultMatcher , new Thingy ("foo" ));
20
+ }
21
+
22
+ public void testDoesNotThrowNullPointerException () {
23
+ assertMismatchDescription ("was null" , resultMatcher , null );
24
+ }
25
+
26
+ public void testDoesNotThrowClassCastException () {
27
+ resultMatcher .matches (new ShouldNotMatch ());
28
+ StringDescription mismatchDescription = new StringDescription ();
29
+ resultMatcher .describeMismatch (new ShouldNotMatch (), mismatchDescription );
30
+ assertEquals ("was <ShouldNotMatch>" , mismatchDescription .toString ());
31
+ }
14
32
15
- public void testMismatchesPartOfAnObject () {
16
- assertMismatchDescription ("result was \" foo\" " , resultMatcher , new Thingy ("foo" ));
33
+
34
+ public static class Match extends IsEqual <String > {
35
+ public Match (String equalArg ) { super (equalArg ); }
36
+ @ Override public void describeMismatch (Object item , Description description ) {
37
+ description .appendText ("mismatch-description" );
17
38
}
18
-
19
- public void testDoesNotThrowNullPointerException () {
20
- assertMismatchDescription ("was null" , resultMatcher , null );
21
- }
22
-
23
- public void testDoesNotThrowClassCastException () {
24
- resultMatcher .matches (new ShouldNotMatch ());
25
- StringDescription mismatchDescription = new StringDescription ();
26
- resultMatcher .describeMismatch (new ShouldNotMatch (), mismatchDescription );
27
- assertEquals ("was <ShouldNotMatch>" , mismatchDescription .toString ());
28
- }
29
-
39
+ }
30
40
public static class Thingy {
31
41
private final String result ;
32
42
@@ -44,7 +54,7 @@ public static class ShouldNotMatch {
44
54
}
45
55
46
56
private static FeatureMatcher <Thingy , String > resultMatcher () {
47
- return new FeatureMatcher <Thingy , String >(equalTo ("bar" ), "Thingy with result" , "result" ) {
57
+ return new FeatureMatcher <Thingy , String >(new Match ("bar" ), "Thingy with result" , "result" ) {
48
58
@ Override
49
59
public String featureValueOf (Thingy actual ) {
50
60
return actual .getResult ();
0 commit comments