cyrusinnovation / mockito-groovy-support

A library for making Mockito work with Groovy
MIT License
34 stars 17 forks source link

Error while mocking #17

Open obesga-tirant opened 7 years ago

obesga-tirant commented 7 years ago

I can use mockito with groovy only with @CompileStatic classes I tried to use this library, but everytime I launch the test (compilestatic or not) this error ir thrown

With

compile 'org.codehaus.groovy:groovy-all:2.1.9'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.7.22'

Exception

java.lang.AbstractMethodError: com.cyrusinnovation.mockitogroovysupport.GroovyCglibMockMaker.isTypeMockable(Ljava/lang/Class;)Lorg/mockito/plugins/MockMaker$TypeMockability;

    at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
    at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
    at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:186)
    at org.mockito.internal.creation.MockSettingsImpl.confirm(MockSettingsImpl.java:180)
    at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
    at org.mockito.Mockito.mock(Mockito.java:1729)
    at org.mockito.Mockito.mock(Mockito.java:1642)
    at __myclass(__myclass.groovy:57)
rmchale commented 7 years ago

Any word on this? I get this with the following

 <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>2.8.47</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.cyrusinnovation</groupId>
            <artifactId>mockito-groovy-support</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
 <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.8</version>
        </dependency>
obesga-tirant commented 7 years ago

Sadly, I think this project is out. And I must admit I have not the time nor the resources to fix it.

:(

There is a 'native' groovy mock feature http://groovy-lang.org/testing.html#_mockfor_and_stubfor https://dzone.com/articles/mocking-static-methods-groovy https://gist.github.com/crazy4groovy/2979077

dougbacelar commented 7 years ago

This problem was already fixed on newer versions of Mockito.

If you can use the more recent versions of Mockito you do not need this project to make it work with Groovy—it should work out of the box. See https://github.com/mockito/mockito/issues/72#issuecomment-122256375

I am currently using Mockito 2.8.9 with Groovy 2.4.11 and it works just fine.

Not sure why the following happened to you:

I can use mockito with groovy only with @compilestatic classes

If you post stack trace and how to reproduce the issue, maybe we can help.