GeoDistanceSortFieldBuilder extends SortFieldBuilder<GeoDistanceSortField, GeoDistanceSortFieldBuilder> { @Override public GeoDistanceSortField build() { return new GeoDistanceSortField(field, reverse, latitude, longitude); } @JsonCreator  GeoDistanceSortFieldBuilder(@JsonProperty("field") String field,
                                       @JsonProperty("latitude") double latitude,
                                       @JsonProperty("longitude") double longitude); @Override GeoDistanceSortField build();  }
@Test public void testBuild() { String mapper = "geo_place"; double latitude = 0.0; double longitude = 0.0; GeoDistanceSortField field = new GeoDistanceSortFieldBuilder(mapper, latitude, longitude).reverse(true).build(); assertNotNull("GeoDistanceSortField is not built", field); assertEquals("GeoDistanceSortField field name is not set", mapper, field.field); assertEquals("GeoDistanceSortField reverse is not set", true, field.reverse); assertTrue("GeoDistanceSortField latitude is not set", latitude == field.latitude); assertTrue("GeoDistanceSortField longitude is not set", longitude == field.longitude); }
@Test public void testBuildDefault() { String mapper = "geo_place"; double latitude = 0.0; double longitude = 0.0; GeoDistanceSortField field = new GeoDistanceSortFieldBuilder(mapper, latitude, longitude).build(); assertNotNull("GeoDistanceSortField is not built", field); assertEquals("GeoDistanceSortField field name is not set", mapper, field.field); assertEquals("GeoDistanceSortField reverse is not properly set", SortField.DEFAULT_REVERSE, field.reverse); }
@Test public void testBuildInvalidLat() { String field = "field"; double latitude = 91.0; double longitude = 0.0; GeoDistanceSortFieldBuilder builder = new GeoDistanceSortFieldBuilder(field, latitude, longitude); try { builder.build(); } catch (IndexException e) { assertEquals("Creating a GeoDistanceSortFieldBuilder with invalid longitude must throw an IndexException", "latitude must be in range [-90.0, 90.0], but found 91.0", e.getMessage()); } }
@Test public void testBuildInvalidLong() { String field = "field"; double latitude = 0.0; double longitude = 200.0; GeoDistanceSortFieldBuilder builder = new GeoDistanceSortFieldBuilder(field, latitude, longitude); try { builder.build(); } catch (IndexException e) { assertEquals("Creating a GeoDistanceSortFieldBuilder with invalid longitude must throw an IndexException", "longitude must be in range [-180.0, 180.0], but found 200.0", e.getMessage()); } }
@Test public void testBuildReverse() { String mapper = "geo_place"; GeoDistanceSortField field = new GeoDistanceSortFieldBuilder(mapper, 0.0, 0.0).reverse(false).build(); assertNotNull("GeoDistanceSortField is not built", field); assertEquals("GeoDistanceSortField field name is not set", mapper, field.field); assertEquals("GeoDistanceSortField reverse is not set", false, field.reverse); }