Search code examples
javaunit-testinghamcrestjunit5

Cannot import assertThat method junit


I am using hamcrest and junit to perform the tests, I need to compare 2 maps that have the same items but in different order, so assertEquals does not work for me. I have already seen the answers that have been put to that, but I have not been able to import the required methods.

I am importing in the following way

import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertThat;

and then I try the next thing I've seen in the answers

assertThat(expectedMap, containsInAnyOrder(receivedMap));

but does not recognize the method assertThat, the IDE shows me a warning that asks me to create the method

IntelliJ error tooltip: "assertThat(java.util.Map,org.hamcrest.Matcher>>)"


Solution

  • Map does not implement Iterable. Thus, the method signature does not match with the inferred argument types Map<?> and Matcher<Iterable<?>>.