### Question:
GeoJsonReader { public Geometry read(String string) { try { JSONObject json = new JSONObject(string); String type = json.getString(TYPE); switch (type) { case "Feature": return createFeature(json); case "FeatureCollection": Geometry[] features = createFeatures(json.getJSONArray(FEATURES)); return factory.createGeometryCollection(features); default: return createGeometry(json); } } catch (JSONException e) { throw new GeoJsonException(e); } } GeoJsonReader();  GeoJsonReader(boolean ensureOgcSfsCompliancy); Geometry read(String string);  }### Answer:
@Test public void validateLineString() { try { read("{" + " \"type\": \"LineString\"," + " \"coordinates\": [[1,2]]" + "}"); fail(); } catch (GeoJsonException e) {} }
@Test public void validatePolygon() { try { read("{" + " \"type\": \"Polygon\"," + " \"coordinates\": [[[0,0],[4,0],[0,0]]]" + "}"); fail(); } catch (GeoJsonException e) {} try { read("{" + " \"type\": \"Polygon\"," + " \"coordinates\": [[[0,0],[4,0],[0,4],[2,3]]]" + "}"); fail(); } catch (GeoJsonException e) {} }
@Test public void readFeatureWithEmptyProperties() { assertNull( read("{" + " \"type\": \"Feature\"," + " \"properties\": {}," + " \"geometry\": {" + " \"type\": \"Point\"," + " \"coordinates\": [5,5]" + " }" + "}").getUserData()); }
@Test public void readFeatureWithProperties() { Geometry g = read("{" + " \"type\": \"Feature\"," + " \"properties\": {\"a\": 3, \"b\": \"blub\", \"c\": null, \"d\": [1,2], \"e\": {\"hi\":\"ho\"}}," + " \"geometry\": {" + " \"type\": \"Point\"," + " \"coordinates\": [5,5]" + " }" + "}"); assertTrue(g.getUserData() instanceof Map); Map props = (Map) g.getUserData(); assertEquals(3,props.get("a")); assertEquals("blub",props.get("b")); assertEquals(null,props.get("c")); assertEquals(Arrays.asList(1,2), props.get("d")); assertTrue(props.get("e") instanceof Map); assertEquals("ho", ((Map) props.get("e")).get("hi")); }
@Test public void readFeatureWithInvalidProperties() { try { read("{" + " \"type\": \"Feature\"," + " \"properties\": [1,2,3]," + " \"geometry\": {" + " \"type\": \"Point\"," + " \"coordinates\": [5,5]" + " }" + "}"); fail(); } catch (GeoJsonException e) {} }