package net.ttddyy.dsproxy.test.hamcrest;

import net.ttddyy.dsproxy.test.QueryHolder;
import org.junit.Assert;
import org.junit.Test;

import static net.ttddyy.dsproxy.test.hamcrest.QueryHolderAssertions.query;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;

/**
 * @author Tadaya Tsuyukubo
 * @since 1.4
 */
public class QueryHolderTest {

    @Test
    public void testQuery() {
        QueryHolder queryHolder = new QueryHolder() {
            @Override
            public String getQuery() {
                return "foo";
            }
        };

        Assert.assertThat(queryHolder, query(is("foo")));
        Assert.assertThat(queryHolder, query(startsWith("f")));
    }

}

@@ -205,16 +205,74 @@
 .query;%0A
+import static org.assertj.core.api.Assertions.assertThat;%0A
 import s
@@ -350,16 +350,137 @@
 rtsWith;
+%0Aimport static org.junit.Assert.fail;%0Aimport static org.mockito.BDDMockito.given;%0Aimport static org.mockito.Mockito.mock;
 %0A%0A/**%0A *
@@ -633,58 +633,230 @@
 r = 
-new QueryHolder() %7B%0A            @Override
+mock(QueryHolder.class);%0A        given(queryHolder.getQuery()).willReturn(%22foo%22);%0A%0A        Assert.assertThat(queryHolder, query(is(%22foo%22)));%0A        Assert.assertThat(queryHolder, query(startsWith(%22f%22)));
 %0A    
+%7D%0A%0A
     
+@Test%0A
     
@@ -866,57 +866,151 @@
 lic 
-String getQuery() %7B%0A                r
+void testQueryMismatch() %7B%0A        QueryHolder queryHolder = mock(QueryHolder.class);%0A        given(queryHolder.getQuery()).willR
 eturn
- 
+(
 %22foo%22
-;
+);%0A
 %0A   
@@ -1018,26 +1018,18 @@
     
-    %7D%0A        %7D;%0A%0A
+try %7B%0A    
     
@@ -1077,80 +1077,205 @@
 is(%22
-foo%22)));%0A        Assert.assertThat(queryHolder, query(startsWith(%22f%22)));
+FOO%22)));%0A            fail(%22assertion should fail%22);%0A        %7D catch (AssertionError e) %7B%0A            assertThat(e).hasMessage(%22%5CnExpected: query is %5C%22FOO%5C%22%5Cn     but: query was %5C%22foo%5C%22%22);%0A        %7D
 %0A   

add failure message test