cglib throws an IllegalArgumentException in some Spock tests when using spock.lang.MockingApi#Mock(java.lang.Class<T>)
:
13-Jul-2015 17:07:56 no.xxx.yyy.MyTest > Builds the info mapping lazily and once on the first lookup call FAILED
13-Jul-2015 17:07:56 java.lang.IllegalArgumentException
13-Jul-2015 17:07:56 at net.sf.cglib.proxy.BridgeMethodResolver.resolveAll(BridgeMethodResolver.java:61)
13-Jul-2015 17:07:56 at net.sf.cglib.proxy.Enhancer.emitMethods(Enhancer.java:911)
13-Jul-2015 17:07:56 at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:498)
13-Jul-2015 17:07:56 at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
13-Jul-2015 17:07:56 at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
13-Jul-2015 17:07:56 at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
13-Jul-2015 17:07:56 at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
13-Jul-2015 17:07:56 at org.spockframework.mock.runtime.ProxyBasedMockFactory$CglibMockFactory.createMock(ProxyBasedMockFactory.java:91)
13-Jul-2015 17:07:56 at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:49)
13-Jul-2015 17:07:56 at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:51)
13-Jul-2015 17:07:56 at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:44)
13-Jul-2015 17:07:56 at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:45)
13-Jul-2015 17:07:56 at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:281)
13-Jul-2015 17:07:56 at org.spockframework.lang.SpecInternals.MockImpl(SpecInternals.java:99)
13-Jul-2015 17:07:56 at no.xxx.yyy.MyTest.setup(MyTest.groovy:17)
Lines 15-18 of MyTest is only
def mockSupplier
def setup() {
mockSupplier = Mock(SomeSupplier)
}
This only happens with a couple of mocks, not all. One mock is of a public java class (which extends an abstract java class), the other of a default groovy class (which implements a java class). I haven’t been able to pinpoint why these two are special.