Skip to content

Commit

Permalink
Setup approval tests to track significant behavior changes
Browse files Browse the repository at this point in the history
The following 3 cases are tested:
- writing a complex model to a new file
- updating a complex model to an existing file containing a very minimal model
- updating a complex model to the file containing the complex model
  • Loading branch information
murdos committed Feb 23, 2024
1 parent a992d18 commit a56a10a
Show file tree
Hide file tree
Showing 6 changed files with 2,846 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<version>2.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.approvaltests</groupId>
<artifactId>approvaltests</artifactId>
<version>22.3.2</version>
</dependency>
<!-- needed during tests when running on Java9+ -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/io/fabric8/maven/MavenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.apache.maven.model.Model;
import org.apache.maven.model.Scm;
import org.approvaltests.Approvals;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -120,6 +121,47 @@ void should_preserve_parent_relative_path(@TempDir Path tempDir) throws Exceptio
.isEqualTo("../../pom.xml");
}

@Test
void should_save_full_pom_on_new_file(@TempDir Path tempDir) throws Exception {
URL resource = getClass().getResource("full-pom.xml");
Path basePom = Paths.get(resource.toURI());
Model model = Maven.readModel(new FileReader(basePom.toFile()));

Path newPom = tempDir.resolve("new-pom.xml");
Maven.writeModel(model, newPom);

Approvals.verify(Files.readString(newPom));
}

@Test
void should_save_full_pom_on_updated_full_file(@TempDir Path tempDir) throws Exception {
URL resource = getClass().getResource("full-pom.xml");
Path basePom = Paths.get(resource.toURI());
Model model = Maven.readModel(new FileReader(basePom.toFile()));

Path updatedPom = tempDir.resolve("updated-full-pom.xml");
Files.copy(basePom, updatedPom);
Maven.writeModel(model, updatedPom);

Approvals.verify(Files.readString(updatedPom));
}

@Test
void should_save_full_pom_on_updated_minimal_file(@TempDir Path tempDir) throws Exception {
URL resource = getClass().getResource("full-pom.xml");
Path basePom = Paths.get(resource.toURI());
Model model = Maven.readModel(new FileReader(basePom.toFile()));

Path updatedPom = tempDir.resolve("updated-minimal-pom.xml");
Files.writeString(updatedPom, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+
" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" />");
Maven.writeModel(model, updatedPom);

Approvals.verify(Files.readString(updatedPom));
}

@Test
void should_write_scm_tag(@TempDir Path tempDir) throws Exception {
Path pomXml = tempDir.resolve("pom.xml");
Expand Down
Loading

0 comments on commit a56a10a

Please sign in to comment.