Why is my import of the containsString method not working?
intellij-idea, java, junit
Solution
I thought I had tried every worthwhile import statement already, but this one did the trick:
import static org.junit.matchers.JUnitMatchers.*;
Problem
I've written the simple Java script below in order to learn more about TDD, IntelliJ and Java itself. ``` import java.util.ArrayList; import java.util.List; import org.junit.Before; import org.junit.Test; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.junit.matchers.JUnitMatchers.both; public class JUnit_Dummy { private StringJoiner joiner; private List<String> strings; @Before public void setUp() throws Exception { strings = new ArrayList<String>(); joiner = new StringJoiner(); } .... @Test public void shouldContainBothStringsWhenListIsTwoStrings() { strings.add("one"); strings.add("two"); assertThat(joiner.join(strings), both(containsString("A")). and(containsString("B"))); } } _____________ import java.util.List; public class StringJoiner { public String join(List<String> strings) { if(strings.size() > 0) { return (strings.get(0); } return ""; } } ``` I'm trying to use the "containsString" method inside an assertion, but IntelliJ keeps telling me that it "cannot resolve method 'containsString(java.lang.String)". This despite the fact that the jUnit docs (http://junit.sourceforge.net/javadoc/org/junit/matchers/JUnitMatchers.html#containsString(java.lang.String)) tell me that this method does accept a String parameter. I've tried swapping out various import statements, including the following: ``` import static org.hamcrest.Matcher.containsString; import static org.hamcrest.Matcher.*; import static org.hamcrest.CoreMatchers.*; ``` The best that I get is a greyed-out import statement telling me that the import statement is unused. Not sure what the problem is, any help would be appreciated. UPDATE: Here is the exact compiler error: ``` java: cannot find symbol symbol: method containsString(java.lang.String) location: class JUnit_Dummy ```