~ubuntu-branches/ubuntu/raring/libhamcrest1.2-java/raring

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-12-02 17:55:55 UTC
  • Revision ID: package-import@ubuntu.com-20111202175555-xuj86jbpi8mehr1o
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hamcrest.integration;
 
2
 
 
3
import junit.framework.TestCase;
 
4
import org.easymock.IArgumentMatcher;
 
5
import org.hamcrest.BaseMatcher;
 
6
import org.hamcrest.Description;
 
7
import static org.hamcrest.core.IsEqual.equalTo;
 
8
 
 
9
public class EasyMock2AdapterTest extends TestCase {
 
10
 
 
11
    public static interface InterfaceToMock {
 
12
        void doStuff(String name, int number);
 
13
    }
 
14
 
 
15
    public void testAdaptsHamcrestMatcherToEasyMockArgumentsMatcher() {
 
16
        IArgumentMatcher easyMockMatcher = new EasyMock2Adapter(equalTo("expected"));
 
17
        assertTrue("Should have matched", easyMockMatcher.matches("expected"));
 
18
        assertFalse("Should not have matched", easyMockMatcher.matches("unexpected"));
 
19
    }
 
20
 
 
21
    public void testDelegatesDescriptionToUnderlyingMatcher() {
 
22
        IArgumentMatcher easyMockMatcher = new EasyMock2Adapter(new BaseMatcher<Object>() {
 
23
            public boolean matches(Object o) {
 
24
                return false;
 
25
            }
 
26
 
 
27
            public void describeTo(Description description) {
 
28
                description.appendText("is like ");
 
29
                description.appendValue("cheese");
 
30
            }
 
31
        });
 
32
 
 
33
        StringBuffer buffer = new StringBuffer();
 
34
        easyMockMatcher.appendTo(buffer);
 
35
        assertEquals("is like \"cheese\"", buffer.toString());
 
36
    }
 
37
 
 
38
}