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

2
  • It is always good to provide and MCVE, kudos for that. But it does not mean that the question here should just be a stub linking off to GitHub. Commented May 20, 2020 at 10:08
  • @kriegaex feedback appreciated. What additional information would you recommend I have in the question asked? Commented May 20, 2020 at 10:48

2 Answers 2

3

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> 
Sign up to request clarification or add additional context in comments.

Comments

3

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.

1 Comment

I always use Spock with Groovy-Eclipse because it is a real Maven Compiler plugin, not an extra component which the user needs to configure to match the Maven lifecycle. The OP just used the wrong compiler version. ;-) The Spock manual or a sample project could explain how to use Groovy-Eclipse, though. Feel free to contact me if you need a sample.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.