### Question:
ExplicitIndexValueValidator implements Validator<Object> { @Override public void validate( Object value ) { if ( value == null ) { throw new IllegalArgumentException( "Null value" ); } if ( value instanceof String ) { LuceneIndexValueValidator.INSTANCE.validate( ((String)value).getBytes() ); } if ( !(value instanceof Number) && value.toString() == null ) { throw new IllegalArgumentException( "Value of type " + value.getClass() + " has null toString" ); } } private  ExplicitIndexValueValidator(); @Override void validate( Object value ); static final ExplicitIndexValueValidator INSTANCE; }### Answer:
@Test void nullIsNotAllowed() { IllegalArgumentException iae = assertThrows( IllegalArgumentException.class, () -> INSTANCE.validate( null ) ); assertEquals( iae.getMessage(), "Null value" ); }
@Test void stringOverExceedLimitNotAllowed() { int length = MAX_TERM_LENGTH * 2; IllegalArgumentException iae = assertThrows( IllegalArgumentException.class, () -> INSTANCE.validate( RandomStringUtils.randomAlphabetic( length ) ) ); assertThat( iae.getMessage(), containsString( "Property value size is too large for index. Please see index documentation for limitations." ) ); }
@Test void nullToStringIsNotAllowed() { Object testValue = mock( Object.class ); when( testValue.toString() ).thenReturn( null ); IllegalArgumentException iae = assertThrows( IllegalArgumentException.class, () -> INSTANCE.validate( testValue ) ); assertThat( iae.getMessage(), containsString( "has null toString" ) ); }
@Test void numberIsValidValue() { INSTANCE.validate( 5 ); INSTANCE.validate( 5.0d ); INSTANCE.validate( 5.0f ); INSTANCE.validate( 5L ); }
@Test void shortStringIsValidValue() { INSTANCE.validate( RandomStringUtils.randomAlphabetic( 5 ) ); INSTANCE.validate( RandomStringUtils.randomAlphabetic( 10 ) ); INSTANCE.validate( RandomStringUtils.randomAlphabetic( 250 ) ); INSTANCE.validate( RandomStringUtils.randomAlphabetic( 450 ) ); INSTANCE.validate( RandomStringUtils.randomAlphabetic( MAX_TERM_LENGTH ) ); }