Java Reference
In-Depth Information
Listing 10.17. The Geocoder , yet again, which works on Castle s this time
class GeocoderService {
String base = 'http://maps.googleapis.com/maps/api/geocode/xml?'
def fillInLatLng(Castle castle) {
String encodedAddress =
[castle.city, castle.state].collect {
URLEncoder.encode(it, 'UTF-8')
}.join(',+')
String qs =
[address: encodedAddress, sensor: false].collect { k,v ->
"$k=$v"
}.join('&')
def root = new XmlSlurper().parse("$base$qs")
castle.latitude = root.result[0].geometry.location.lat.toDouble()
castle.longitude = root.result[0].geometry.location.lng.toDouble()
}
}
That much code certainly has to be tested. [ 13 ] Grails has had testing capabilities from the
beginning, which were originally based on JUnit subclasses. Since version 2.0, Grails test
cases use annotations (specifically, the @TestFor annotation) to control so-called mixin
classes. The @TestFor annotation applied to a controller or service test automatically in-
stantiates the test and assigns it to an attribute.
13 In pure test-driven development (TDD), the test would be written first. Then you watch it fail, implement the ser-
vice, and watch the test eventually pass.
For example, the next listing shows the test for the GeocoderService class.
 
Search WWH ::




Custom Search