Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Clee681 opened this issue Aug 4, 2016 · 3 comments
Closed

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

Clee681 opened this issue Aug 4, 2016 · 3 comments

Comments

@Clee681
Copy link

Clee681 commented Aug 4, 2016

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
Copy link
Contributor

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

@Clee681
Copy link
Author

Clee681 commented Aug 4, 2016

Will do @AlexeyBuzdin!

@AlexeyBuzdin
Copy link
Contributor

Thanks for the Pull-Request, merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants