Trying to get code coverage with a “when” expression using Kover or Intellij Coverage Plugin. There are always extra branches that prevent you from achieving 100% coverage.
For example, the Intellij Coverage plugin and Kover show 9 branches:
private fun replaceGuid(guid: String): String {
return when (guid) {
"11" -> "11"
"22" -> "22"
"33" -> "33"
else -> guid
}
}
If you rewrite the condition using “if”, there will be 4 branches.
Is there any way to fix this without changing the code of the class being tested or modifying the bytecode?