Hamcrest Matcher Exception when using expect().log().all()

910 views
Skip to first unread message

Brad Wosmek

unread,
Jun 26, 2013, 4:24:17 PM6/26/13
to rest-a...@googlegroups.com
 If I execute the test:
    @Test
    public void testSimpleGet() {
        expect().log().all()
            .statusCode(200)
            .body("url", equalTo(this.BaseURL + "/get"))
            .body("headers.Accept-Encoding", equalTo("gzip,deflate"))
        .when()
            .get("http://httpbin.org/get");
     }

I receive this stack trace:
java.lang.NoSuchMethodError: org.hamcrest.core.IsInstanceOf.any(Ljava/lang/Class;)Lorg/hamcrest/Matcher;
    at org.hamcrest.Matchers.any(Matchers.java:224)
    at com.jayway.restassured.filter.log.ResponseLoggingFilter.<init>(ResponseLoggingFilter.java:94)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:198)
    at com.jayway.restassured.internal.ResponseLogSpecificationImpl.logWith(ResponseLogSpecificationImpl.groovy:85)
    at com.jayway.restassured.internal.ResponseLogSpecificationImpl.this$3$logWith(ResponseLogSpecificationImpl.groovy)
    at com.jayway.restassured.internal.ResponseLogSpecificationImpl$this$3$logWith.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
    at com.jayway.restassured.internal.ResponseLogSpecificationImpl.all(ResponseLogSpecificationImpl.groovy:45)
    at com.jayway.restassured.internal.ResponseLogSpecificationImpl.all(ResponseLogSpecificationImpl.groovy)
    at com.jayway.restassured.specification.LogSpecification$all.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at com.jayway.restassured.internal.ResponseLogSpecificationImpl.all(ResponseLogSpecificationImpl.groovy:41)
    at com.jayway.restassured.internal.ResponseLogSpecificationImpl.all(ResponseLogSpecificationImpl.groovy)
    at com.fpx.qa.rest.RestAssuredTest.testSimpleGet(RestAssuredTest.java:53)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.InvokeMethodRunnable.runOne(InvokeMethodRunnable.java:46)
    at org.testng.internal.InvokeMethodRunnable.run(InvokeMethodRunnable.java:37)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)
 
If I replace log().all() with log.ifError(), then the test passes with no exception.
   @Test
    public void testSimpleGet() {
        expect().log().ifError()
            .statusCode(200)
            .body("url", equalTo(this.BaseURL + "/get"))
            .body("headers.Accept-Encoding", equalTo("gzip,deflate"))
        .when()
            .get("http://httpbin.org/get");
     }

I've searched this group and all issues to see if anyone else has seen this issue and overcome it, but I've come up empty.  I've also tried several iterations of the code seen above.  The only iteration that seems significant is that this test passes with no exception with log().all() moved to the given line, which I understand returns the request details and not the response details.

  @Test
    public void testSimpleGet() {
        given().log().all()
        .expect()
            .statusCode(200)
            .body("url", equalTo(this.BaseURL + "/get"))
            .body("headers.Accept-Encoding", equalTo("gzip,deflate"))
        .when()
            .get("http://httpbin.org/get");
     }

jar versions:
rest-assured-common-1.8.1.jar
rest-assured-1.8.1.jar
hamcrest-core-1.2.1.jar
hamcrest-library-1.2.1.jar

There are numerous examples of this syntax in tutorials throughout the web, so I suspect I have some sort of environmental issue.  Has anyone seen this before and know of a solution?

Thanks,

Brad

Johan Haleby

unread,
Jun 27, 2013, 1:42:25 AM6/27/13
to rest-a...@googlegroups.com
Are you using Maven or are you using the zip file distribution provided from the webpage?

Regards,
/Johan




--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Brad Wosmek

unread,
Jun 27, 2013, 10:06:20 AM6/27/13
to rest-a...@googlegroups.com
I'm using Gradle, but using the mavenCentral repository for getting dependencies.

Regards,
Brad

Johan Haleby

unread,
Jun 28, 2013, 2:07:18 AM6/28/13
to rest-a...@googlegroups.com
It's quite possible that you depend on another framework that also uses Hamcrest but another version. Try moving RA to the top of your dependency list.

/Johan
Reply all
Reply to author
Forward
0 new messages