@@ -37,14 +37,14 @@ public static CloseToAssertion parse(XContentParser parser) throws IOException {
3737 throw new IllegalArgumentException ("expected a map with value and error but got a map with " + map .size () + " fields" );
3838 }
3939 Object valObj = map .get ("value" );
40- if (valObj instanceof Number == false ) {
41- throw new IllegalArgumentException ("value is missing or not a number " );
40+ if (valObj == null ) {
41+ throw new IllegalArgumentException ("value is missing" );
4242 }
4343 Object errObj = map .get ("error" );
4444 if (errObj instanceof Number == false ) {
4545 throw new IllegalArgumentException ("error is missing or not a number" );
4646 }
47- return new CloseToAssertion (location , fieldValueTuple .v1 (), (( Number ) valObj ). doubleValue () , ((Number ) errObj ).doubleValue ());
47+ return new CloseToAssertion (location , fieldValueTuple .v1 (), valObj , ((Number ) errObj ).doubleValue ());
4848 } else {
4949 throw new IllegalArgumentException (
5050 "expected a map with value and error but got " + fieldValueTuple .v2 ().getClass ().getSimpleName ()
@@ -57,7 +57,7 @@ public static CloseToAssertion parse(XContentParser parser) throws IOException {
5757
5858 private final double error ;
5959
60- public CloseToAssertion (XContentLocation location , String field , Double expectedValue , Double error ) {
60+ public CloseToAssertion (XContentLocation location , String field , Object expectedValue , Double error ) {
6161 super (location , field , expectedValue );
6262 this .error = error ;
6363 }
@@ -69,10 +69,14 @@ public final double getError() {
6969 @ Override
7070 protected void doAssert (Object actualValue , Object expectedValue ) {
7171 logger .trace ("assert that [{}] is close to [{}] with error [{}] (field [{}])" , actualValue , expectedValue , error , getField ());
72+ if ((expectedValue instanceof Number ) == false ) {
73+ throw new AssertionError ("Expected value should be a number, but was [" + expectedValue + "], which is not a number" );
74+ }
75+
7276 if (actualValue instanceof Number actualValueNumber ) {
73- assertThat (actualValueNumber .doubleValue (), closeTo ((Double ) expectedValue , error ));
77+ assertThat (actualValueNumber .doubleValue (), closeTo ((( Number ) expectedValue ). doubleValue () , error ));
7478 } else {
75- throw new AssertionError ("excpected a value close to " + expectedValue + " but got " + actualValue + ", which is not a number" );
79+ throw new AssertionError ("expected a value close to " + expectedValue + " but got " + actualValue + ", which is not a number" );
7680 }
7781 }
7882}
0 commit comments