Skip to content

Commit 4b7a7f5

Browse files
authored
Merge pull request #1361 from hcoles/feature/cross_module
Maven cross module tests
2 parents d93b3c2 + a94bd6a commit 4b7a7f5

File tree

18 files changed

+450
-47
lines changed

18 files changed

+450
-47
lines changed

pitest-entry/src/main/java/org/pitest/classpath/DefaultCodeSource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.pitest.functional.Streams;
99

1010
import java.util.Collection;
11+
import java.util.HashSet;
1112
import java.util.Optional;
1213
import java.util.Set;
1314
import java.util.stream.Collectors;
@@ -36,7 +37,7 @@ public Stream<ClassTree> codeTrees() {
3637
}
3738

3839
public Set<ClassName> getCodeUnderTestNames() {
39-
return this.classPath.code().stream().collect(Collectors.toSet());
40+
return new HashSet<>(this.classPath.code());
4041
}
4142

4243
public Set<ClassName> getTestClassNames() {

pitest-entry/src/main/java/org/pitest/mutationtest/config/ReportOptions.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
import org.pitest.util.Verbosity;
3434

3535
import java.io.File;
36-
import java.io.FileInputStream;
3736
import java.io.IOException;
3837
import java.io.InputStreamReader;
3938
import java.io.Reader;
4039
import java.nio.charset.Charset;
4140
import java.nio.charset.StandardCharsets;
41+
import java.nio.file.Files;
4242
import java.nio.file.Path;
4343
import java.util.ArrayList;
4444
import java.util.Arrays;
@@ -502,8 +502,7 @@ public Optional<Reader> createHistoryReader() {
502502
try {
503503
if (this.historyInputLocation.exists()
504504
&& (this.historyInputLocation.length() > 0)) {
505-
return Optional.ofNullable(new InputStreamReader(new FileInputStream(
506-
this.historyInputLocation), StandardCharsets.UTF_8));
505+
return Optional.of(new InputStreamReader(Files.newInputStream(this.historyInputLocation.toPath()), StandardCharsets.UTF_8));
507506
}
508507
return Optional.empty();
509508
} catch (final IOException ex) {

pitest-entry/src/main/java/org/pitest/mutationtest/tooling/EntryPoint.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public AnalysisResult execute(File baseDir, ReportOptions data,
111111
final LaunchOptions launchOptions = new LaunchOptions(ja,
112112
settings.getJavaExecutable(), createJvmArgs(data), environmentVariables)
113113
.usingClassPathJar(data.useClasspathJar());
114+
114115
final ProjectClassPaths cps = data.getMutationClassPaths();
115116

116117
final CodeSource code = settings.createCodeSource(cps);

pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -360,21 +360,6 @@ public void shouldWorkWithGWTMockito() throws Exception {
360360
assertThat(actual).doesNotContain("status='RUN_ERROR'");
361361
}
362362

363-
@Test
364-
@Ignore("yatspec is not available on maven central. Repo currently down")
365-
public void shouldWorkWithYatspec() throws Exception {
366-
File testDir = prepare("/pit-263-yatspec");
367-
verifier.executeGoal("test");
368-
verifier.executeGoal("org.pitest:pitest-maven:mutationCoverage");
369-
370-
String actual = readResults(testDir);
371-
assertThat(actual)
372-
.contains(
373-
"<mutation detected='true' status='KILLED' numberOfTestsRun='1'><sourceFile>SomeClass.java</sourceFile>");
374-
assertThat(actual).doesNotContain("status='NO_COVERAGE'");
375-
assertThat(actual).doesNotContain("status='RUN_ERROR'");
376-
}
377-
378363
@Test
379364
// note this test depends on the junit5 plugin
380365
public void shouldWorkWithQuarkus() throws Exception {
@@ -465,6 +450,31 @@ public void resolvesCorrectFilesForKotlinMultiModules() throws Exception {
465450

466451
}
467452

453+
@Test
454+
public void handlesTestsInSeparateModulesWhenConfigured()
455+
throws Exception {
456+
File testDir = prepare("/pit-cross-module-tests");
457+
458+
verifier.executeGoal("install");
459+
verifier.executeGoal("org.pitest:pitest-maven:mutationCoverage");
460+
461+
verifier.executeGoal("org.pitest:pitest-maven:report-aggregate-module");
462+
463+
File siteParentDir = buildFilePath(testDir, "target", "pit-reports");
464+
assertThat(buildFilePath(siteParentDir, "index.html")).exists();
465+
String projectReportsHtmlContents = FileUtils
466+
.readFileToString(buildFilePath(testDir, "target", "pit-reports",
467+
"index.html"));
468+
469+
assertTrue("miss data of subModule 1",
470+
projectReportsHtmlContents
471+
.contains("<a href=\"./org.example1/index.html\">org.example1</a>"));
472+
473+
assertTrue("coverage included",
474+
projectReportsHtmlContents
475+
.contains("85%"));
476+
}
477+
468478
private void runForJava8Only() {
469479
String javaVersion = System.getProperty("java.version");
470480
assumeTrue(javaVersion.startsWith("1.8"));
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.example</groupId>
6+
<artifactId>pit-parent-module</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>cross-tests-code</artifactId>
11+
<packaging>jar</packaging>
12+
<version>1.0-SNAPSHOT</version>
13+
<name>cross-tests-code</name>
14+
<dependencies>
15+
<dependency>
16+
<groupId>junit</groupId>
17+
<artifactId>junit</artifactId>
18+
<version>${junit.version}</version>
19+
</dependency>
20+
</dependencies>
21+
<build>
22+
<plugins>
23+
<plugin>
24+
<groupId>org.apache.maven.plugins</groupId>
25+
<artifactId>maven-compiler-plugin</artifactId>
26+
<configuration>
27+
<source>1.8</source>
28+
<target>1.8</target>
29+
</configuration>
30+
</plugin>
31+
32+
</plugins>
33+
</build>
34+
<properties>
35+
<junit.version>4.13.1</junit.version>
36+
</properties>
37+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.example1;
2+
3+
public class SystemUnderTest {
4+
5+
private int aNumber = 0;
6+
7+
public SystemUnderTest() {
8+
super();
9+
10+
int a = 25;
11+
int b = 10;
12+
if (a < b) {
13+
aNumber = 10;
14+
} else {
15+
aNumber = -25;
16+
}
17+
}
18+
19+
public String toString() {
20+
return "SystemUnderTest";
21+
}
22+
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.example2;
2+
3+
public class SystemUnderTest {
4+
5+
private int aNumber = 0;
6+
7+
public SystemUnderTest() {
8+
super();
9+
10+
int a = 25;
11+
int b = 10;
12+
if (a < b) {
13+
aNumber = 10;
14+
} else {
15+
aNumber = -25;
16+
}
17+
}
18+
19+
public int getNumber() {
20+
return aNumber;
21+
}
22+
23+
public String toString() {
24+
return "SystemUnderTest";
25+
}
26+
27+
public boolean isActive() {
28+
return false;
29+
}
30+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.example</groupId>
6+
<artifactId>pit-parent-module</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>cross-tests-tests</artifactId>
11+
<packaging>jar</packaging>
12+
<version>1.0-SNAPSHOT</version>
13+
<name>cross-tests-tests</name>
14+
<dependencies>
15+
<dependency>
16+
<groupId>junit</groupId>
17+
<artifactId>junit</artifactId>
18+
<version>${junit.version}</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.example</groupId>
22+
<artifactId>cross-tests-code</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
</dependencies>
26+
<build>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-compiler-plugin</artifactId>
31+
<configuration>
32+
<source>1.8</source>
33+
<target>1.8</target>
34+
</configuration>
35+
</plugin>
36+
37+
</plugins>
38+
</build>
39+
<properties>
40+
<junit.version>4.13.1</junit.version>
41+
</properties>
42+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.example1;
2+
3+
import static junit.framework.Assert.assertTrue;
4+
import static junit.framework.Assert.assertNotNull;
5+
6+
import java.io.File;
7+
import org.junit.Test;
8+
9+
public class FileOpeningTest {
10+
11+
@Test
12+
public void testOpenFileRelativeToWorkingDirectory() {
13+
SystemUnderTest sut = new SystemUnderTest();
14+
15+
File file = new File("src/test/resources/fixture.file");
16+
assertTrue(file.exists());
17+
assertNotNull(sut.toString());
18+
}
19+
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.example2;
2+
3+
import static junit.framework.Assert.assertTrue;
4+
import static junit.framework.Assert.assertNotNull;
5+
6+
import java.io.File;
7+
import org.junit.Test;
8+
9+
public class FileOpeningTest {
10+
11+
@Test
12+
public void testOpenFileRelativeToWorkingDirectory() {
13+
SystemUnderTest sut = new SystemUnderTest();
14+
15+
File file = new File("src/test/resources/fixture.file");
16+
assertTrue(file.exists());
17+
assertNotNull(sut.toString());
18+
}
19+
20+
21+
}

0 commit comments

Comments
 (0)