### Question:
LocationUtil { public static List<Location> parseLocations(final String input) { final List<Location> locations = new ArrayList<>(); final Matcher locationsMatcher = LOCATIONS_PATTERN.matcher(input); if (locationsMatcher.matches()) { Matcher locationMatcher = LOCATION_PATTERN.matcher(input); while (locationMatcher.find()) { final String location = locationMatcher.group(); locations.add(parseLocation(location)); } } else { throw new IllegalStateException("The provided location string was invalid."); } return locations; }  static List<Location> parseLocations(final String input); static Location parseLocation(final String location);  }### Answer:
@Test public void testParseLocationsSingle() { final String swLon = "-122.75"; final String swLat = "36.8"; final String neLon = "-121.75"; final String neLat = "37.8"; final String locationString = swLon + "," + swLat + "," + neLon + "," + neLat; List<Location> locations = LocationUtil.parseLocations(locationString); Assert.assertEquals(1, locations.size()); Location location = locations.get(0); Assert.assertEquals(new Double(location.southwestCoordinate().longitude()), Double.valueOf(swLon)); Assert.assertEquals(new Double(location.southwestCoordinate().latitude()), Double.valueOf(swLat)); Assert.assertEquals(new Double(location.northeastCoordinate().longitude()), Double.valueOf(neLon)); Assert.assertEquals(new Double(location.northeastCoordinate().latitude()), Double.valueOf(neLat)); }
@Test public void testParseLocationsMultiple() { final Location location1 = new Location(new Location.Coordinate(-122.75, 36.8), new Location.Coordinate(-121.75,37.8)); final Location location2 = new Location(new Location.Coordinate(-74, 40), new Location.Coordinate(-73, 41)); final Location location3 = new Location(new Location.Coordinate(-64, 30), new Location.Coordinate(-63, 31)); final Location location4 = new Location(new Location.Coordinate(-54, 20), new Location.Coordinate(-53, 21)); final List<Location> expectedLocations = Arrays.asList(location1, location2, location3, location4); final String locationString = "-122.75,36.8,-121.75,37.8,-74,40,-73,41,-64,30,-63,31,-54,20,-53,21"; List<Location> locations = LocationUtil.parseLocations(locationString); Assert.assertEquals(expectedLocations.size(), locations.size()); for (Location expectedLocation : expectedLocations) { boolean found = false; for (Location location : locations) { if (location.northeastCoordinate().longitude() == expectedLocation.northeastCoordinate().longitude() && location.northeastCoordinate().latitude() == expectedLocation.northeastCoordinate().latitude() && location.southwestCoordinate().longitude() == expectedLocation.southwestCoordinate().longitude() && location.southwestCoordinate().latitude() == expectedLocation.southwestCoordinate().latitude()) { found = true; break; } } Assert.assertTrue(found); } }