ActorsProcessor extends AbstractProcessor { @VisibleForTesting void parseModel(@NotNull ActorParsedModel model, @NotNull RoundEnvironment environment) { if (model.collectInterfaces) { final Set<? extends Element> elements = environment.getElementsAnnotatedWith(ActorInterface.class); for (Element element : elements) { model.interfaces.add(mModelFactory.createInterfaceDescription(element)); } } if (model.collectPackages) { Set<? extends Element> packages = environment.getElementsAnnotatedWith(ActorsPackage.class); for (Element _package : packages) { model.packages.add(mModelFactory.createPackageDescription(_package)); } } } @SuppressWarnings("unused")  ActorsProcessor(); @VisibleForTesting  ActorsProcessor(@NotNull ModelFactory modelFactory); @Override synchronized void init(ProcessingEnvironment processingEnv); @Override SourceVersion getSupportedSourceVersion(); @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv);  }
@Test public void parseModel_interfacesList_notEmptyActorsInterfaces() { ActorInterfaceDescription interface1 = Mockito.mock(ActorInterfaceDescription.class); ActorInterfaceDescription interface2 = Mockito.mock(ActorInterfaceDescription.class); ActorInterfaceDescription interface3 = Mockito.mock(ActorInterfaceDescription.class); Mockito.doReturn(interface1).doReturn(interface2).doReturn(interface3).when(mFactory).createInterfaceDescription(Mockito.<Element>any()); HashSet<Element> elements = new HashSet<>(); elements.add(Mockito.mock(Element.class)); elements.add(Mockito.mock(Element.class)); elements.add(Mockito.mock(Element.class)); Mockito.doReturn(elements).when(mEnvironment).getElementsAnnotatedWith(ActorInterface.class); ActorParsedModel model = new ActorParsedModel(); model.collectInterfaces = true; ActorsProcessor processor = new ActorsProcessor(mFactory); processor.parseModel(model, mEnvironment); for (Element element : elements) { Mockito.verify(mFactory).createInterfaceDescription(element); } Mockito.verifyNoMoreInteractions(mFactory); Assert.assertSame(interface1, model.interfaces.get(0)); Assert.assertSame(interface2, model.interfaces.get(1)); Assert.assertSame(interface3, model.interfaces.get(2)); }
@Test public void parseModel_packagesList_notEmptyPackages() { ActorsPackageDescription package1 = Mockito.mock(ActorsPackageDescription.class); Mockito.doReturn(package1).when(mFactory).createPackageDescription(Mockito.<Element>any()); Element element = Mockito.mock(Element.class); HashSet<Element> elements = new HashSet<>(); elements.add(element); Mockito.doReturn(elements).when(mEnvironment).getElementsAnnotatedWith(ActorsPackage.class); ActorParsedModel model = new ActorParsedModel(); model.collectPackages = true; ActorsProcessor processor = new ActorsProcessor(mFactory); processor.parseModel(model, mEnvironment); Mockito.verify(mFactory).createPackageDescription(element); Mockito.verifyNoMoreInteractions(mFactory); Assert.assertSame(package1, model.packages.get(0)); }