GeonamesGeocoderService implements GeocoderService { public GetLocationResult[] getLocation(List<String> location, int maxAlternatives, Locale ignore) { GetLocationResult[] result; try { List<Toponym> toponyms = search(splitCommaReverseService.combine(location), maxAlternatives, false); int resCount = toponyms.size(); if (0 == resCount) { toponyms = search(splitCommaReverseService.combine(location), maxAlternatives, true); } removeDuplicates(toponyms); resCount = toponyms.size(); result = new GetLocationResult[resCount]; for (int i = 0; i < resCount; i++) { Toponym toponym = toponyms.get(i); GetLocationResult one = new GetLocationResult(); List<String> prefResult = new ArrayList<String>(); prefResult.add(toponym.getCountryCode()); prefResult.add(toponym.getName()); one.setCanonicalStrings(prefResult); Coordinate coordinate = new Coordinate(); coordinate.x = toponym.getLongitude(); coordinate.y = toponym.getLatitude(); one.setCoordinate(coordinate); result[i] = one; } return result; } catch (Exception ex) { log.error("Search failed", ex); return null; } }  String getName(); @Api void setName(String name); @Api void setUserName(String userName); @Api void setUserNameProperty(String userNameProperty); CoordinateReferenceSystem getCrs(); GetLocationResult[] getLocation(List<String> location, int maxAlternatives, Locale ignore); List<Toponym> search(String q, int maxRows, boolean fuzzy);  }
@Test public void testGeocoder() { List<String> list = new ArrayList<String>(); GetLocationResult[] result; list.clear(); list.add("booischot"); result = geocoder.getLocation(list, 500, null); Assert.assertNotNull("Geonames may be down", result); Assert.assertEquals(1,result.length); Assert.assertNotNull(result[0].getCoordinate()); Assert.assertEquals(4.7751, result[0].getCoordinate().x, .00001); Assert.assertEquals(51.05219, result[0].getCoordinate().y, .00001); list.clear(); list.add("london"); result = geocoder.getLocation(list, 500, null); Assert.assertNotNull("Geonames may be down", result); int londonWorldCount = result.length; Assert.assertTrue(londonWorldCount > 1); list.clear(); list.add("london"); list.add("UK"); result = geocoder.getLocation(list, 500, null); Assert.assertNotNull("Geonames may be down", result); Assert.assertTrue(result.length > 1); Assert.assertTrue(result.length < londonWorldCount); list.clear(); list.add("blablabla"); result = geocoder.getLocation(list, 500, null); Assert.assertNotNull("Geonames may be down", result); Assert.assertTrue(0 == result.length); }