Skip to content

Commit

Permalink
Add tests for multi source sets (#888)
Browse files Browse the repository at this point in the history
* Add support for multiple test sources sets

* Rename test files to something more meaningful

* Reduce warnings

* Run `generate-test-sources` before build helper test

* Revert back to a list now there's no duplicates

* Drop unneeded plugin reference; that's handled in RewriteRunIT

---------

Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
nielsdebruin and timtebeek authored Nov 1, 2024
1 parent 8f7d930 commit d86d22c
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ protected enum State {
private static final String OPENREWRITE_PROCESSED_MARKER = "openrewrite.processed";

protected void putState(State state) {
//noinspection unchecked
getPluginContext().put(OPENREWRITE_PROCESSED_MARKER, state.name());
}

Expand Down
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()));
List<Path> testJavaSources = new ArrayList<>();
for (String p : mavenProject.getTestCompileSourceRoots()) {
testJavaSources.addAll(listJavaSources(mavenProject.getBasedir().toPath().resolve(p)));
}
alreadyParsed.addAll(testJavaSources);

// scan Kotlin files
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/org/openrewrite/maven/MeterRegistryProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
import io.rsocket.transport.ClientTransport;
import io.rsocket.transport.netty.client.TcpClientTransport;
import io.rsocket.transport.netty.client.WebsocketClientTransport;
import org.apache.maven.plugin.logging.Log;
import org.jspecify.annotations.Nullable;
import org.apache.maven.plugin.logging.Log;
import org.jspecify.annotations.Nullable;
import reactor.netty.http.client.HttpClient;
import reactor.netty.tcp.TcpClient;
import reactor.util.retry.Retry;

import java.net.URI;
import java.time.Duration;
import java.util.Base64;

import java.util.Base64;

public class MeterRegistryProvider implements AutoCloseable {
private final Log log;
private final Log log;

@Nullable
private final String uriString;
private final String uriString;

@Nullable
private final String username;
private final String username;

@Nullable
private final String password;
Expand Down Expand Up @@ -115,6 +115,7 @@ private MeterRegistry buildRegistry() {
}

private ClientTransport getWebsocketClientTransport(TcpClient tcpClient) {
//noinspection deprecation
HttpClient httpClient = HttpClient.from(tcpClient).wiretap(true);
if (username != null && password != null) {
httpClient = httpClient.headers(h -> h.add("Authorization", "Basic: " + Base64.getUrlEncoder()
Expand Down
37 changes: 27 additions & 10 deletions src/test/java/org/openrewrite/maven/RewriteRunIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ 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")
})
@MavenGoal("generate-test-sources")
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/IntegrationTest.java by:",
"Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/project/src/test/java/sample/RegularTest.java by:"
);
}

@MavenTest
void single_project(MavenExecutionResult result) {
assertThat(result)
Expand Down Expand Up @@ -113,16 +130,16 @@ void java_compiler_plugin_project(MavenExecutionResult result) {
@SystemProperty(value = "rewrite.additionalPlainTextMasks", content = "**/*.ext,**/.in-root")
void plaintext_masks(MavenExecutionResult result) {
assertThat(result)
.isSuccessful()
.out()
.warn()
.contains(
"Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/src/main/java/sample/in-src.ext by:",
"Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/.in-root by:",
"Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/from-default-list.py by:",
"Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/src/main/java/sample/Dummy.java by:"
)
.doesNotContain("in-root.ignored");
.isSuccessful()
.out()
.warn()
.contains(
"Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/src/main/java/sample/in-src.ext by:",
"Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/.in-root by:",
"Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/from-default-list.py by:",
"Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/src/main/java/sample/Dummy.java by:"
)
.doesNotContain("in-root.ignored");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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>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,8 @@
package sample;

import org.junit.jupiter.api.Test;

class IntegrationTest {
@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 RegularTest {
@Test
void testBar() {}
}

0 comments on commit d86d22c

Please sign in to comment.