CrestCommandLoaderDescriptorGeneratorMojo extends AbstractMojo { private void scan(final Collection<String> commands, final File file) throws IOException { if (file.isFile()) { if (file.getName().endsWith(".class")) { final String command = commandName(file); if (command != null) { commands.add(command); } } } else if (file.isDirectory()) { final File[] children = file.listFiles(); if (children != null) { for (final File child : children) { scan(commands, child); } } } }  @Override void execute();  }
@Test public void scan() throws IOException, MojoFailureException, MojoExecutionException { final CrestCommandLoaderDescriptorGeneratorMojo mojo = new CrestCommandLoaderDescriptorGeneratorMojo(); mojo.classes = new File("target/test-classes"); mojo.output = new File("target/CrestCommandLoaderDescriptorGeneratorMojoTest/test.txt"); mojo.execute(); final BufferedReader reader = new BufferedReader(new FileReader(mojo.output)); final Collection<String> found = new HashSet<>(); String line; while ((line = reader.readLine()) != null) { found.add(line); } reader.close(); assertEquals(new HashSet<String>() {{ add(ClassCommand.class.getName()); add(MethodCommand.class.getName()); }}, found); }