ConnectEndpointsValidator implements ClassLoaderAwareServletContainerInitializer, Serializable { @Override public void process(Set<Class<?>> classSet, ServletContext servletContext) throws ServletException { if (classSet == null) { return; } ClassFinder finder = new DefaultClassFinder(classSet); Set<Class<?>> endpoints = finder.getAnnotatedClasses(Endpoint.class); if (!endpoints.isEmpty()) { try { finder.loadClass(classToCheck); } catch (ClassNotFoundException e) { throw new ServletException( "ERROR: Vaadin Connect Endpoints only work for Spring " + "enabled projects.\n" + "This is not a spring application but there are connect endpoints in these classes: " + endpoints.stream().map(Class::getName) .collect( Collectors.joining("\n - ")), e); } } }  @Override void process(Set<Class<?>> classSet, ServletContext servletContext);  }
@Test public void should_start_when_spring_in_classpath() throws Exception { ConnectEndpointsValidator validator = new ConnectEndpointsValidator(); classes.add(WithConnectEndpoint.class); validator.process(classes, servletContext); }
@Test public void should_start_when_no_endpoints_and_spring_not_in_classpath() throws Exception { ConnectEndpointsValidator validator = new ConnectEndpointsValidator(); classes.add(WithoutConnectEndpoint.class); validator.process(classes, servletContext); }
@Test public void should_start_when_CDI_environment() throws Exception { ConnectEndpointsValidator validator = new ConnectEndpointsValidator(); classes = null; validator.process(classes, servletContext); }