From 1b3c0bd20d43e868e1cead1e60f99d8d6c250c11 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Fri, 16 Feb 2024 15:01:46 +0100 Subject: [PATCH] Add indent test (failing) --- .../maven/merge/SmartModelMergerTest.java | 28 +++++++++++++++++++ .../fabric8/maven/merge/indent/source-pom.xml | 15 ++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/test/resources/io/fabric8/maven/merge/indent/source-pom.xml diff --git a/src/test/java/io/fabric8/maven/merge/SmartModelMergerTest.java b/src/test/java/io/fabric8/maven/merge/SmartModelMergerTest.java index 9e91c2a..ffa7754 100644 --- a/src/test/java/io/fabric8/maven/merge/SmartModelMergerTest.java +++ b/src/test/java/io/fabric8/maven/merge/SmartModelMergerTest.java @@ -2,8 +2,12 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; +import io.fabric8.maven.Maven; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.Profile; @@ -89,4 +93,28 @@ public void should_merge_profiles() { assertThat(target.getProfiles().get(0).getModules()).containsExactly("A", "B", "C", "D", "E", "F"); } + @Test + void should_keep_target_indent_2() throws URISyntaxException { + ModelMerger merger = new SmartModelMerger(); + final Model source = Maven.readModel(Paths.get(getClass().getResource("indent/source-pom.xml").toURI())); + final Path targetFile = Paths.get(getClass().getResource("indent/pom-2.xml").toURI()); + final Model target = Maven.readModel(targetFile); + merger.merge(target, source, false, null); + Maven.writeModel(target, targetFile); + assertThat(targetFile).hasSameBinaryContentAs(Paths.get(getClass().getResource("indent/result-pom-2.xml").toURI())); + } + + @Test + void should_keep_target_indent_4() throws URISyntaxException { + ModelMerger merger = new SmartModelMerger(); + final Model source = Maven.readModel(Paths.get(getClass().getResource("indent/source-pom.xml").toURI())); + final Path targetFile = Paths.get(getClass().getResource("indent/pom-4.xml").toURI()); + final Model target = Maven.readModel(targetFile); + merger.merge(target, source, true, null); + Maven.writeModel(target, targetFile); + assertThat(targetFile).hasSameBinaryContentAs(Paths.get(getClass().getResource("indent/result-pom-4.xml").toURI())); + } + + + } diff --git a/src/test/resources/io/fabric8/maven/merge/indent/source-pom.xml b/src/test/resources/io/fabric8/maven/merge/indent/source-pom.xml new file mode 100644 index 0000000..d6f2349 --- /dev/null +++ b/src/test/resources/io/fabric8/maven/merge/indent/source-pom.xml @@ -0,0 +1,15 @@ + + + + + org.apache.maven + maven-model-builder + 3.5.4 + + + org.apache.maven + maven-model + 3.5.4 + + + \ No newline at end of file