RoboconfErrorHelpers { public static Map<RoboconfError,String> formatErrors( Collection<? extends RoboconfError> errors, String lang, boolean addMetadata ) { ResourceBundle resourceBundle = getResourceBundle( lang ); Map<RoboconfError,String> result = new LinkedHashMap<> (); for( RoboconfError error : errors ) { StringBuilder sb = new StringBuilder(); if( addMetadata ) { sb.append( "[ " ); sb.append( error.getErrorCode().getCategory().toString().toLowerCase()); sb.append( " ] " ); } sb.append( resourceBundle.getString( error.getErrorCode().name())); sb.append( " " ); for( Iterator<ErrorDetails> it = Arrays.asList( error.getDetails()).iterator(); it.hasNext(); ) { ErrorDetails details = it.next(); sb.append( resourceBundle.getString( details.getErrorDetailsKind().name())); sb.append( details.getElementName()); if( it.hasNext()) sb.append( resourceBundle.getString( TranslationBundle.DETAILS_SEPARATOR )); } result.put( error, sb.toString().trim()); } return result; } private  RoboconfErrorHelpers(); static boolean containsCriticalErrors( Collection<? extends RoboconfError> errors ); static Collection<RoboconfError> findWarnings( Collection<? extends RoboconfError> errors ); static List<RoboconfError> resolveErrorsWithLocation( ApplicationLoadResult alr ); static void filterErrorsForRecipes( ApplicationLoadResult alr ); static void filterErrorsForRecipes( Collection<? extends RoboconfError> errors ); static void filterErrors( Collection<? extends RoboconfError> errors, ErrorCode... errorCodes ); static Map<RoboconfError,String> formatErrors(
			Collection<? extends RoboconfError> errors,
			String lang,
			boolean addMetadata );  }
@Test public void testFormatError_en() { final String msg = "This component cannot have any parent. It cannot be instantiated under this instance."; List<RoboconfError> errors = new ArrayList<> (); errors.add( new RoboconfError( CMD_CANNOT_HAVE_ANY_PARENT )); errors.add( new RoboconfError( CMD_CANNOT_HAVE_ANY_PARENT, name( "oops" ))); errors.add( new RoboconfError( CMD_CANNOT_HAVE_ANY_PARENT, value( "oops" ))); errors.add( new RoboconfError( CMD_CANNOT_HAVE_ANY_PARENT, unexpected( "oops." ))); errors.add( new ParsingError( CMD_CANNOT_HAVE_ANY_PARENT, new File( "/test" ), 24 )); errors.add( new ParsingError( CMD_CANNOT_HAVE_ANY_PARENT, new File( "/test" ), 21, name( "you" ), variable( "v" ))); List<String> errorMessages = new ArrayList<>( RoboconfErrorHelpers.formatErrors( errors, TranslationBundle.EN, true ).values()); Assert.assertEquals( errors.size(), errorMessages.size()); Assert.assertEquals( "[ " + CMD_CANNOT_HAVE_ANY_PARENT.getCategory().name().toLowerCase() + " ] " + msg, errorMessages.get( 0 )); Assert.assertEquals( "[ " + CMD_CANNOT_HAVE_ANY_PARENT.getCategory().name().toLowerCase() + " ] " + msg + " Name: oops", errorMessages.get( 1 )); Assert.assertEquals( "[ " + CMD_CANNOT_HAVE_ANY_PARENT.getCategory().name().toLowerCase() + " ] " + msg + " Value: oops", errorMessages.get( 2 )); Assert.assertEquals( "[ " + CMD_CANNOT_HAVE_ANY_PARENT.getCategory().name().toLowerCase() + " ] " + msg + " Unexpected: oops.", errorMessages.get( 3 )); Assert.assertEquals( "[ " + CMD_CANNOT_HAVE_ANY_PARENT.getCategory().name().toLowerCase() + " ] " + msg + " File: /test. Line number: 24", errorMessages.get( 4 )); Assert.assertEquals( "[ " + CMD_CANNOT_HAVE_ANY_PARENT.getCategory().name().toLowerCase() + " ] " + msg + " Name: you. Variable: v. File: /test. Line number: 21", errorMessages.get( 5 )); }
@Test public void testFormatError_fr() { final String msg = "Ce composant ne peut pas avoir de parent. Il ne peut pas être instancié sous cette instance."; List<RoboconfError> errors = new ArrayList<> (); errors.add( new RoboconfError( CMD_CANNOT_HAVE_ANY_PARENT )); errors.add( new RoboconfError( CMD_CANNOT_HAVE_ANY_PARENT, name( "oops" ))); errors.add( new RoboconfError( CMD_CANNOT_HAVE_ANY_PARENT, value( "oops" ))); errors.add( new RoboconfError( CMD_CANNOT_HAVE_ANY_PARENT, unexpected( "oops." ))); errors.add( new ParsingError( CMD_CANNOT_HAVE_ANY_PARENT, new File( "/test" ), 24 )); errors.add( new ParsingError( CMD_CANNOT_HAVE_ANY_PARENT, new File( "/test" ), 21, name( "you" ), variable( "v" ))); List<String> errorMessages = new ArrayList<>( RoboconfErrorHelpers.formatErrors( errors, TranslationBundle.FR, false ).values()); Assert.assertEquals( errors.size(), errorMessages.size()); Assert.assertEquals( msg, errorMessages.get( 0 )); Assert.assertEquals( msg + " Nom : oops", errorMessages.get( 1 )); Assert.assertEquals( msg + " Valeur : oops", errorMessages.get( 2 )); Assert.assertEquals( msg + " Non-attendu : oops.", errorMessages.get( 3 )); Assert.assertEquals( msg + " Fichier : /test. N° de ligne : 24", errorMessages.get( 4 )); Assert.assertEquals( msg + " Nom : you. Variable : v. Fichier : /test. N° de ligne : 21", errorMessages.get( 5 )); }