### Question:
DefaultValue { public static DefaultValue of(Object defaultValue) { if (defaultValue instanceof DefaultValue) { return (DefaultValue) defaultValue; } else { return new DefaultValue(defaultValue); } } private  DefaultValue(@Nullable Object defaultValue); static DefaultValue of(Object defaultValue); long longValue(); double doubleValue(); long[] longArrayValue(); double[] doubleArrayValue(); float[] floatArrayValue(); @Nullable Object getObject(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); static final DefaultValue DEFAULT; static final int INTEGER_DEFAULT_FALLBACK; static final long LONG_DEFAULT_FALLBACK; static final float FLOAT_DEFAULT_FALLBACK; static final double DOUBLE_DEFAULT_FALLBACK; }### Answer:
@Test void shouldNotNestDefaultValues() { assertEquals(DefaultValue.of(42), DefaultValue.of(DefaultValue.of(42))); }
@Test void shouldThrowAnErrorIfDoubleCannotBeSafelyCoercedToLong() { var defaultValue = DefaultValue.of(42.42); var e = assertThrows(UnsupportedOperationException.class, defaultValue::longValue); assertThat(e.getMessage(), containsString("Cannot safely convert 42.42 into an long value")); }
@Test void shouldThrowAnErrorIfLongCannotBeSafelyCoercedToDouble() { var defaultValue = DefaultValue.of(1L << 53 + 1); var e = assertThrows(UnsupportedOperationException.class, defaultValue::doubleValue); assertThat(e.getMessage(), containsString("Cannot safely convert")); }