ActorsProcessor extends AbstractProcessor { @VisibleForTesting boolean validateModel(@NotNull ActorParsedModel model) { boolean result = true; if (model.collectInterfaces) { for (ActorInterfaceDescription _interface : model.interfaces) { if (!_interface.validate()) { _interface.describeProblems(model.errors); result = false; } } } if (!model.collectInterfaces || model.collectPackages) { int packages = 0; for (ActorsPackageDescription _package : model.packages) { if (!_package.validate()) { _package.describeProblems(model.errors); } else { ++packages; } } switch (packages) { case 0: model.errors.add(new GenerationError(GenerationError.ER0010)); result = false; break; case 1: break; default: model.errors.add(new GenerationError(GenerationError.ER0009)); result = false; break; } } return result; } @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 validateModel_false_moreThanOnePackageAnnotations() { ActorParsedModel model = new ActorParsedModel(); ActorsPackageDescription packageDescription = Mockito.mock(ActorsPackageDescription.class); Mockito.doReturn(true).when(packageDescription).validate(); model.packages.add(packageDescription); model.packages.add(packageDescription); ActorsProcessor processor = new ActorsProcessor(mFactory); Assert.assertEquals(false, processor.validateModel(model)); Assert.assertEquals(1, model.errors.size()); Assert.assertEquals(true, model.errors.get(0).isError); Assert.assertEquals(GenerationError.ER0009, model.errors.get(0).message); }
@Test public void validateModel_false_nonValidPackage() { ActorParsedModel model = new ActorParsedModel(); ActorsPackageDescription packageDescription = Mockito.mock(ActorsPackageDescription.class); Mockito.doReturn(false).when(packageDescription).validate(); model.packages.add(packageDescription); ActorsProcessor processor = new ActorsProcessor(mFactory); Assert.assertEquals(false, processor.validateModel(model)); }
@Test public void validateModel_true_oneValidPackage() { ActorParsedModel model = new ActorParsedModel(); ActorsPackageDescription packageDescription = Mockito.mock(ActorsPackageDescription.class); Mockito.doReturn(true).when(packageDescription).validate(); model.packages.add(packageDescription); ActorsProcessor processor = new ActorsProcessor(mFactory); Assert.assertEquals(true, processor.validateModel(model)); }
@Test public void validateModel_true_validInterfaceAndCollectInterfaces() { ActorParsedModel model = new ActorParsedModel(); ActorInterfaceDescription _interface = Mockito.mock(ActorInterfaceDescription.class); Mockito.doReturn(true).when(_interface).validate(); model.collectInterfaces = true; model.interfaces.add(_interface); ActorsProcessor processor = new ActorsProcessor(mFactory); Assert.assertEquals(true, processor.validateModel(model)); }
@Test public void validateModel_false_notValidInterfaceAndCollectInterfaces() { ActorParsedModel model = new ActorParsedModel(); ActorInterfaceDescription _interface = Mockito.mock(ActorInterfaceDescription.class); Mockito.doReturn(false).when(_interface).validate(); model.collectInterfaces = true; model.interfaces.add(_interface); ActorsProcessor processor = new ActorsProcessor(mFactory); Assert.assertEquals(false, processor.validateModel(model)); Mockito.verify(_interface).describeProblems(Mockito.anyListOf(GenerationError.class)); }
@Test public void validateModel_false_noPackageAnnotations() { ActorParsedModel model = new ActorParsedModel(); ActorsProcessor processor = new ActorsProcessor(mFactory); Assert.assertEquals(false, processor.validateModel(model)); Assert.assertEquals(1, model.errors.size()); Assert.assertEquals(true, model.errors.get(0).isError); Assert.assertEquals(GenerationError.ER0010, model.errors.get(0).message); }