I just started a new Gradle project. In my previous build.gradles I had been putting this:
compile 'org.codehaus.groovy:groovy-all:2.4.15'
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4'
... and also these dependencies:
testCompile 'net.bytebuddy:byte-buddy:1.6.11'
testCompile 'org.objenesis:objenesis:2.6'
By a process of trial and error I had found that Groovy 2.4.15 with these Bytebuddy and Objensis dependencies enabled me to mock BufferedReader
. This proved useful in a console application where I wanted to mock user input to the console. The "console handler" class thus has the following field/property:
def br = new BufferedReader( new InputStreamReader(System.in, 'UTF-8' ))
used as follows in the app class to get user console input:
String response = br.readLine().trim()
... meaning that Spock tests can do this sort of thing:
def 'prompt should show help on entering H'() {
given:
consoleHandler.br = Mock( BufferedReader )
consoleHandler.br.readLine() >> 'h'
i.e. simulate the entry of the letter h at the console.
... but it doesn't work with Groovy 2.5.3 and its matching Spock dependency: for this new project I put:
compile 'org.codehaus.groovy:groovy-all:2.5.3'
testCompile 'org.spockframework:spock-core:1.2-groovy-2.5'
... with the same ByteBuddy and Objenisis dependencies. I get the following test failure:
java.lang.IllegalArgumentException: Could not create type at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:140) at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) at org.spockframework.mock.runtime.ByteBuddyMockFactory.createMock(ByteBuddyMockFactory.java:41) at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:42) at org.spockframework.mock.runtime.JavaMockFactory.createInternal(JavaMockFactory.java:58) at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:38) at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:42) at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:46) at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:294) at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:284) at org.spockframework.lang.SpecInternals.MockImpl(SpecInternals.java:100) at core.FirstSpec.setup(first_tests.groovy:20)
Caused by: java.lang.NoSuchMethodError: net.bytebuddy.dynamic.loading.ClassInjector$UsingLookup.isAvailable()Z at org.spockframework.mock.runtime.ByteBuddyMockFactory.determineBestClassLoadingStrategy(ByteBuddyMockFactory.java:103) at org.spockframework.mock.runtime.ByteBuddyMockFactory.access$300(ByteBuddyMockFactory.java:27) at org.spockframework.mock.runtime.ByteBuddyMockFactory$1.call(ByteBuddyMockFactory.java:54) at org.spockframework.mock.runtime.ByteBuddyMockFactory$1.call(ByteBuddyMockFactory.java:43) at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138)
Any Groovy über-geeks out there?
Aucun commentaire:
Enregistrer un commentaire