NullValue extends ValueAdapter { @Override public String asString() { return "null"; } private  NullValue(); @Override boolean isNull(); @Override Object asObject(); @Override String asString(); @Override Type type(); @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); static final Value NULL; }
@Test void shouldReturnNativeTypesAsDefaultValue() { Value value = NullValue.NULL; assertThat( value.asString( "string value" ), equalTo( "string value" ) ); assertThat( value.asBoolean( false ), equalTo( false ) ); assertThat( value.asBoolean( true ), equalTo( true ) ); assertThat( value.asInt( 10 ), equalTo( 10 ) ); assertThat( value.asLong( 100L ), equalTo( 100L ) ); assertThat( value.asFloat( 10.4f ), equalTo( 10.4f ) ); assertThat( value.asDouble( 10.10 ), equalTo( 10.10 ) ); assertThat( value.asByteArray( new byte[]{1, 2} ), equalTo( new byte[]{1, 2} ) ); assertThat( value.asList( emptyList() ), equalTo( emptyList() ) ); assertThat( value.asList( ofValue(), emptyList() ), equalTo( emptyList() ) ); assertThat( value.asMap( emptyMap() ), equalTo( emptyMap() ) ); assertThat( value.asMap( ofValue(), emptyMap() ), equalTo( emptyMap() ) ); assertAsWithDefaultValueReturnDefault( value::asPoint, point( 1234, 1, 2 ).asPoint() ); assertAsWithDefaultValueReturnDefault( value::asLocalDate, LocalDate.now() ); assertAsWithDefaultValueReturnDefault( value::asOffsetTime, OffsetTime.now() ); assertAsWithDefaultValueReturnDefault( value::asLocalTime, LocalTime.now() ); assertAsWithDefaultValueReturnDefault( value::asLocalDateTime, LocalDateTime.now() ); assertAsWithDefaultValueReturnDefault( value::asOffsetDateTime, OffsetDateTime.now() ); assertAsWithDefaultValueReturnDefault( value::asZonedDateTime, ZonedDateTime.now() ); assertAsWithDefaultValueReturnDefault( value::asIsoDuration, isoDuration( 1, 2, 3, 4 ).asIsoDuration() ); }