Java mock maker inline使其他模拟无法工作

Java mock maker inline使其他模拟无法工作,java,spring,junit,mockito,cglib,Java,Spring,Junit,Mockito,Cglib,我尝试了Mockito的mock-maker-inline“孵化”特性,以便能够模拟最后一个类(描述并讨论了问题)。此后,其他测试因以下原因而失败: org.mockito.exceptions.misusing.NotAMockException: Argument passed to when() is not a mock! Example of correct stubbing: doThrow(new RuntimeException()).when(mock).someMe

我尝试了Mockito的
mock-maker-inline
“孵化”特性,以便能够模拟最后一个类(描述并讨论了问题)。此后,其他测试因以下原因而失败:

org.mockito.exceptions.misusing.NotAMockException: 
Argument passed to when() is not a mock!
Example of correct stubbing:
    doThrow(new RuntimeException()).when(mock).someMethod();
当我定义一个由间谍抛出的异常时。 其中一项测试的相关代码:

在@Configuration类中:

@Bean
public MessagePersister messagePersister() {
    return Mockito.spy(new MessagePersister(...));
}
注意:MessagePersister由CGLIB代理

在测试班:

@Inject
private MessagePersister messagePersisterSpy;

@Test
public void exceptionInPersisterTest() {
    doThrow(new SomeException("exceptionFromTest")).doCallRealMethod()
            .when(messagePersisterSpy).persistMessages(any());
...
}
这种例外是可以理解的。
messagePersisterSpy
的类是
MessagePersister$$EnhancerBySpringCGLIB$$6c49f1e2
,但是如果我删除
mock maker inline
功能,我的间谍类是
MessagePersister$MockitoMock$515952708$$EnhancerBySpringCGLIB$$9523b504
,测试是绿色的

你知道这种干扰是从哪里来的吗?我能不能做点什么


谢谢大家!

我也有同样的问题。。。您最终能否找到解决方法/修复方案?任何反馈都将不胜感激。@teemoo对不起,我记不清了。由于我在项目中没有发现使用
mock-maker-inline
,我想我把它放在了一起,重新设计了测试/代码。