Mockito - 0 Matchers Expected, 1 Recorded (InvalidUseOfMatchersException)

前端 未结 3 484
离开以前
离开以前 2021-01-17 13:28

I\'m trying to mock up some mongo classes so that I don\'t need a connection (fairly standard stuff) but the following code gives me problems:

when(dbCollect         


        
相关标签:
3条回答
  • 2021-01-17 13:39

    I think your results are compatible with the result that would happen if dbCollection is not a Mockito-mock (or your method is static or final). That would mean that a matcher is being used where none can be used; hence the "0 matchers expected, 1 recorded".

    0 讨论(0)
  • 2021-01-17 13:56

    This same issue can be reproduced in Scala if you have default arguments. It may look like you're providing any() for every argument, but you should verify that the method definition doesn't have any default parameters which might be messing things up.

    0 讨论(0)
  • 2021-01-17 13:59

    Probably unrelated, but I encountered the same error when I spied a package private method. Changing it to public solved the issue for me.

    0 讨论(0)
提交回复
热议问题