admin管理员组

文章数量:1390192

The code below throws

.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
0 matchers expected, 1 recorded

exception when mockRepository annotated with @SpyBean, but doesn't when I annotate it with @MockBean. The reason I want to use an ArgumentMatcher is that in other tests (such as a save operation), I can't know in advance what the object to be saved will be, so I would definitely need to use an any matcher for that.

    @Test
    public void gettingAllEntitiesFailed() throws InterruptedException {
        Mockito.when(mockitoRepository.customFindAll(eq(true))).thenThrow(RuntimeException.class);
        [...]
    }

The repository called mockitoRepository is an interface (with @Repository annotation), which extends a BaseRepository, which extends .springframework.data.repository.Repository. The BaseRepository has an implementation class: BaseRepositoryImpl. The mockitoRepository hasn't got its own impl class.

I've also tried the other "form" of mocking (the doThrow-when one), but the problem still persist. The interesting thing is that when I use true instead of eq(true) it works with @SpyBean too.

本文标签: