CodeGeneratorMojo extends AbstractMojo { protected List<CodeGenerator> initGenerators() { List<CodeGenerator> codeGenerators = new ArrayList<>(); codeGenerators.add(new DefaultCodeGenerator()); ServiceLoader<CodeGenerator> serviceLoader = ServiceLoader.load(CodeGenerator.class, this.getClass().getClassLoader()); Iterator<CodeGenerator> iterator = serviceLoader.iterator(); while (iterator.hasNext()) { codeGenerators.add(iterator.next()); } getLog().info("Loaded code generators: " + StringUtils.join(codeGenerators, ",")); return codeGenerators; }  @Override void execute(); static void main(String[] args);  }
@Test public void testInitGenerators() { CodeGeneratorMojo mojo = new CodeGeneratorMojo(); List<CodeGenerator> codeGenerators = mojo.initGenerators(); assertThat("There should be the default code generator and the test edit one", codeGenerators.size(), is(2)); }