Java 使用扩展抽象类的@Spy for Groovy类编写Mockito单元测试时出错

Java 使用扩展抽象类的@Spy for Groovy类编写Mockito单元测试时出错,java,groovy,mockito,junit5,Java,Groovy,Mockito,Junit5,当使用@Spy为扩展抽象类的Groovy类运行Mockito单元测试时,我面临一个问题。如果删除abstract或将父类创建为常规Java类,则不会发生此错误。可能是什么问题 abstract class ClassA { } @Component class ClassB extends ClassA { void validateBeforeCreate(String arg1, Object arg2)

当使用
@Spy
为扩展
抽象类的
Groovy
类运行
Mockito
单元
测试时,我面临一个问题。如果删除
abstract
或将父类创建为常规
Java
类,则不会发生此错误。可能是什么问题

    abstract class ClassA
    {
    }
    
    @Component
    class ClassB extends ClassA
    {
        void validateBeforeCreate(String arg1, Object arg2)
        {
            check(arg1, arg2)
        }
    
        protected void check(String arg1, Object arg2)
        {
            // some validation logic
        }
    }
    
    @ExtendWith(MockitoExtension)
    class ClassBTest
    {
        @Spy
        @InjectMocks
        private ClassB classB
    
        @Test
        void testValidateBeforeCreate_Success()
        {
            String arg1 = "test"
            Object arg2 = new Object()
    
            doNothing().when(classB).check(arg1, arg2)
    
            assertDoesNotThrow({ classB.validateBeforeCreate(arg1, arg2) } as Executable)
        }
    }


Groovy和Mockito的版本是什么?这对于其他人尝试复制非常重要。它可以通过Groovy 2.5.6和Mockito 2.24.5进行复制。Groovy和Mockito的版本是什么?这对于其他人尝试复制非常重要,可以使用Groovy 2.5.6和Mockito 2.24.5进行复制。
Only void methods can doNothing()!
Example of correct use of doNothing():
    doNothing().
    doThrow(new RuntimeException())
    .when(mock).someVoidMethod();
Above means:
someVoidMethod() does nothing the 1st time but throws an exception the 2nd time is called
org.mockito.exceptions.base.MockitoException: 
Only void methods can doNothing()!
Example of correct use of doNothing():
    doNothing().
    doThrow(new RuntimeException())
    .when(mock).someVoidMethod();
Above means:
someVoidMethod() does nothing the 1st time but throws an exception the 2nd time is called
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPogoSite(CallSiteArray.java:146)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:163)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135)
    at com.tr.cws.workflow.trigger.test.ClassBTest.testValidateBeforeCreate_Success(ClassBTest.groovy:25)