### Question:
PersistableClassValidator { public List<ValidationMessage> validate( String className, ClassLoader classLoader ) { List<ValidationMessage> result = new ArrayList<>( ); Class< ? > clazz; try { if ( className == null || className.trim( ).isEmpty( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY ) ); return result; } clazz = classLoader.loadClass( className ); Annotation[] annotations = clazz.getAnnotations( ); Optional< Annotation > persistable = Arrays.stream( annotations ) .filter( annotation -> Entity.class.equals( annotation.annotationType( ) ) || Embeddable.class.equals( annotation.annotationType( ) ) || MappedSuperclass.class.equals( annotation.annotationType( ) ) ) .findFirst( ); if ( !persistable.isPresent( ) ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE, className ), className ) ); } } catch ( ClassNotFoundException e ) { result.add( newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND, className ), className ) ); } return result; } PersistableClassValidator( ); List<ValidationMessage> validate( String className, ClassLoader classLoader );  }### Answer:
@Test public void testValidateValidPersistableClasses( ) { assertTrue( validator.validate( PersistableClass1.class.getName( ), classLoader ).isEmpty( ) ); assertTrue( validator.validate( PersistableClass2.class.getName( ), classLoader ).isEmpty( ) ); assertTrue( validator.validate( PersistableClass3.class.getName( ), classLoader ).isEmpty( ) ); }
@Test public void testValidateInvalidPersistableClasses( ) { List< ValidationMessage > result = validator.validate( NonPersistableClass1.class.getName( ), classLoader ); assertEquals( 1, result.size( ) ); ValidationMessage expectedMessage = newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_PERSISTABLE, NonPersistableClass1.class.getName( ) ), NonPersistableClass1.class.getName( ) ); assertEquals( expectedMessage, result.get( 0 ) ); result = validator.validate( NOT_EXISTING_CLASS, classLoader ); assertEquals( 1, result.size( ) ); expectedMessage = newErrorMessage( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND_ID, MessageFormat.format( PersistenceDescriptorValidationMessages.CLASS_NOT_FOUND, NOT_EXISTING_CLASS ), NOT_EXISTING_CLASS ); assertEquals( expectedMessage, result.get( 0 ) ); result = validator.validate( "", classLoader ); assertEquals( 1, result.size( ) ); expectedMessage = newErrorMessage( PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY_ID, PersistenceDescriptorValidationMessages.PERSISTABLE_CLASS_NAME_EMPTY ); assertEquals( expectedMessage, result.get( 0 ) ); result = validator.validate( null, classLoader ); assertEquals( 1, result.size( ) ); assertEquals( expectedMessage, result.get( 0 ) ); }