PolygonGeometryFilter implements GeometryFilter { @Override public boolean accept(CompoundData compoundData) throws IOException { final float lat = compoundData.getFloat(1); final float lon = compoundData.getFloat(2); final Coordinate coord = new Coordinate(lon, lat); final Point point = geometryFactory.createPoint(coord); return polygon.contains(point); } PolygonGeometryFilter(Geometry geometry); @Override boolean accept(CompoundData compoundData);  }
@Test public void testAccept_insidePolygon() throws IOException { final CompoundData compoundData = mock(CompoundData.class); when(compoundData.getFloat(1)).thenReturn(0.01f); when(compoundData.getFloat(2)).thenReturn(10.02f); assertTrue(geometryFilter.accept(compoundData)); when(compoundData.getFloat(1)).thenReturn(2.65f); when(compoundData.getFloat(2)).thenReturn(11.78f); assertTrue(geometryFilter.accept(compoundData)); when(compoundData.getFloat(1)).thenReturn(9.98f); when(compoundData.getFloat(2)).thenReturn(19.78f); assertTrue(geometryFilter.accept(compoundData)); }
@Test public void testAccept_outsidePolygon() throws IOException { final CompoundData compoundData = mock(CompoundData.class); when(compoundData.getFloat(1)).thenReturn(-0.01f); when(compoundData.getFloat(2)).thenReturn(9.99f); assertFalse(geometryFilter.accept(compoundData)); when(compoundData.getFloat(1)).thenReturn(10.01f); when(compoundData.getFloat(2)).thenReturn(20.02f); assertFalse(geometryFilter.accept(compoundData)); when(compoundData.getFloat(1)).thenReturn(22.65f); when(compoundData.getFloat(2)).thenReturn(41.78f); assertFalse(geometryFilter.accept(compoundData)); }