@Test
public void test() throws NoSuchAuthorityCodeException, FactoryException, TransformException {

  final CoordinateReferenceSystem crs = CRS.decode("EPSG:4326", true);
  final GeometryCalculations calculator = new GeometryCalculations(crs);
  List<Geometry> geos =
      calculator.buildSurroundingGeometries(
          new double[] {50000, 50000},
          Units.METRE,
          new Coordinate(30, 30));
  assertEquals(1, geos.size());
  Geometry geo = geos.get(0);
  double lastDist = Double.NaN;
  Coordinate lastCoord = null;
  for (final Coordinate coord : geo.getCoordinates()) {
    if (lastCoord != null) {
      final double dist = JTS.orthodromicDistance(lastCoord, coord, crs);
      // scaling on the globe...so not perfect square
      assertEquals(Math.abs(dist), 100000, 500);
    }
    final double dist = JTS.orthodromicDistance(geo.getCentroid().getCoordinate(), coord, crs);
    // distances are roughly even to all corners
    if (!Double.isNaN(lastDist)) {
      assertTrue(Math.abs(dist - lastDist) < 200);
    }
    lastDist = dist;
    lastCoord = coord;
  }
  Envelope envelope = geo.getEnvelopeInternal();
  assertTrue(envelope.getMaxX() > 30);
  assertTrue(envelope.getMinX() < 30);
  assertTrue(envelope.getMaxY() > 30);
  assertTrue(envelope.getMinX() < 30);
  geos =
      calculator.buildSurroundingGeometries(
          new double[] {100000, 100000},
          Units.METRE,
          new Coordinate(179.9999999996, 0));
  assertEquals(2, geos.size());
  geo = geos.get(0);
  envelope = geo.getEnvelopeInternal();
  assertTrue((envelope.getMaxX() < -179) && (envelope.getMaxX() > -180));
  assertEquals(-180.0, envelope.getMinX(), 0.0000001);
  geo = geos.get(1);
  envelope = geo.getEnvelopeInternal();
  assertTrue((envelope.getMinX() < 180) && (envelope.getMinX() > 179));
  assertEquals(180.0, envelope.getMaxX(), 0.0000001);
}