static PolygonBuilder mutatePolygonBuilder(PolygonBuilder pb) {
   if (randomBoolean()) {
     pb = polyWithOposingOrientation(pb);
   } else {
     // change either point in shell or in random hole
     LineStringBuilder lineToChange;
     if (randomBoolean() || pb.holes().size() == 0) {
       lineToChange = pb.shell();
     } else {
       lineToChange = randomFrom(pb.holes());
     }
     Coordinate coordinate = randomFrom(lineToChange.coordinates(false));
     if (randomBoolean()) {
       if (coordinate.x != 0.0) {
         coordinate.x = coordinate.x / 2;
       } else {
         coordinate.x = randomDoubleBetween(-180.0, 180.0, true);
       }
     } else {
       if (coordinate.y != 0.0) {
         coordinate.y = coordinate.y / 2;
       } else {
         coordinate.y = randomDoubleBetween(-90.0, 90.0, true);
       }
     }
   }
   return pb;
 }
  public void testCoerceShell() {
    try {
      new PolygonBuilder(
          new LineStringBuilder(
              new CoordinatesBuilder()
                  .coordinate(0.0, 0.0)
                  .coordinate(1.0, 0.0)
                  .coordinate(1.0, 1.0)
                  .build()),
          Orientation.RIGHT);
      fail("should raise validation exception");
    } catch (IllegalArgumentException e) {
      assertEquals(
          "invalid number of points in LinearRing (found [3] - must be >= 4)", e.getMessage());
    }

    PolygonBuilder pb =
        new PolygonBuilder(
            new LineStringBuilder(
                new CoordinatesBuilder()
                    .coordinate(0.0, 0.0)
                    .coordinate(1.0, 0.0)
                    .coordinate(1.0, 1.0)
                    .build()),
            Orientation.RIGHT,
            true);
    assertThat(
        "Shell should have been closed via coerce",
        pb.shell().coordinates(false).length,
        equalTo(4));
  }
 /**
  * Takes an input polygon and returns an identical one, only with opposing orientation setting.
  * This is done so we don't have to expose a setter for orientation in the actual class
  */
 private static PolygonBuilder polyWithOposingOrientation(PolygonBuilder pb) {
   PolygonBuilder mutation =
       new PolygonBuilder(
           pb.shell(),
           pb.orientation() == Orientation.LEFT ? Orientation.RIGHT : Orientation.LEFT);
   for (LineStringBuilder hole : pb.holes()) {
     mutation.hole(hole);
   }
   return mutation;
 }