2

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?

Albert Scholtz
  • 337
  • 3
  • 15

1 Answers1

1

The exception occurs because I'm only providing one invocation of the mock to Mockito. For the invocation of this tailrec function, 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 tailrec to return up the call stack.

Albert Scholtz
  • 337
  • 3
  • 15