### Question:
PropertyValidator { public List<ValidationMessage> validate( String name, String value ) { return validate( name, value, -1 ); } PropertyValidator(); List<ValidationMessage> validate( String name, String value ); List<ValidationMessage> validate( String name, String value, int propertyIndex );  }### Answer:
@Test public void testValidateValidProperties( ) { List< ValidationMessage > result = validator.validate( PROPERTY_NAME, "value" ); assertTrue( result.isEmpty( ) ); result = validator.validate( PROPERTY_NAME, "value", 0 ); assertTrue( result.isEmpty( ) ); }
@Test public void testValidateInvalidProperties( ) { List< ValidationMessage > result = validator.validate( "", "value" ); assertEquals( 1, result.size( ) ); ValidationMessage expectedMessage = newErrorMessage( PersistenceDescriptorValidationMessages.PROPERTY_NAME_EMPTY_ID, PersistenceDescriptorValidationMessages.PROPERTY_NAME_EMPTY ); assertEquals( expectedMessage, result.get( 0 ) ); result = validator.validate( null, "value" ); assertEquals( 1, result.size( ) ); assertEquals( expectedMessage, result.get( 0 ) ); result = validator.validate( "", "value", 1 ); assertEquals( 1, result.size( ) ); expectedMessage = newErrorMessage( PersistenceDescriptorValidationMessages.INDEXED_PROPERTY_NAME_EMPTY_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.INDEXED_PROPERTY_NAME_EMPTY, Integer.toString( 1 ) ), Integer.toString( 1 ) ); assertEquals( expectedMessage, result.get( 0 ) ); result = validator.validate( null, "value", 1 ); assertEquals( 1, result.size( ) ); assertEquals( expectedMessage, result.get( 0 ) ); result = validator.validate( PROPERTY_NAME, "" ); assertEquals( 1, result.size( ) ); expectedMessage = newWarningMessage( PersistenceDescriptorValidationMessages.PROPERTY_VALUE_EMPTY_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.PROPERTY_VALUE_EMPTY, PROPERTY_NAME ), PROPERTY_NAME ); assertEquals( expectedMessage, result.get( 0 ) ); result = validator.validate( PROPERTY_NAME, null ); assertEquals( 1, result.size( ) ); assertEquals( expectedMessage, result.get( 0 ) ); }