I'm testing a function with an external dependency inside of a tailrec function. The function returns an Either.
When mocking this dependency, I'm providing a single mock invocation. I get the following exception:
kotlin.NoWhenBranchMatchedException
Why is the exception occurring and how do I fix it?
The exception occurs because I'm only providing one invocation of the mock to Mockito. For the invocation of this
tailrecfunction, the function is executing twice, hence first going to the right case, then to the left, and causing the exception to be thrown since I'm not providing a left case mock.To fix the issue provide another invocation of the mock (another right case), causing the
tailrecto return up the call stack.