1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.csv;
18
19 import static org.hamcrest.core.AllOf.allOf;
20
21 import org.hamcrest.Description;
22 import org.hamcrest.Matcher;
23 import org.hamcrest.TypeSafeDiagnosingMatcher;
24
25
26
27
28 final class TokenMatchers {
29
30 public static Matcher<Token> hasContent(final String expectedContent) {
31 return new TypeSafeDiagnosingMatcher<Token>() {
32
33 @Override
34 public void describeTo(final Description description) {
35 description.appendText("token has content ");
36 description.appendValue(expectedContent);
37 }
38
39 @Override
40 protected boolean matchesSafely(final Token item,
41 final Description mismatchDescription) {
42 mismatchDescription.appendText("token content is ");
43 mismatchDescription.appendValue(item.content.toString());
44 return expectedContent.equals(item.content.toString());
45 }
46 };
47 }
48
49 public static Matcher<Token> hasType(final Token.Type expectedType) {
50 return new TypeSafeDiagnosingMatcher<Token>() {
51
52 @Override
53 public void describeTo(final Description description) {
54 description.appendText("token has type ");
55 description.appendValue(expectedType);
56 }
57
58 @Override
59 protected boolean matchesSafely(final Token item,
60 final Description mismatchDescription) {
61 mismatchDescription.appendText("token type is ");
62 mismatchDescription.appendValue(item.type);
63 return item.type == expectedType;
64 }
65 };
66 }
67
68 public static Matcher<Token> isReady() {
69 return new TypeSafeDiagnosingMatcher<Token>() {
70
71 @Override
72 public void describeTo(final Description description) {
73 description.appendText("token is ready ");
74 }
75
76 @Override
77 protected boolean matchesSafely(final Token item,
78 final Description mismatchDescription) {
79 mismatchDescription.appendText("token is not ready ");
80 return item.isReady;
81 }
82 };
83 }
84
85 public static Matcher<Token> matches(final Token.Type expectedType, final String expectedContent) {
86 return allOf(hasType(expectedType), hasContent(expectedContent));
87 }
88
89 }