~brian-thomason/+junk/hamcrest

« back to all changes in this revision

Viewing changes to hamcrest-unit-test/src/main/java/org/hamcrest/CustomTypeSafeMatcherTest.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:40:16 UTC
  • Revision ID: brian.thomason@canonical.com-20111220174016-g67bgjybqqhzuuxt
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hamcrest;
 
2
 
 
3
public class CustomTypeSafeMatcherTest extends AbstractMatcherTest {
 
4
    private static final String STATIC_DESCRIPTION = "I match non empty strings";
 
5
    private Matcher<String> customMatcher;
 
6
 
 
7
    @Override
 
8
    protected void setUp() throws Exception {
 
9
        customMatcher = new CustomTypeSafeMatcher<String>(STATIC_DESCRIPTION) {
 
10
            @Override
 
11
            public boolean matchesSafely(String item) {
 
12
                return false;
 
13
            }
 
14
 
 
15
            @Override
 
16
            public void describeMismatchSafely(String item, Description mismatchDescription) {
 
17
              mismatchDescription.appendText("an " + item);
 
18
            }
 
19
        };
 
20
    }
 
21
 
 
22
    public void testUsesStaticDescription() throws Exception {
 
23
        assertDescription(STATIC_DESCRIPTION, customMatcher);
 
24
    }
 
25
 
 
26
    public void testReportsMismatch() {
 
27
      assertMismatchDescription("an item", customMatcher, "item");
 
28
    }
 
29
 
 
30
    @Override
 
31
    protected Matcher<?> createMatcher() {
 
32
        return customMatcher;
 
33
    }
 
34
}