Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-39362

Build test classpath is inconsistent: mockito-all clashes with hamcrest-core

XMLWordPrintable

      Trying to implement semantically improved unit test results in a runtime error:

      mvn test -Dtest=MatcherTest -Dconcurrency=1 -DtrimStackTrace=false
      
      -------------------------------------------------------------------------------
      Test set: hudson.plugins.promoted_builds.MatcherTest
      -------------------------------------------------------------------------------
      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.068 sec <<< FAILURE! - in hudson.plugins.promoted_builds.MatcherTest
      test(hudson.plugins.promoted_builds.MatcherTest)  Time elapsed: 0.008 sec  <<< ERROR!
      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 hudson.plugins.promoted_builds.MatcherTest.test(MatcherTest.java:14)
      
      package hudson.plugins.promoted_builds;
      
      import org.hamcrest.BaseMatcher;
      import org.hamcrest.Description;
      import org.junit.Test;
      
      import static org.junit.Assert.assertThat;
      
      public class MatcherTest {
          @Test
          public void test() throws Throwable {
              // object to perform assertion against
              final Object actual = new Object();
              assertThat(actual, new BaseMatcher() {
                  @Override
                  public void describeTo(Description description) {
                      description.appendText("custom description");
                  }
                  @Override
                  public boolean matches(Object item) {
                      // for demonstration purpose
                      return false;
                  }
              });
          }
      }
      

      This is caused by org.hamcrest.Matcher being provided by both hamcrest-core:1.3 and mockito-all:1.8.5

      Workaround: give up creating semantically improved assertions and do low level assertions

            oleg_nenashev Oleg Nenashev
            fchuong Frédéric Chuong
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: