Griffon
  1. Griffon
  2. GRIFFON-435

Spock Unit Tests With Closure definitions fail with java.lang.IllegalAccessError

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.4
    • Fix Version/s: 0.9.5-rc1
    • Component/s: plugins
    • Labels:
    • Environment:
      Linux
    • Number of attachments :
      0

      Description

      Spock UnitSpecs containing a closure fail. Here's an example case:

      package com.aussieswithtails.LyricManager
       
      import java.util.Comparator;
       
      import javax.swing.JTree;
      import javax.swing.tree.DefaultTreeModel;
       
      import com.aussieswithtails.lyricmanager.Artist;
      import com.aussieswithtails.lyricmanager.Release;
      import com.aussieswithtails.lyricmanager.Track;
      import com.aussieswithtails.lyricmanager.TrackSelectorController;
       
      import griffon.spock.*
       
      class TrackSelectorUnitSpec extends UnitSpec {
      	def "test"() {
      		def list = ["c", "d", "a"]
      			list.sort({a,b -> a <=> b})
      		expect:
      			list == ["a'"]
      	}
      }
      

      which returns the following errors:

      Running test com.aussieswithtails.LyricManager.TrackSelectorUnitSpec...
      test...FAILED
      2011-11-16 15:43:53,278 [main] ERROR StackTrace - Sanitizing stacktrace:
      java.lang.IllegalAccessError: tried to access class com.aussieswithtails.LyricManager.TrackSelectorUnitSpec$_$spock_feature_1_0_closure1 from class com.aussieswithtails.LyricManager.TrackSelectorUnitSpec
      	at com.aussieswithtails.LyricManager.TrackSelectorUnitSpec.test(TrackSelectorUnitSpec.groovy:19)
      2011-11-16 15:43:53,294 [main] ERROR StackTrace - Sanitizing stacktrace:
      java.lang.IllegalAccessError: tried to access class com.aussieswithtails.LyricManager.TrackSelectorUnitSpec$_$spock_feature_1_0_closure1 from class com.aussieswithtails.LyricManager.TrackSelectorUnitSpec
      	at com.aussieswithtails.LyricManager.TrackSelectorUnitSpec.test(TrackSelectorUnitSpec.groovy:19)
      

      Per Andres Almiray this is indicative of a classpath issue and can be solved by making the following changes (extending specification rather than UnitSpec and explicitly grabbing the Spock class):

      @Grab(group='org.spockframework', module='spock-core', version='0.5-groovy-1.8')
      import spock.lang.*
      
      class TrackSelectorUnitSpec extends Specification {
       def "test"() {
             def list = ["c", "d", "a"]
             list.sort({a,b -> a <=> b})
          expect:
             list == ["a", "c", "d"]
       }
      }
      

      My initial testing suggests that the grab may be unnecessary and the core issue is when extending UnitSpec

        Activity

        Hide
        Andres Almiray added a comment -

        Do not use griffon.spock.UnitSpec rather just use spock.lang.Specification. Version 0.5.1 provides a template that suggest the latter.

        Show
        Andres Almiray added a comment - Do not use griffon.spock.UnitSpec rather just use spock.lang.Specification . Version 0.5.1 provides a template that suggest the latter.

          People

          • Assignee:
            Andres Almiray
            Reporter:
            Stephen Nesbitt
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: