GeometryUtility { public static String attributeToLineString( Attribute attribute, GeometryOperator geometryOperator, GeometryOperator.Context geometryOperatorContext) { List<String> points = getAttributeStrings(attribute); Coordinate[] coordinates = listToArray(convertWktToCoordinates(points)); Geometry geometry = convertCoordinatesToGeometry(coordinates); if (geometry == null) { return null; } geometry = geometryOperator.apply(geometry, geometryOperatorContext); if (geometry == null) { return null; } return convertGeometryToWkt(geometry); }  static Optional<String> createUnionOfGeometryAttribute(
      WKTReader wktReader,
      WKTWriter wktWriter,
      Attribute attribute,
      GeometryOperator.Context geometryOperatorContext); static Optional<String> createUnionOfGeometryAttribute(
      WKTReader wktReader,
      WKTWriter wktWriter,
      Attribute attribute,
      BiFunction<Geometry, GeometryOperator.Context, Geometry> postUnionGeometryOperator,
      BiFunction<Geometry, GeometryOperator.Context, Geometry> preUnionGeometryOperator,
      GeometryOperator.Context geometryOperatorContext); static Optional<Geometry> wktToGeometry(String wkt, WKTReader wktReader); static String attributeToLineString(
      Attribute attribute,
      GeometryOperator geometryOperator,
      GeometryOperator.Context geometryOperatorContext);  }
@Test public void testAttributeToLineStringWithNullGeometry() { Attribute attribute = new AttributeImpl(FIELD, Arrays.asList("POINT ( 0 0 )", "POINT ( 10 10 )")); GeometryOperator geometryOperator = mock(GeometryOperator.class); when(geometryOperator.apply(any(), any())).thenReturn(null); String lineString = GeometryUtility.attributeToLineString( attribute, geometryOperator, new GeometryOperator.Context()); verify(geometryOperator).apply(any(), any()); assertThat(lineString, is(nullValue())); }
@Test public void testAttributeToLineString() { Attribute attribute = new AttributeImpl(FIELD, Arrays.asList("POINT ( 0 0 )", "POINT ( 10 10 )")); String lineString = GeometryUtility.attributeToLineString( attribute, GeometryOperator.IDENTITY, new GeometryOperator.Context()); assertThat(lineString, is("LINESTRING (0 0, 10 10)")); }
@Test public void testAttributeToLineStringWithSomeBadData() { Attribute attribute = new AttributeImpl(FIELD, Arrays.asList("POINT ( 0 0 )", "POINT ( xxx )")); String lineString = GeometryUtility.attributeToLineString( attribute, GeometryOperator.IDENTITY, new GeometryOperator.Context()); assertThat(lineString, is("POINT (0 0)")); }
@Test public void testAttributeToLineStringWithBadData() { Attribute attribute = new AttributeImpl(FIELD, Arrays.asList("POINT ( yyy )", "POINT ( xxx )")); String lineString = GeometryUtility.attributeToLineString( attribute, GeometryOperator.IDENTITY, new GeometryOperator.Context()); assertThat(lineString, is((String) null)); }
@Test public void testAttributeToLineStringWithEmptyData() { Attribute attribute = new AttributeImpl(FIELD, Collections.emptyList()); String lineString = GeometryUtility.attributeToLineString( attribute, GeometryOperator.IDENTITY, new GeometryOperator.Context()); assertThat(lineString, is((String) null)); }