What is the best way to assert that each element in a collection of strings contains a particular substring?
Something like
List<String> list = Arrays.asList("xyfoobar", "foobarxy", "xyfoobarxy");
assertThat(list, eachElementContains("foobar")); // pass
Something simple like:
list.forEach(string -> {
assertTrue(string.contains("foobar"));
});
This doesn't use Hamcrest matchers but has the same semantics.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With