AssertContains on strings in jUnit
If you add in Hamcrest and JUnit4, you could do:
String x = "foo bar";
Assert.assertThat(x, CoreMatchers.containsString("foo"));
With some static imports, it looks a lot better:
assertThat(x, containsString("foo"));
The static imports needed would be:
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
use fest assert 2.0 whenever possible EDIT: assertj may have more assertions (a fork)
assertThat(x).contains("foo");