hamcrest matching on actual empty list fails with nosuchmethoderror

45 views Asked by At

Sometimes the actual asserted upon can be surprisingly different. A list can be empty while it was expected to contain something... what a surprise...

assertThat(new ArrayList<Integer>(), equalTo(singletonList(7)));
assertThat(new ArrayList<>(), not(Matchers.empty()));

both result in java.lang.NoSuchMethodError: 'void org.hamcrest.Matcher.describeMismatch(java.lang.Object, org.hamcrest.Description)'

(hamcrest 2.1 on jdk 14)

1

There are 1 answers

0
Adrian Herscu On

Added a dependency having transitive dependency on Hamcrest 1.1 -- excluded and now it works as expected.