Java Reference
In-Depth Information
In the Spock test the Java class under test is instantiated as an attribute. I populate the data
using the native collection in Groovy, even though the class under test is written in Java
and the methods take Java lists as arguments. [ 6 ] I have two tests, and in each case, even
without knowing anything about Spock, it should be clear what the tests are doing. I'm tak-
ing advantage of Groovy capabilities like optional parentheses and the spread-dot operator,
which applies to a list and returns a list with the specified properties only.
6 Applying Groovy tests to Java code is discussed in chapter 6 .
The test passes, and I can use the same test with the Groovy implementation. The point,
though, is that I can add a Groovy test to a Java system without any problems.
1.1.5. Groovy tools simplify your build
Another area where Groovy helps Java is in the build process. I'll have a lot to say about
Groovy build mechanisms in chapter 5 , but here I'll just mention a couple of ways they
help Java. If you're accustomed to using Apache Ant for building systems, Groovy adds
execution and compilation tasks to Ant. Another option is to use AntBuilder , which al-
lows you to write Ant tasks using Groovy syntax.
That's actually a common theme in Groovy, which I should emphasize:
Groovy Feature
Groovy augments and enhances existing Java tools, rather than replacing them.
If your company has moved from Ant to Maven you're using a tool that works at a higher
level of abstraction and manages dependencies for you. In chapter 5 two ways are provided
to add Groovy to a Maven build. The Groovy ecosystem, however, provides another altern-
ative.
In chapter 5 I discuss the latest Groovy killer app, Gradle. Gradle does dependency man-
agement based on Maven repositories (though it uses Ivy under the hood) and defines build
tasks in a manner similar to Ant, but it's easy to set up and run. Maven is very powerful,
but it has a lot of trouble with projects that weren't designed from the beginning with it in
 
Search WWH ::




Custom Search