Reputation: 809
How to check in a simpler way whether a string matches one of the given options?
List<String> OPTIONS = Arrays.asList("alpha", "beta", "gamma");
String text = "beta";
assertThat(OPTIONS.stream().anyMatch(o -> o.equals(text))).isTrue();
Upvotes: 0
Views: 1444
Reputation: 809
There is a built-in solution in AssertJ: org.assertj.core.api.AbstractAssert::isIn
@Test
public void testOneOf() {
List<String> OPTIONS = Arrays.asList("alpha", "beta", "gamma");
String text = "beta";
Assertions.assertThat(text)
.as("Should contain one value from OPTIONS")
.isIn(OPTIONS);
}
Upvotes: 2