Java Reference
In-Depth Information
Listing 4.2. A
Department
with a map of
Employees
and operator overriding
By the way, notice that the
plus
method doesn't add two
Department
instances; rather,
it adds an
Employee
to a
Department
. Groovy only cares about the name of the meth-
3
As an example from the Groovy JDK, the
java.util.Date
class has a
plus
method that takes an integer
representing the number of days. See also the
multiply
method in
Collection
that takes an integer.
To test this I'll use the Spock testing framework. As in
chapter 1
, I'll present the test
without going into much detail about the Spock framework itself, which I'll deal with in
chapter 6
. Fortunately, Spock tests are easy to read even if you don't know the details. The
next listing shows a Spock test that's focused on just the operator methods.