Java Reference
In-Depth Information
Table 3.1. Static methods in
groovy.util.Eval
for executing Groovy from Java
Eval.me
Overloaded to take a String expression or an expression with a String symbol and an Object
Eval.x
One argument: the value of x
Eval.xy
Two arguments, x and y
Eval.xyz
Three arguments, x, y, and z
To demonstrate the methods I'll add additional tests to the JUnit test case. The test is writ-
ten in Java, so I'll automatically call Groovy from Java.
The following listing showsfourtests, oneforeach ofthe static methods inthe
Eval
class.
Listing 3.4. JUnit 4 test class verifying results of calling
Eval
methods from Java
In each test the Groovy script to be evaluated is included as a string. Unlike the
ScriptEngine
there's no overload for instances of
Reader
, so to execute a script in a
separate file would require reading the file into a string. The methods also assume that the