Ajay
Ajay

Reputation: 485

Mocking of concrete class failing with Spock 2.0

Mocking of external concrete class fails with the below mentioned error.

java.lang.AbstractMethodError: Receiver class me.spike.LibraryTest does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject.

I've tried adding cglibs-nodep and objenesis but was not successful in getting to mock the concrete class.

The repository mentioned here has a failing test. The test itself nonsensical. The intent is to get the mock working.

MCVE - https://github.com/ajaydivakaran/spock_spike

Upvotes: 0

Views: 1242

Answers (2)

kriegaex
kriegaex

Reputation: 67287

Like I said in the other question, you should get rid of the Build Helper plugin because Maven will recognise your src/test/groovy automatically - at least, as long as your src/test/java is not completely empty. Moreover, the Surefire plugin is over-specified, like I also told you before. You should keep your build files small and only include what is needed.

But the real problem is that your Groovy Eclipse batch compiler is version 3.0.3 while you use Groovy version 2.5.11. Just downgrade that one dependency to fit your Groovy version, and your test runs normally. Or go the other way, upgrade Groovy and Spock to 3.0. Anyway, changing this line fixes your build:

<groovy-eclipse-batch.version>2.5.11-01</groovy-eclipse-batch.version>

Upvotes: 3

Marcin Zajączkowski
Marcin Zajączkowski

Reputation: 4126

While this is just a workaround, you may switch to gmavenplus to handle Groovy compilation instead of groovy-eclipse-compiler and then that test passes:

            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>1.8.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compileTests</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-all</artifactId>
                        <version>2.5.11</version>
                        <scope>runtime</scope>
                        <type>pom</type>
                    </dependency>
                </dependencies>
            </plugin>

It definitely seems to be Groovy Eclipse Compiler related. We don't test Spock with GEC, nor it is officially supported. That test fails also with Spock 1.3-groovy-2.5 (and GEC), so it is not a regression in 2.0. However, may be related to the "hacks" in JavaMockInterceptor and some issues with Groovy 3 - #1076.

You may report it in the Spock issue tracker, however, I don't know if it will be properly handled.

Upvotes: 3

Related Questions