### Question:
MapquestGeocoder implements Geocoder { public GWTLatLng geocode(final String geolocation) throws GeocoderException { final HttpUriRequest method = new HttpGet(getUrl(geolocation)); method.addHeader("User-Agent", "OpenNMS-MapQuestGeocoder/1.0"); method.addHeader("Referer", m_referer); try { InputStream responseStream = m_httpClient.execute(method).getEntity().getContent(); final ElementTree tree = ElementTree.fromStream(responseStream); if (tree == null) { throw new GeocoderException("an error occurred connecting to the MapQuest geocoding service (no XML tree was found)"); } final ElementTree statusCode = tree.find(" if (statusCode == null || !statusCode.getText().equals("0")) { final String code = (statusCode == null? "unknown" : statusCode.getText()); final ElementTree messageTree = tree.find(" final String message = (messageTree == null? "unknown" : messageTree.getText()); throw new GeocoderException( "an error occurred when querying MapQuest (statusCode=" + code + ", message=" + message + ")" ); } final List<ElementTree> locations = tree.findAll(" if (locations.size() > 1) { LogUtils.warnf(this, "more than one location returned for query: %s", geolocation); } else if (locations.size() == 0) { throw new GeocoderException("MapQuest returned an OK status code, but no locations"); } final ElementTree location = locations.get(0); if (m_minimumQuality != null) { final Quality geocodeQuality = Quality.valueOf(location.find(" if (geocodeQuality.compareTo(m_minimumQuality) < 0) { throw new GeocoderException("response did not meet minimum quality requirement (" + geocodeQuality + " is less specific than " + m_minimumQuality + ")"); } } final ElementTree latLng = location.find(" Double latitude = Double.valueOf(latLng.find(" Double longitude = Double.valueOf(latLng.find(" return new GWTLatLng(latitude, longitude); } catch (GeocoderException e) { throw e; } catch (Throwable e) { throw new GeocoderException("unable to get lat/lng from MapQuest", e); } } MapquestGeocoder();  MapquestGeocoder(String apiKey); GWTLatLng geocode(final String geolocation);  }### Answer:
@Test public void testSuccessfulLookup() throws Exception { if (shouldRun()) { Geocoder geocoder = new MapquestGeocoder(); final GWTLatLng remote = geocoder.geocode("220 Chatham Business Dr, Pittsboro, NC 27312"); final GWTLatLng local = new GWTLatLng(35.71735, -79.16181); assertEquals(local.hashCode(), remote.hashCode()); assertEquals(local, remote); } }
@Test public void testSuccessfulLookupFailsMinimumQuality() throws Exception { if (shouldRun()) { Geocoder geocoder = new MapquestGeocoder(); try { geocoder.geocode("asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf"); } catch (GeocoderException e) { assertEquals("response did not meet minimum quality requirement (COUNTRY is less specific than ZIP)", e.getMessage()); } } }
@Test public void testBadApiKey() throws Exception { if (shouldRun()) { Geocoder geocoder = new MapquestGeocoder("unitTestBadApiKey"); try { geocoder.geocode("asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf"); } catch (GeocoderException e) { assertEquals("an error occurred when querying MapQuest (statusCode=403, message=This is not a valid key. Please check that you have entered this correctly. If you do not have a key, you can obtain a free key by registering at http: } } }