Mockito Exception - when() requires an argument which has to be a method call on a mock

后端 未结 9 2335
终归单人心
终归单人心 2020-12-15 15:12

I have a very simple test case that is using Mockito and Spring Test framework. When I do

when(pcUserService.read(\"1\")).thenReturn(pcUser);
9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 15:59

    There's another possible reason for such error - sometimes IDE prefers to statically import Mockito.when() from another package:

    import static io.codearte.catchexception.shade.mockito.Mockito.when;
    

    vs

    import static org.mockito.Mockito.when; //should normally use this one
    

    The thing is 'when' from io.codearte package is compliant with org.mockito.Mockito.any() on compilation level, but fails during runtime with that exact same error message.

提交回复
热议问题