Skip to content

Commit

Permalink
Added test for getting maven source directory from ancestors
Browse files Browse the repository at this point in the history
  • Loading branch information
Strum355 committed Sep 3, 2020
1 parent 221cfdb commit 7c8b185
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/test/java/spoon/support/compiler/SpoonPomTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;

import static org.junit.Assert.*;

Expand All @@ -30,4 +31,21 @@ public void checkVersion(String path, int expected) throws IOException, XmlPullP
//contract: Java version is read accurately from pom and does not trigger exceptions
assertEquals(expected, version);
}

@Test
public void getSourceDirectory() throws IOException, XmlPullParserException {
checkSourceDirectory(
"src/test/resources/maven-launcher/hierarchy",
Paths.get("src/test/resources/maven-launcher/hierarchy/child/src").toAbsolutePath().toString()
);
}

public void checkSourceDirectory(String path, String expected) throws IOException, XmlPullParserException {
SpoonPom pomModel = new SpoonPom(path, null, MavenLauncher.SOURCE_TYPE.APP_SOURCE, new StandardEnvironment());

SpoonPom childModel = pomModel.getModules().get(0);
//contract: source directory is derived from parent pom.xml if not declared in the current
// (childModel) SpoonPom
assertEquals(expected, childModel.getSourceDirectories().get(0).getAbsolutePath(), expected);
}
}
16 changes: 16 additions & 0 deletions src/test/resources/maven-launcher/hierarchy/child/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>sample.text</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<groupId>sample.text</groupId>
<artifactId>child</artifactId>
<version>0.0.1-SNAPSHOT</version>

<packaging>jar</packaging>
</project>
24 changes: 24 additions & 0 deletions src/test/resources/maven-launcher/hierarchy/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>sample.text</groupId>
<artifactId>project</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/>
</parent>
<groupId>sample.text</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>

<packaging>pom</packaging>

<modules>
<module>child</module>
</modules>

<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
</build>
</project>

0 comments on commit 7c8b185

Please sign in to comment.