Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for multi source sets #888

Merged
merged 6 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())));
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
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() {}
}