mockito-kotlin icon indicating copy to clipboard operation
mockito-kotlin copied to clipboard

wheneverBlocking confuses with similar stub methods

Open 07jasjeet opened this issue 1 year ago • 0 comments

Introduction

In the below screen shot, there are 3 stub methods which are almost same but differ in parameters supplied.

image

Problem

When a call to 2nd stub (testUsername) is executed, result of 3rd stub (testFamiliarUser) is returned. This is the main issue.

Variables

testUsername = "Jasjeet", testFamiliarUser = "Jasjeettest", testSomeOtherUser = "SomeOtherUser"

Analysis

  • When the 3rd stub is removed, the stub works as expected.

  • When the 1st stub is removed, the 3rd stub is again executed.

  • When 2nd stub (our target) is removed, rest of the stubs work fine as expected.

  • Now this is where things get interesting. When 2nd stub (with testUsername) and 3rd stub (with testFamiliarUser) interchange places, the stub with testUsername starts working but breaks the previously 3rd stub (with testFamiliarUser).

  • When 1st stub and 2rd stub interchange places the error still remains as initially, i.e., 1st and 3rd stubs work but 2nd doesn't.

  • When a new stub is declared with parameter as "JasjeetTesttttt", the 2nd stub (testUsername or "Jasjeet") starts working woohoo, but sadly 3rd stub (testFamiliarUser or "JasjeetTest") breaks and when called, result of 4th stub (the one we just declared) is returned.

  • Finally, according to my analysis, the problem occurs with stubs that have somewhat similar parameters. The stub that is declared second last in not considered, rest all are considered.

07jasjeet avatar Jul 12 '23 17:07 07jasjeet