### Question:
GenericHandler { protected Polygon[] convertAvoidAreas(JSONObject geoJson, int profileType) throws StatusCodeException { org.json.JSONObject complexJson = new org.json.JSONObject(); complexJson.put("type", geoJson.get("type")); List<List<Double[]>> coordinates = (List<List<Double[]>>) geoJson.get("coordinates"); complexJson.put("coordinates", coordinates); Geometry convertedGeom; try { convertedGeom = GeometryJSON.parse(complexJson); } catch (Exception e) { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } Polygon[] avoidAreas; if (convertedGeom instanceof Polygon) { avoidAreas = new Polygon[]{(Polygon) convertedGeom}; } else if (convertedGeom instanceof MultiPolygon) { MultiPolygon multiPoly = (MultiPolygon) convertedGeom; avoidAreas = new Polygon[multiPoly.getNumGeometries()]; for (int i = 0; i < multiPoly.getNumGeometries(); i++) avoidAreas[i] = (Polygon) multiPoly.getGeometryN(i); } else { throw new ParameterValueException(getInvalidParameterValueErrorCode(), "avoid_polygons"); } return avoidAreas; } GenericHandler();  static final String KEY_PROFILE; }### Answer:
@Test public void convertAvoidAreas() throws StatusCodeException { JSONObject geomJSON = new JSONObject(); geomJSON.put("type", "Polygon"); JSONArray poly = generateGeoJSONPolyCoords(); JSONArray coords = new JSONArray(); coords.add(0, poly); geomJSON.put("coordinates", coords); Polygon[] avoidAreas = handler.convertAvoidAreas(geomJSON, 1); Assert.assertEquals(1, avoidAreas.length); Assert.assertEquals(4, avoidAreas[0].getCoordinates().length); Assert.assertEquals(1, avoidAreas[0].getCoordinates()[0].x, 0.0); JSONObject geomJSONMulti = new JSONObject(); geomJSONMulti.put("type", "MultiPolygon"); JSONArray polys1 = new JSONArray(); polys1.add(0, poly); JSONArray polys2 = new JSONArray(); polys2.add(0, poly); coords = new JSONArray(); coords.add(0,polys1); coords.add(0,polys2); geomJSONMulti.put("coordinates", coords); avoidAreas = handler.convertAvoidAreas(geomJSONMulti, 1); Assert.assertEquals(2, avoidAreas.length); }
@Test(expected = ParameterValueException.class) public void convertAvoidAreasInvalidType() throws StatusCodeException { JSONObject geomJSON = new JSONObject(); geomJSON.put("type", "LineString"); JSONArray poly = generateGeoJSONPolyCoords(); geomJSON.put("coordinates", poly); handler.convertAvoidAreas(geomJSON, 1); }
@Test(expected = ParameterValueException.class) public void convertAvoidAreasInvalidFeature() throws StatusCodeException { JSONObject geomJSON = new JSONObject(); geomJSON.put("type", "Polygon"); JSONArray poly = generateGeoJSONPolyCoords(); geomJSON.put("coooooooooooordinates", poly); handler.convertAvoidAreas(geomJSON, 1); }