ctco / cukes

Cucumber DSL for testing RESTful Web Services
Apache License 2.0
112 stars 66 forks source link

Consider using "mockito-core" rather than "mockito-all" #47

Closed creeefs closed 8 years ago

creeefs commented 8 years ago

Hello again!

While debugging a NoSuchMethodError with @yegeniy and @iantabolt, I wanted to offer a suggestion to use the mockito-core library rather than mockito-all. mockito-all includes Hamcrest classes, which can clash with Hamcrest classes pulled in as a transitive dependency of JUnit 4.11+ (see below dependency tree for JUnit 4.12).

[INFO] \- junit:junit:jar:4.12:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.3:test

Specifically, cukes-rest version 0.2.13 uses mockito-all version 1.10.8, which includes old Hamcrest classes (I think from 1.1). Notice that the below 1.10.8 version of mockito-all's Hamcrest Matcher class is missing the describeMismatch method.

public interface Matcher<T> extends SelfDescribing {
  boolean matches(Object var1);
  // Missing describeMismatch method!!
  void _dont_implement_Matcher___instead_extend_BaseMatcher_();
}

This manifests itself in the following NoSuchMethodError exception when a test fails using JUnit 4.11+.

Scenario: currentTeam hydration                                                        # features/person.feature:2
Given queryParam "hydrate" is "currentTeam"                                            # GivenSteps.query_Param(String,String)
When the client performs GET request on /v1/people/8471675                             # WhenSteps.perform_Http_Request(String,String)
Then response contains property "people[0].currentTeam.teamName" with value "Penguins" # ThenSteps.response_Body_Contains_Property(String,String)
  java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
    at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
    at org.junit.Assert.assertThat(Assert.java:956)
    at org.junit.Assert.assertThat(Assert.java:923)
    at lv.ctco.cukesrest.internal.AssertionFacadeImpl.bodyContainsPathWithValue(AssertionFacadeImpl.java:103)
    at lv.ctco.cukesrest.internal.switches.SwitchedByInterceptor.invoke(SwitchedByInterceptor.java:33)
    at lv.ctco.cukesrest.internal.context.InflateContextInterceptor.invoke(InflateContextInterceptor.java:30)
    at lv.ctco.cukesrest.api.ThenSteps.response_Body_Contains_Property(ThenSteps.java:64)
    at ✽.Then response contains property "people[0].currentTeam.teamName" with value "Penguins"(features/person.feature:5)

When fixing the dependency, we get a much more helpful error message.

Scenario: currentTeam hydration                                                          # features/person.feature:2
  Given queryParam "hydrate" is "currentTeam"                                            # GivenSteps.query_Param(String,String)
  When the client performs GET request on /v1/people/8471675                             # WhenSteps.perform_Http_Request(String,String)
  Then response contains property "people[0].currentTeam.teamName" with value "Penguins" # ThenSteps.response_Body_Contains_Property(String,String)
    java.lang.AssertionError:
    Expected: Path people[0].currentTeam.teamName contains equal to ignoring type Penguins
         but: was null
      at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
      at org.junit.Assert.assertThat(Assert.java:956)
      at org.junit.Assert.assertThat(Assert.java:923)
      at lv.ctco.cukesrest.internal.AssertionFacadeImpl.bodyContainsPathWithValue(AssertionFacadeImpl.java:103)
      at lv.ctco.cukesrest.internal.switches.SwitchedByInterceptor.invoke(SwitchedByInterceptor.java:33)
      at lv.ctco.cukesrest.internal.context.InflateContextInterceptor.invoke(InflateContextInterceptor.java:30)
      at lv.ctco.cukesrest.api.ThenSteps.response_Body_Contains_Property(ThenSteps.java:64)
      at ✽.Then response contains property "people[0].currentTeam.teamName" with value "Penguins"(features/person.feature:5)
AlexeyBuzdin commented 8 years ago

Valid point @Clee861, thank you! Would be really grateful if you could send a Pull Request with the fix.

creeefs commented 8 years ago

Will do @AlexeyBuzdin!

AlexeyBuzdin commented 8 years ago

Thanks for the Pull-Request, merged.