AnnotationValidator extends AbstractAnnotationValidator implements ClassLoaderAwareServletContainerInitializer { @Override public void process(Set<Class<?>> classSet, ServletContext servletContext) throws ServletException { validateClasses(classSet); }  @Override void process(Set<Class<?>> classSet, ServletContext servletContext); @Override List<Class<?>> getAnnotations();  }
@Test public void onStartUp_all_failing_anotations_are_reported() throws ServletException { try { annotationValidator.process(Stream .of(InlineViewportWithParent.class, BodySizeViewportWithParent.class, ViewPortViewportWithParent.class) .collect(Collectors.toSet()), servletContext); Assert.fail("No exception was thrown for faulty setup."); } catch (InvalidApplicationConfigurationException iace) { String errorMessage = iace.getMessage(); Assert.assertTrue("Exception has wrong beginning.", errorMessage.startsWith(ERROR_MESSAGE_BEGINNING)); Assert.assertTrue("Exception was missing Inline exception", errorMessage.contains(String.format(NON_PARENT, InlineViewportWithParent.class.getName(), "@" + Inline.class.getSimpleName()))); Assert.assertTrue("Exception was missing Viewport exception", errorMessage.contains(String.format(NON_PARENT, ViewPortViewportWithParent.class.getName(), "@" + Viewport.class.getSimpleName()))); Assert.assertTrue("Exception was missing BodySize exception", errorMessage.contains(String.format(NON_PARENT, BodySizeViewportWithParent.class.getName(), "@" + BodySize.class.getSimpleName()))); } }
@Test public void onStartUp_all_failing_annotations_are_marked_for_class() throws ServletException { expectedEx.expect(InvalidApplicationConfigurationException.class); expectedEx.expectMessage(ERROR_MESSAGE_BEGINNING + String.format( NON_PARENT, FailingMultiAnnotation.class.getName(), "@" + BodySize.class.getSimpleName() + ", " + "@" + Inline.class.getSimpleName())); annotationValidator.process(Stream.of(FailingMultiAnnotation.class) .collect(Collectors.toSet()), servletContext); Assert.fail("No exception was thrown for faulty setup."); }
@Test public void onStartUp_no_exception_is_thrown_for_correctly_setup_classes() throws ServletException { annotationValidator .process(Stream.of(MultiAnnotation.class, AbstractMain.class) .collect(Collectors.toSet()), servletContext); }