How to assert that some String contains at least one value from the List <String>?

Vadam :

I'm testing some UI functionality with Java and AssertJ. So when I receive some massive string from UI, I should verify if that String contains at least one predefined value from List<String>. It is easy to do opposite thing - verify if list contains at least once some String value but this is not my case. I can't find solution in standard methods.

public static final List<String> OPTIONS = Arrays.asList("Foo", "Bar", "Baz");

String text = "Just some random text with bar";

what I need is smth like this :

Assertions.assertThat(text)
                .as("Should contain at least one value from OPTIONS ")
                .containsAnyOf(OPTIONS)
JB Nizet :
.matches(s -> OPTIONS.stream().anyMatch(option -> s.contains(option)));

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=117175&siteId=1