I would like to check with Java Truth assertion library if any of the following statements is satisfied:
assertThat(strToCheck).startsWith("a");
assertThat(strToCheck).contains("123");
assertThat(strToCheck).endsWith("@");
In another word, I am checking if strToCheck
starts with a
OR contains the substring 123
, OR ends with @
. Aka, if any of the 3 conditions applies. I am just giving the assertions as an example.
Is there a way to do the logical OR assertion with Truth?
I know with Hamcrest, we could do something like:
assertThat(strToCheck, anyOf(startsWith("a"), new StringContains("123"), endsWith("@")));
assertTrue(strToCheck.startsWith("a") || strToCheck.contains("123") ||strToCheck.endsWith("@"));
You can do what you asked for with this single line only.