kotest

How to achieve an effect of AssertJ's satisfiesAnyOf with KoTest?


With AssertJ you can say:

assertThat(list).satisfiesAnyOf(
    listParam -> assertThat(listParam).contains(Tags.SWEETS, Tags.HIGH),
    listParam -> assertThat(listParam).contains(Tags.SOUPS, Tags.RED)
);

How am I supposed to express the same with KoTest? Is there some meta-assertion which passes as soon as one of the internal assertions is successful?


Solution

  • You can use any, like:

    any {
      list.shouldContain(Tags.SWEETS, Tags.HIGH)
      list.shouldContain(Tags.SOUPS, Tags.RED)
    }
    

    or you could create a composite matcher that tests for either of the tags:

    list should contain(Tags.SWEETS, Tags.HIGH).or(contain(Tags.SOUPS, Tags.RED))