MavenProcessor extends Processor<Class<?>> implements AutoCloseable { @Override protected Stream<Class<?>> annotated(Class<? extends Annotation> annotation) { if (results == null) { results = graph.scan(); } return results.getClassesWithAnnotation(annotation.getName()).stream().map(ClassInfo::loadClass); } MavenProcessor(Environment<Class<?>> environment, ClassGraph graph); @Override void close();  }
@Test void annotated() { var info = mock(ClassInfo.class); doReturn(Command.class).when(info).loadClass(); ClassInfoList list = when(mock(ClassInfoList.class).stream()).thenReturn(Stream.of(info)).getMock(); when(results.getClassesWithAnnotation(Command.class.getName())).thenReturn(list); var actual = processor.annotated(Command.class).collect(toList()); verify(graph).scan(); verify(results).getClassesWithAnnotation(Command.class.getName()); assertEquals(List.of(Command.class), actual); }