PojoGenerator extends AbstractMojo { @Override public void execute() throws MojoExecutionException { validateParameters(); project.addCompileSourceRoot(outputDirectory.getPath()); Map<JavaInterfaceSource, String> interfaces = getInterfaces(); Map<JavaClassSource, String> pojos = createPojos(interfaces); final File outputPackage = new File(outputDirectory, implementationPackageSuffix.replaceAll("\\.", "/")); if (!outputPackage.exists()) { outputPackage.mkdirs(); } for (Entry<JavaClassSource, String> pojoEntry : pojos.entrySet()) { File fileDir = outputPackage; if ("".equals(pojoEntry.getValue())) { fileDir = new File(outputPackage, pojoEntry.getValue()); if (!fileDir.exists()) { fileDir.mkdirs(); } } File javaFile = new File(fileDir, pojoEntry.getKey().getName() + ".java"); try (FileWriter w = new FileWriter(javaFile)) { w.write(pojoEntry.getKey().toString()); } catch (IOException e) { throw new MojoExecutionException("Error creating file " + javaFile, e); } } }  @Override void execute();  }
@Test public void testSomething() throws Exception { File pom = new File("target/test-classes/project-to-test/"); assertNotNull(pom); assertTrue(pom.exists()); PojoGenerator pojoGenerator = (PojoGenerator) rule.lookupConfiguredMojo(pom, "generatePojos"); assertNotNull(pojoGenerator); File outputDirectory = (File) rule.getVariableValueFromObject(pojoGenerator, "outputDirectory"); assertNotNull(outputDirectory); File interfaceDirectory = (File) rule.getVariableValueFromObject(pojoGenerator, "interfaceDirectory"); assertNotNull(interfaceDirectory); String implementationPackageSuffix = (String) rule.getVariableValueFromObject(pojoGenerator, "implementationPackageSuffix"); assertNotNull(implementationPackageSuffix); List<File> interfaceFiles = Files.walk(interfaceDirectory.toPath()) .filter(Files::isRegularFile) .map(path -> path.toFile()) .filter(file -> file.getAbsolutePath().endsWith(".java")) .collect(Collectors.toList()); assertEquals(2, interfaceFiles.size()); pojoGenerator.execute(); File outputPackage = new File(outputDirectory, implementationPackageSuffix.replaceAll("\\.", "/")); List<File> classFiles = Files.walk(outputPackage.toPath()) .filter(Files::isRegularFile) .map(path -> path.toFile()) .filter(file -> file.getAbsolutePath().endsWith(".java")) .collect(Collectors.toList()); for (File file : classFiles) { assertTrue(file.exists()); } }