ValidationExceptionMessageExtractor { public void extract(MessageContext context, ValidationException e) { if (e.hasChildExceptions()) { List<ValidationException> children = e.getChildExceptions(); for (ValidationException child : children) { if (child instanceof BadNumericResponseException) { extractBadNumericResponseException(context, (BadNumericResponseException) child); } else if (child instanceof MandatoryAnswerNotFoundException) { extractMandatoryAnswerNotFoundException(context, (MandatoryAnswerNotFoundException) child); } else { extractDefault(context, child); } } } }  void extract(MessageContext context, ValidationException e);  }
@Test public void testMandatoryAnswerNotFoundException() { MandatoryAnswerNotFoundException e = new MandatoryAnswerNotFoundException("Title"); ValidationException parent = new ValidationException("Key"); parent.addChildException(e); ValidationExceptionMessageExtractor extractor = new ValidationExceptionMessageExtractor(); extractor.extract(context, parent); verify(context).addMessage(any(MessageResolver.class)); }
@Test public void testValidationException() { ValidationException parent = new ValidationException("Key 1"); ValidationException child = new ValidationException("Key 2"); parent.addChildException(child); ValidationExceptionMessageExtractor extractor = new ValidationExceptionMessageExtractor(); extractor.extract(context, parent); verify(context).addMessage(any(MessageResolver.class)); }