Java Reference
In-Depth Information
Listing 10.18. The unit test for the
GeocoderService
Test Cases
Grails generates a unit-test class for each artifact (domain class, controller, or service) that
it produces. The default implementations fail on purpose to encourage you to implement
them properly.
In a Grails application, services use Spring's dependency injection. Here the
Geocoder
service is injected into
CastleController
to update the latitude and longitude before
an instance is saved in a database. Injecting a service is done by declaring an attribute with
code is another section of the
CastleController
implementation.
14
In Spring parlance, this is “autowiring by name.”
Listing 10.19. Dependency injection of a service into a controller