OIDGenerator extends AbstractMojo { @Override public void execute() throws MojoFailureException { List<String> fileNames = new ArrayList<>(getFileNames(new ArrayList<String>(), oidDirectory.toPath())); Map<String, String> nameToOIDHashMap = new HashMap<>(); for (String fileName : fileNames) { nameToOIDHashMap.putAll(parseOIDsFromFile(new File(fileName))); } fileNames = new ArrayList<>(getFileNames(new ArrayList<String>(), yangDirectory.toPath())); Boolean modified = false; for (String fileName : fileNames) { try { modified = parseAndUpdateGeneratedYangFile(new File(fileName), nameToOIDHashMap) || modified; } catch (IOException e) { getLog().error("Could not process " + fileName, e); throw new MojoFailureException("Could not process " + fileName + " due to " + e); } } if (modified) { File oidClassFolder = oidClassFile.getParentFile(); if (!oidClassFolder.exists() && !oidClassFolder.mkdirs()) { throw new MojoFailureException("Error creating directory " + oidClassFolder); } try { writeLinesToFile(OID_CLASS, oidClassFile); } catch (IOException e) { getLog().info("Error writting changes to file", e); } } } @SuppressWarnings("unused")  OIDGenerator();   OIDGenerator(File oidDirectory, File yangDirectory, File oidClassFile); @Override void execute();  }
@Test public void testExecute() throws Exception { testOIDGenerator.execute(); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); String classOutputFolder = targetDir().getAbsolutePath() + "/generated-test-sources"; Iterable<String> options = Arrays.asList("-d", classOutputFolder); JavaFileObject fileObject = new JavaSourceFromString(IF_ENTRY_CLASS_NAME, changedFileBuilder.toString()); Iterable<? extends JavaFileObject> iterableFileObjects = Arrays.asList(fileObject); JavaCompiler.CompilationTask compilationTask = compiler.getTask(null, null, null, options, null, iterableFileObjects); assertTrue("Compilation failed, see stderr above", compilationTask.call()); Class<?> ifEntryClass = null; URLClassLoader classLoader = URLClassLoader.newInstance(new URL[]{new File(classOutputFolder).toURI().toURL()}); ifEntryClass = classLoader.loadClass(IF_ENTRY_CLASS_NAME); List<String> testMethodNames = Arrays.asList("getIfDescr", "getIfMtu", "setIfMtu", "setIfDescr"); assertNotNull("ifEntryClass is null", ifEntryClass); for (Method method : ifEntryClass.getMethods()) { if (testMethodNames.contains(method.getName())) { OID oid = method.getAnnotation(OID.class); assertNotNull("OID for method" + method.getName() + " was null", oid); } } }