SpringBootAnnotationConfigProvider extends HttpConfigurationProvider { @Override @Nullable public Configuration getConfiguration(final ServletContext servletContext) { if (!this.properties.isEnabled()) { return null; } final Set<Class<? extends Annotation>> ruleAnnotations = new LinkedHashSet<>(); final List<AnnotationHandler<Annotation>> annotationHandlers = new ArrayList<>(); for (AnnotationHandler<Annotation> handler : (Iterable<AnnotationHandler<Annotation>>) ServiceLoader.load(AnnotationHandler.class)) { annotationHandlers.add(handler); ruleAnnotations.add(handler.handles()); } final ClassVisitorImpl ruleBuilderVisitor = new ClassVisitorImpl(annotationHandlers, servletContext); Set<Class<?>> scanResult = findPreparedScanResult(servletContext.getClassLoader()) .orElseGet(() -> scanClasses(ruleAnnotations)); scanResult.forEach(ruleBuilderVisitor::visit); return ruleBuilderVisitor; }  @Override @Nullable Configuration getConfiguration(final ServletContext servletContext); @Override int priority();  }
@Test void getConfiguration_classpathScanningEnabled() { this.webApplicationContextRunner.run(context -> { SpringBootAnnotationConfigProvider annotationConfigProvider = context.getBean( SpringBootAnnotationConfigProvider.class); assertThat(annotationConfigProvider).isNotNull(); MockServletContext servletContext = new MockServletContext(); Configuration configuration = annotationConfigProvider.getConfiguration(servletContext); assertThat(configuration.getRules().size()).isEqualTo(1); }); }
@Test void getConfiguration_classpathScanningDisabled() { this.webApplicationContextRunner .withPropertyValues("joinfaces.rewrite.annotation-config-provider.enabled=false") .run(context -> { SpringBootAnnotationConfigProvider annotationConfigProvider = context.getBean( SpringBootAnnotationConfigProvider.class); assertThat(annotationConfigProvider).isNotNull(); MockServletContext servletContext = new MockServletContext(); Configuration configuration = annotationConfigProvider.getConfiguration(servletContext); assertThat(configuration).isNull(); }); }
@Test void getConfiguration_noBasePackage() { this.webApplicationContextRunner.run(context -> { SpringBootAnnotationConfigProvider annotationConfigProvider = context.getBean( SpringBootAnnotationConfigProvider.class); assertThat(annotationConfigProvider).isNotNull(); MockServletContext servletContext = new MockServletContext(); Configuration configuration = annotationConfigProvider.getConfiguration(servletContext); assertThat(configuration.getRules().isEmpty()).isFalse(); }); }