I got some samplecode from a college, imported the project and try to run the Tests: The method assertThat(Integer, Matcher) is ambiguous for the type MyClass
Every assertThat is marked red with the same error-message so i tried to write the simpliest test which describes the problem:
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
@Test
public void whenAssertThatThenItIsAmbiguous() {
List<String> list = Arrays.asList("A", "B", "C");
assertThat(list.size(), is(3));
}
after I scroll over assertThat I get the following message:
The method assertThat(Integer, Matcher<Integer>) is ambiguous for the type MyClass
I searched google and stackoverflow but couldn't find anybody with the same problem... Please help.
EDIT1:
Solution:
import static org.junit.Assert.*; // delete this line
Both org.junit.Assert
and org.hamcrest.MatcherAssert
declare assertThat(T, Matcher<T>)
. Choose to static-import one or the other, but not both, and you should be OK.