IntegerValue extends NumberValueAdapter<Long> { @Override public double asDouble() { double doubleVal = (double) val; if ( (long) doubleVal != val) { throw new LossyCoercion( type().name(), "Java double" ); } return (double) val; } IntegerValue( long val ); @Override Type type(); @Override Long asNumber(); @Override long asLong(); @Override int asInt(); @Override double asDouble(); @Override float asFloat(); @Override String toString(); @Override boolean equals( Object o ); @Override int hashCode();  }
@Test void shouldThrowIfLargerThan() { IntegerValue value1 = new IntegerValue( 9007199254740992L); IntegerValue value2 = new IntegerValue(9007199254740993L ); assertThat(value1.asDouble(), equalTo(9007199254740992D)); assertThrows( LossyCoercion.class, value2::asDouble ); }