On the Groovy "Using methodMissing and propertyMissing <http://groovy.codehaus.org/Using+methodMissing+and+propertyMissing>" page, it has this sample code:

   class Foo {defstorage = [:] defpropertyMissing(String name, value) {
   storage[name] = value } defpropertyMissing(String name) {
   storage[name] } } deff = newFoo() f.foo = "bar"assertEquals "bar", f.foo

Plugging this into foo.groovy and running that as a Groovy script (changing the assertEquals to a println), it works as expected. Because I've been having trouble getting propertyMissing to work properly for me, I tried to turn the above into a JUnit test:

   import static org.junit.Assert.assertEquals

   import org.junit.Test

   class PropertyMissingTest {
   class Foo {
   def storage = [:]
   def propertyMissing(String name, value) { storage[name] = value }
   def propertyMissing(String name) { storage[name] }
   }

   @Test
   void test() {
   def f = new Foo()
   f.foo = "bar"
   assertEquals "bar", f.foo
   }
   }

Unfortunately, when I run that I get this:

   java.lang.VerifyError: (class: PropertyMissingTest$Foo, method:
   propertyMissing signature:
   (Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;) Wrong
   return type in function
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:186)
        at PropertyMissingTest.class$(PropertyMissingTest.groovy)
        at
   
PropertyMissingTest.$get$$class$PropertyMissingTest$Foo(PropertyMissingTest.groovy)
        at PropertyMissingTest.test(PropertyMissingTest.groovy:14)
   [...]

I've gone over this multiple times and am a bit stumped. Any suggestions on why this isn't working?

Reply via email to