0

For a scenario unit testing a user entering a password and password confirmation. when i try to verify the same method being called in a different on() block, i get the following error on the 2nd on()block.

org.mockito.exceptions.verification.TooManyActualInvocations: 
activationPasswordView.disableButton();
Wanted 1 time:
But was twice

Here is the code:

 given("user set password "){

        on(“password is null”){
         presenterImpl.validatePassword(null, null)

            it("done button should be disabled"){
                verify(view).disableButton()
            }
        }

        on("input only one password"){
          presenterImpl.validatePassword("Password", "")

            it("done button should be disabled"){
                verify(view).disableButton()
            }
        }
    }

But if i call a different method, it works correctly. I assume this was not how Spek framework was intended to be used as all the examples i have seen always use an Assert. Is there a way i can write the following conditions in Spek without the error?. Even a different given() still causes the error.

irobotxx
  • 5,963
  • 11
  • 62
  • 91

1 Answers1

0

The mocked object counts the number of times the function invoked for the specific mock. Since you did not reset the mock between each test, the counter is increased each time you invoked the method.

You should use: reset(view) to reset the mocks counter. This issue is not related to the Spek framework.

Nizan Ifrach
  • 131
  • 3