Here's some code:
data class House(val line1: String)
data class Street(val house: House)
fun mapCheck(key : String) : House {
val map = mapOf("A" to Street(House("10 London Road")))
val street = map[key]
return street?.house ?: throw IllegalArgumentException("unknown key")
}
and here's a test for it (using Kotest and Junit 5)
@Test
fun mapTest() {
val factory = dpsServiceFactory()
factory.mapCheck("A").line1 shouldBe "10 London Road"
shouldThrow<java.lang.IllegalArgumentException> { factory.mapCheck("V") }
}
For this line return street?.house ?: throw IllegalArgumentException("unknown key") my jacoco coverage report says I only have 3 out of 4 conditions covered.
I'm confused by this. I can only see two conditions, the two I have catered for in the test. What's the condition I'm not testing for ?
Update - this only occurs in Kotlin 1.7.10, Jacoco reports full coverage in Kotlin 1.6.10.