GoogleGeocoderImpl implements GeocoderService { public GeocoderResults geocode(String location) { StringBuilder b = new StringBuilder(); b.append(BASE_URL); b.append("?"); b.append("sensor=").append(sensor); String encodedLocation; try { encodedLocation = URLEncoder.encode(location, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new IllegalStateException("unknown encoding: UTF-8"); } b.append("&address=").append(encodedLocation); URL url = url(b.toString()); Digester digester = createDigester(); GeocoderResults results = new GeocoderResults(); digester.push(results); InputStream inputStream = null; try { inputStream = url.openStream(); digester.parse(inputStream); } catch (Exception ex) { throw new IllegalStateException(ex); } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception ex) {} } } return results; }  void setSensor(boolean sensor); GeocoderResults geocode(String location);  }
@Test public void testGeocoder() { GoogleGeocoderImpl geocoder = new GoogleGeocoderImpl(); GeocoderResults results = geocoder.geocode("98105"); List<GeocoderResult> records = results.getResults(); assertEquals(1, records.size()); GeocoderResult result = records.get(0); assertEquals(47.663355, result.getLatitude(), 0.1); assertEquals(-122.298259, result.getLongitude(), 0.1); assertEquals("",result.getAddress()); assertEquals("Seattle", result.getCity()); assertEquals("WA", result.getAdministrativeArea()); assertEquals("98105", result.getPostalCode()); assertEquals("US", result.getCountry()); }