PomReplaceDependency extends AbstractArtifactPomOperation<PomReplaceDependency> implements ChangeOrRemoveElement<PomReplaceDependency> { @Override public PomReplaceDependency warnIfNotPresent() { ifNotPresent = IfNotPresent.Warn; return this; } PomReplaceDependency();  PomReplaceDependency(String groupId, String artifactId, String newGroupId, String newArtifactId);  PomReplaceDependency(String groupId, String artifactId, String newGroupId, String newArtifactId, String newVersion);  PomReplaceDependency(String groupId, String artifactId, String newGroupId, String newArtifactId, String newVersion, String newScope); PomReplaceDependency setNewGroupId(String newGroupId); PomReplaceDependency setNewArtifactId(String newArtifactId); PomReplaceDependency setNewVersion(String newVersion); PomReplaceDependency setNewScope(String newScope); @Override PomReplaceDependency failIfNotPresent(); @Override PomReplaceDependency warnIfNotPresent(); @Override PomReplaceDependency noOpIfNotPresent(); String getNewGroupId(); String getNewArtifactId(); String getNewVersion(); String getNewScope(); @Override String getDescription();  }
@Test public void warningNotPresentTest() { PomReplaceDependency pomReplaceDependency = new PomReplaceDependency("foo", "bar", "newfoo", "newbar").relative("pom.xml").warnIfNotPresent(); TOExecutionResult executionResult = pomReplaceDependency.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.WARNING); assertNull(executionResult.getException()); assertEquals(executionResult.getWarnings().get(0).getClass(), TransformationOperationException.class); assertEquals(executionResult.getWarnings().get(0).getMessage(), "Dependency foo:bar has not been replaced by newfoo:newbar in POM file /pom.xml because it is not present"); }
@Test public void fileDoesNotExistTest() { PomReplaceDependency pomReplaceDependency = new PomReplaceDependency("foo", "bar", "newfoo", "newbar") .relative("non_existent_file.xml") .warnIfNotPresent(); TOExecutionResult executionResult = pomReplaceDependency.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR); assertEquals(executionResult.getException().getClass(), TransformationOperationException.class); assertEquals(executionResult.getException().getMessage(), "POM file could not be modified"); assertEquals(executionResult.getException().getCause().getClass(), FileNotFoundException.class); assertEquals(executionResult.getException().getCause().getMessage(), new File(transformedAppFolder, "non_existent_file.xml").getAbsolutePath() + " (No such file or directory)"); }