private static void checkViolations ( List < String > givenViolations , List < String > expectedValidationViolations ) { /* * check if number of expected violations matches the given violations */ Assert . assertEquals ( String . format ( "number of expected validation violations (%s) does not match the number of given violations (%s)" , StringUtils . join ( expectedValidationViolations , LIST_DELIMITER ) , StringUtils . join ( givenViolations , LIST_DELIMITER ) ) , expectedValidationViolations . size ( ) , givenViolations . size ( ) ) ; /* * check if the set of given violations matches the expected violations */ boolean listsAreCongruent = true ; List < String > givenButNotExpected = new ArrayList < String > ( ) ; for ( String givenViolation : givenViolations ) { if ( ! expectedValidationViolations . contains ( givenViolation ) ) { listsAreCongruent = false ; givenButNotExpected . add ( givenViolation ) ; } } Assert . assertTrue ( String . format ( "the violations (%s) where given but not expected: all given violations (%s), all expected violations (%s)" , StringUtils . join ( givenButNotExpected , LIST_DELIMITER ) , StringUtils . join ( givenViolations , LIST_DELIMITER ) , StringUtils . join ( expectedValidationViolations , LIST_DELIMITER ) ) , listsAreCongruent ) ; }
Helper method doing the checking work .