Problem assigning method to Expando inside void-method

Hi!


When entering the following as a groovy script, the editor underlines "The description" and
says: "Cannot return an object from a method that returns 'void'!"

-


SNIP -


#!/usr/bin/env groovy
void test() {

def mock = new Expando()
mock.getDescription = { return "The description"}
println "description: " + mock.getDescription()
}

test()
-


SNIP -



But the script runs fine (prints out: "description: The description") when executed by Intellij.



Regards,
Dirk

0
2 comments
Avatar
Permanently deleted user

Forgot to mention:

Selena build is: 7330
JetGroovy Plugin: 0.1.11420
Macosx: 10.4.10
JDK (for intellij): 1.5.0_06-112
groovy: 1.1-beta3


Dirk

0
Avatar
Permanently deleted user

Hi!

When using this in a unit-test:

-


SNIP -


import junit.framework.TestCase

class ExpandoTest extends TestCase {

void testExpando() {

def mock = new Expando()
mock.getDescription = { return "The description" }
println "description: " + mock.getDescription()
}

}
-


SNIP -



I get the following exception when executing inside intellij:

-


SNIP -


java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/GeneratedClosure
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:662)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:287)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:361)
at ExpandoTest.testExpando(ExpandoTest.groovy:9)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
-


SNIP -



Is there another way to assign something to an Expando that could return something when
called as a method (.getDescription())?

This test works when executed with mvn on the command line.


Regards,
Dirk

0

Please sign in to leave a comment.