Skip to content

Commit

Permalink
Add support for multiple test sources sets
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdebruin committed Nov 1, 2024
1 parent 8f7d930 commit 638fcc5
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,10 @@ private Stream<SourceFile> processTestSources(
javaParserBuilder.classpath(testDependencies).typeCache(typeCache);
kotlinParserBuilder.classpath(testDependencies).typeCache(new JavaTypeCache());

List<Path> testJavaSources = listJavaSources(mavenProject.getBasedir().toPath().resolve(mavenProject.getBuild().getTestSourceDirectory()));
Set<Path> testJavaSources = new LinkedHashSet<>(listJavaSources(mavenProject.getBasedir().toPath().resolve(mavenProject.getBuild().getTestSourceDirectory())));
for (String p : mavenProject.getTestCompileSourceRoots()) {
testJavaSources.addAll(listJavaSources(mavenProject.getBasedir().toPath().resolve(p)));
}
alreadyParsed.addAll(testJavaSources);

// scan Kotlin files
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/openrewrite/maven/RewriteRunIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ void multi_module_project(MavenExecutionResult result) {
.anySatisfy(line -> assertThat(line).contains("org.openrewrite.staticanalysis.SimplifyBooleanExpression"));
}

@MavenTest
@SystemProperties({
@SystemProperty(value = "rewrite.activeRecipes", content = "org.openrewrite.java.search.FindTypes"),
@SystemProperty(value = "rewrite.options", content = "fullyQualifiedTypeName=org.junit.jupiter.api.Test")
})
@Disabled
void multi_source_sets_project(MavenExecutionResult result) {
assertThat(result)
.isSuccessful()
.out()
.warn()
.contains("Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/project/src/integration-test/java/sample/SomeIntegrationTest.java by:")
.contains("Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/project/src/test/java/sample/CoolTest.java by:");
}

@MavenTest
void single_project(MavenExecutionResult result) {
assertThat(result)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>

<groupId>org.openrewrite.maven</groupId>
<artifactId>multi_source_sets_project</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>add integration test sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package sample;

import org.junit.jupiter.api.Test;

class SomeIntegrationTest {
@Test
void testBar() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package sample;

import org.junit.jupiter.api.Test;

class CoolTest {
@Test
void testBar() {}
}

0 comments on commit 638fcc5

Please sign in to comment.