@Test public void testEncodeFeatureWithNullAttributes() throws Exception { GeometryBuilder geomBuilder = new GeometryBuilder(); MultiPolygon multiPolygon = geomBuilder.multiPolygon(geomBuilder.polygon(0, 0, 0, 1, 1, 1, 0, 0)); GMLComplexType instance = GMLComplexTypes.AbstractFeatureType.getInstance(); SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName("person"); typeBuilder.add("mpolygon", MultiPolygon.class); typeBuilder.add("name", MultiPolygon.class); SimpleFeatureType type = typeBuilder.buildFeatureType(); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type); SimpleFeature lFeature = featureBuilder.buildFeature(null); Element element = mock(Element.class); Element element_mpolygon = mock(Element.class); Element element_name = mock(Element.class); when(element.getType()).thenReturn(GMLComplexTypes.AbstractFeatureType.getInstance()); when(element.findChildElement(eq("mpolygon"))).thenReturn(element_mpolygon); when(element.findChildElement(eq("name"))).thenReturn(element_name); when(element_mpolygon.getType()) .thenReturn(GMLComplexTypes.MultiPolygonPropertyType.getInstance()); when(element_name.getType()).thenReturn(XSISimpleTypes.String.getInstance()); Map<?, ?> hints = new HashMap(); PrintHandler printHandler = mock(PrintHandler.class); instance.encode(element, lFeature, printHandler, hints); verify(printHandler, Mockito.times(2)).startElement(any(), any(), any()); verify(printHandler, Mockito.times(2)).endElement(any(), any()); lFeature.setAttribute("name", "Pink Panther"); lFeature.setAttribute("mpolygon", multiPolygon); printHandler = mock(PrintHandler.class); instance.encode(element, lFeature, printHandler, hints); verify(printHandler, Mockito.times(9)).startElement(any(), any(), any()); verify(printHandler, Mockito.times(9)).endElement(any(), any()); }
static void encode(Element e, Geometry g, PrintHandler output) throws OperationNotSupportedException, IOException { if (g instanceof Point) { encode(e, (Point) g, output); return; } if (g instanceof Polygon) { encode(e, (Polygon) g, output); return; } if (g instanceof LinearRing) { encode(e, (LinearRing) g, output); return; } if (g instanceof LineString) { encode(e, (LineString) g, output); return; } if (g instanceof MultiLineString) { encode(e, (MultiLineString) g, output); return; } if (g instanceof MultiPolygon) { encode(e, (MultiPolygon) g, output); return; } if (g instanceof MultiPoint) { encode(e, (MultiPoint) g, output); return; } if (g instanceof GeometryCollection) { encode(e, (GeometryCollection) g, output); return; } }
GMLComplexTypes { static void encode(Element e, Geometry g, PrintHandler output) throws OperationNotSupportedException, IOException { if (g instanceof Point) { encode(e, (Point) g, output); return; } if (g instanceof Polygon) { encode(e, (Polygon) g, output); return; } if (g instanceof LinearRing) { encode(e, (LinearRing) g, output); return; } if (g instanceof LineString) { encode(e, (LineString) g, output); return; } if (g instanceof MultiLineString) { encode(e, (MultiLineString) g, output); return; } if (g instanceof MultiPolygon) { encode(e, (MultiPolygon) g, output); return; } if (g instanceof MultiPoint) { encode(e, (MultiPoint) g, output); return; } if (g instanceof GeometryCollection) { encode(e, (GeometryCollection) g, output); return; } } }
GMLComplexTypes { static void encode(Element e, Geometry g, PrintHandler output) throws OperationNotSupportedException, IOException { if (g instanceof Point) { encode(e, (Point) g, output); return; } if (g instanceof Polygon) { encode(e, (Polygon) g, output); return; } if (g instanceof LinearRing) { encode(e, (LinearRing) g, output); return; } if (g instanceof LineString) { encode(e, (LineString) g, output); return; } if (g instanceof MultiLineString) { encode(e, (MultiLineString) g, output); return; } if (g instanceof MultiPolygon) { encode(e, (MultiPolygon) g, output); return; } if (g instanceof MultiPoint) { encode(e, (MultiPoint) g, output); return; } if (g instanceof GeometryCollection) { encode(e, (GeometryCollection) g, output); return; } }  }
GMLComplexTypes { static void encode(Element e, Geometry g, PrintHandler output) throws OperationNotSupportedException, IOException { if (g instanceof Point) { encode(e, (Point) g, output); return; } if (g instanceof Polygon) { encode(e, (Polygon) g, output); return; } if (g instanceof LinearRing) { encode(e, (LinearRing) g, output); return; } if (g instanceof LineString) { encode(e, (LineString) g, output); return; } if (g instanceof MultiLineString) { encode(e, (MultiLineString) g, output); return; } if (g instanceof MultiPolygon) { encode(e, (MultiPolygon) g, output); return; } if (g instanceof MultiPoint) { encode(e, (MultiPoint) g, output); return; } if (g instanceof GeometryCollection) { encode(e, (GeometryCollection) g, output); return; } }  static SimpleFeatureType createFeatureType(Element element); static SimpleFeatureType createFeatureType(ComplexType element); }
GMLComplexTypes { static void encode(Element e, Geometry g, PrintHandler output) throws OperationNotSupportedException, IOException { if (g instanceof Point) { encode(e, (Point) g, output); return; } if (g instanceof Polygon) { encode(e, (Polygon) g, output); return; } if (g instanceof LinearRing) { encode(e, (LinearRing) g, output); return; } if (g instanceof LineString) { encode(e, (LineString) g, output); return; } if (g instanceof MultiLineString) { encode(e, (MultiLineString) g, output); return; } if (g instanceof MultiPolygon) { encode(e, (MultiPolygon) g, output); return; } if (g instanceof MultiPoint) { encode(e, (MultiPoint) g, output); return; } if (g instanceof GeometryCollection) { encode(e, (GeometryCollection) g, output); return; } }  static SimpleFeatureType createFeatureType(Element element); static SimpleFeatureType createFeatureType(ComplexType element);  }