The test below employs the strikt framework to first assert that the list contains a single pair satisfying first=="B" and then make an assertion on second of that pair.
@Test
fun `should verify that key occurs once and has expected value`() {
val listOfPairs = listOf("A" to 1, "B" to 2, "C" to 3, "C" to 3)
expectThat(listOfPairs).one { get { this.first }.isEqualTo("B") }
expectThat(listOfPairs).filter { it.first.equals("B") }.single().get { this.second }.isEqualTo(2)
}
Is there a way to fluently continue the first expectThat to include the second assertion?
I'm aware that it is debatable whether this is actually desirable, but what I really don't fancy is that to access the pair again in the second expectThat, I need to use a predicate instead of an assertion.
Given the return value of
onedoesn't expose any useful properties or methods, I think realistically you are looking at a custom assertion.This should fit the bill:
And sample tests: