0

simple I thought

 Assert.assertThat(
                iterator.next(),
                Matchers.either(Matchers.nullValue()).or(
                        Matchers.instanceOf(Double.class)));

So I'd like to ensre next() returns one of two, NULL or instance of a Double. Sth like

Assert.assertTrue(next == null || next instanceof Double);

Test run (assertThat) outcomes in...

 java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
at org.hamcrest.core.CombinableMatcher.matchesSafely(CombinableMatcher.java:17)
at org.hamcrest.TypeSafeDiagnosingMatcher.matches(TypeSafeDiagnosingMatcher.java:55)
at org.junit.Assert.assertThat(Assert.java:772)
at org.junit.Assert.assertThat(Assert.java:738

Why? And how to fix?

EDIT

You were right, there was a collision with hamcrest lib comming from Mockito. I have it fixed. Ther's no error but the assertion fails strangely, take a look:

 java.lang.AssertionError: 
 Expected: (null or an instance of java.lang.Double)
 got: null
at org.junit.Assert.assertThat(Assert.java:780)
at org.junit.Assert.assertThat(Assert.java:738)

Null was expected, got null and a test is failing.

wilu
  • 549
  • 1
  • 12
  • 26
  • possible duplicate of [JMock- java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch()](http://stackoverflow.com/questions/12070514/jmock-java-lang-nosuchmethoderror-org-hamcrest-matcher-describemismatch) – David Harkness Dec 04 '12 at 22:40

2 Answers2

2

The NoSuchMethodError indicates an issue concerning the difference between the compile-time and runtime environment. A typical cause would be that you have a different version of a JAR at runtime. Maybe you have two Hamcrest JARs, but one takes precedence. Carefully check the compile-time and runtime classpaths.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
2

I suggest that you have multiple dependencies of Hamcrest that are in conflict. Check your build path / maven dependencies.

If you execute the search on java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch you will get the following list of entries for the exact same problem:

Did you search before posting this question?

The first result looks right to me:

First search result

Community
  • 1
  • 1
John B
  • 32,493
  • 6
  • 77
  • 98