PomAddPlugin extends AbstractArtifactPomOperation<PomAddPlugin> implements AddElement<PomAddPlugin> { public String getVersion() { return version; } PomAddPlugin();  PomAddPlugin(String groupId, String artifactId);  PomAddPlugin(String groupId, String artifactId, String version); PomAddPlugin setVersion(String version); @Override PomAddPlugin failIfPresent(); @Override PomAddPlugin warnNotAddIfPresent(); @Override PomAddPlugin warnButAddIfPresent(); @Override PomAddPlugin noOpIfPresent(); @Override PomAddPlugin overwriteIfPresent(); String getVersion(); @Override String getDescription(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void addPluginWithVersionTest() throws IOException, XmlPullParserException { Model pomModelBeforeChange = getOriginalPomModel("pom.xml"); assertEquals(pomModelBeforeChange.getBuild().getPlugins().size(), 3); assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo"); assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin"); PomAddPlugin pomAddPlugin = new PomAddPlugin("org.apache.maven.plugins", "maven-javadoc-plugin", "2.10.4").relative("pom.xml"); TOExecutionResult executionResult = pomAddPlugin.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS); Model pomModelAfterChange = getTransformedPomModel("pom.xml"); assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 4); Plugin plugin = new Plugin(); plugin.setGroupId("org.apache.maven.plugins"); plugin.setArtifactId("maven-javadoc-plugin"); assertTrue(pomModelAfterChange.getBuild().getPlugins().contains(plugin)); assertEquals(pomModelAfterChange.getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-javadoc-plugin").getVersion(), "2.10.4"); }
@Test public void addPluginWithoutVersionTest() throws IOException, XmlPullParserException { Model pomModelBeforeChange = getOriginalPomModel("pom.xml"); assertEquals(pomModelBeforeChange.getBuild().getPlugins().size(), 3); assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo"); assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin"); PomAddPlugin pomAddPlugin = new PomAddPlugin("org.apache.maven.plugins", "maven-javadoc-plugin").relative("pom.xml"); TOExecutionResult executionResult = pomAddPlugin.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS); Model pomModelAfterChange = getTransformedPomModel("pom.xml"); assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 4); Plugin plugin = new Plugin(); plugin.setGroupId("org.apache.maven.plugins"); plugin.setArtifactId("maven-javadoc-plugin"); assertTrue(pomModelAfterChange.getBuild().getPlugins().contains(plugin)); assertNull(pomModelAfterChange.getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-javadoc-plugin").getVersion()); }