Я использую Mockito 1.9 с Grails 1.3.7, и у меня странная ошибка.
Следующий тестовый пример в Java работает:
import static org.mockito.Mockito.*;
public class MockitoTests extends TestCase {
@Test
public void testSomeVoidMethod(){
TestClass spy = spy(new TestClass());
doNothing().when(spy).someVoidMethod();
}
public static class TestClass {
public void someVoidMethod(){
}
}
}
Этот тест в Groovy не работает:
import static org.mockito.Mockito.*
public class MockitoTests extends TestCase {
public void testSomeVoidMethod() {
def testClassMock = spy(new TestClass())
doNothing().when(testClassMock).someVoidMethod()
}
}
public class TestClass{
public void someVoidMethod(){
}
}
Это сообщение об ошибке:
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:129)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:146)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
Кто-нибудь наблюдал такую же ошибку?