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.
本文标签:
版权声明:本文标题:spring boot - Why does Mockito @MockBean work, but @SpyBean throws InvalidUseOfMatchersException? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744666202a2618548.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论