### Question:
PersistenceDescriptorValidationMessageTranslator implements ValidationMessageTranslator { @Override public ValidationMessage translate( ValidationMessage checkMessage ) { PersistenceDescriptorValidationMessage pdValidationMessage = ( PersistenceDescriptorValidationMessage ) checkMessage; ValidationMessage result = new ValidationMessage( ); result.setId( checkMessage.getId( ) ); result.setLevel( checkMessage.getLevel( ) ); String translationKey = createTranslationKey( pdValidationMessage.getId( ) ); if ( translationService.getTranslation( translationKey ) != null ) { if ( pdValidationMessage.getParams( ) != null && !pdValidationMessage.getParams( ).isEmpty( ) ) { pdValidationMessage.getParams().toArray( new String[ pdValidationMessage.getParams().size() ] ); result.setText( translationService.format( translationKey, pdValidationMessage.getParams().toArray() ) ); } else { result.setText( translationService.getTranslation( translationKey ) ); } } else { result.setText( checkMessage.getText( ) ); } return result; } @Inject  PersistenceDescriptorValidationMessageTranslator( TranslationService translationService ); @Override boolean accept( ValidationMessage checkMessage ); @Override ValidationMessage translate( ValidationMessage checkMessage ); static final String PREFIX; }### Answer:
@Test public void testSimpleTranslation( ) { String translationKey = PersistenceDescriptorValidationMessageTranslator.PREFIX + originalMessage.getId( ); when( translationService.getTranslation( translationKey ) ).thenReturn( TRANSLATED_MESSAGE ); ValidationMessage expectedTranslatedMessage = new ValidationMessage( ); expectedTranslatedMessage.setId( originalMessage.getId( ) ); expectedTranslatedMessage.setLevel( originalMessage.getLevel( ) ); expectedTranslatedMessage.setText( TRANSLATED_MESSAGE ); assertEquals( expectedTranslatedMessage, translator.translate( originalMessage ) ); }
@Test public void testParametrizedTranslation( ) { String translationKey = PersistenceDescriptorValidationMessageTranslator.PREFIX + originalMessage.getId( ); originalMessage.getParams( ).add( "param1" ); originalMessage.getParams( ).add( "param2" ); when( translationService.getTranslation( translationKey ) ).thenReturn( TRANSLATED_MESSAGE ); when( translationService.format( translationKey, originalMessage.getParams( ).toArray( ) ) ).thenReturn( FORMATTED_MESSAGE ); ValidationMessage expectedTranslatedMessage = new ValidationMessage( ); expectedTranslatedMessage.setId( originalMessage.getId( ) ); expectedTranslatedMessage.setLevel( originalMessage.getLevel( ) ); expectedTranslatedMessage.setText( FORMATTED_MESSAGE ); assertEquals( expectedTranslatedMessage, translator.translate( originalMessage ) ); }