Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -32,6 +32,7 @@
import java.util.*;

import static java.util.Objects.requireNonNull;
import static org.openrewrite.Preconditions.and;
import static org.openrewrite.Preconditions.or;

public class AdoptAssertJDurationAssertions extends Recipe {
Expand Down Expand Up @@ -74,13 +75,16 @@ public class AdoptAssertJDurationAssertions extends Recipe {
@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(
or(
new UsesMethod<>(INTEGER_ASSERT_IS_EQUAL_TO, true),
new UsesMethod<>(INTEGER_ASSERT_IS_GREATER_THAN, true),
new UsesMethod<>(INTEGER_ASSERT_IS_LESS_THAN, true),
new UsesMethod<>(LONG_ASSERT_IS_EQUAL_TO, true),
new UsesMethod<>(LONG_ASSERT_IS_GREATER_THAN, true),
new UsesMethod<>(LONG_ASSERT_IS_LESS_THAN, true)
and(
new UsesMethod<>("java.time.Duration *(..)"),
or(
new UsesMethod<>(INTEGER_ASSERT_IS_EQUAL_TO, true),
new UsesMethod<>(INTEGER_ASSERT_IS_GREATER_THAN, true),
new UsesMethod<>(INTEGER_ASSERT_IS_LESS_THAN, true),
new UsesMethod<>(LONG_ASSERT_IS_EQUAL_TO, true),
new UsesMethod<>(LONG_ASSERT_IS_GREATER_THAN, true),
new UsesMethod<>(LONG_ASSERT_IS_LESS_THAN, true)
)
), new JavaIsoVisitor<ExecutionContext>() {
@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class KotlinTestMethodsShouldReturnUnit extends Recipe {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new UsesType<>(TEST_ANNOTATION_TYPE_PATTERN, true), new KotlinIsoVisitor<ExecutionContext>() {
return Preconditions.check(Preconditions.or(new UsesType<>(TEST_ANNOTATION_TYPE_PATTERN, true), new UsesType<>("org.testng.annotations.Test", true)), new KotlinIsoVisitor<ExecutionContext>() {
@Override
public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) {
J.MethodDeclaration m = super.visitMethodDeclaration(method, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

public class TestMethodsShouldBeVoid extends Recipe {

private static final String TEST_ANNOTATION_TYPE_PATTERN = "org..*Test";
private static final List<AnnotationMatcher> JUNIT5_TEST_ANNOTATIONS = asList(
new AnnotationMatcher("@org.junit.jupiter.api.Test"),
new AnnotationMatcher("@org.junit.jupiter.api.RepeatedTest"),
Expand All @@ -59,7 +58,14 @@ public class TestMethodsShouldBeVoid extends Recipe {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(Preconditions.and(new JavaFileChecker<>(), new UsesType<>(TEST_ANNOTATION_TYPE_PATTERN, true)), new JavaIsoVisitor<ExecutionContext>() {
return Preconditions.check(Preconditions.and(
new JavaFileChecker<>(),
Preconditions.or(
new UsesType<>("org.junit.jupiter.api.Test", false),
new UsesType<>("org.junit.jupiter.api.RepeatedTest", false),
new UsesType<>("org.junit.jupiter.params.ParameterizedTest", false),
new UsesType<>("org.junit.jupiter.api.TestTemplate", false))
), new JavaIsoVisitor<ExecutionContext>() {
@Override
public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) {
J.MethodDeclaration m = super.visitMethodDeclaration(method, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RemoveIsMatcher extends Recipe {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new UsesMethod<>(ASSERT_THAT_MATCHER), new JavaVisitor<ExecutionContext>() {
return Preconditions.check(Preconditions.and(new UsesMethod<>(IS_MATCHER), new UsesMethod<>(ASSERT_THAT_MATCHER)), new JavaVisitor<ExecutionContext>() {
@Override
public J visitMethodInvocation(J.MethodInvocation mi, ExecutionContext ctx) {
if (ASSERT_THAT_MATCHER.matches(mi)) {
Expand Down
15 changes: 14 additions & 1 deletion src/main/resources/META-INF/rewrite/easymock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ recipeList:
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: org.easymock
artifactId: easymock
- org.openrewrite.java.testing.easymock.EasyMockCodeToMockito
- org.openrewrite.java.testing.mockito.MockitoBestPractices
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.easymock.EasyMockCodeToMockito
displayName: Migrate EasyMock code to Mockito
description: Change EasyMock types, mock creation, expectations and argument matchers to their Mockito equivalents, and remove replay and verify calls.
preconditions:
- org.openrewrite.java.search.HasType:
fullyQualifiedTypeName: org.easymock..*
tags:
- testing
- easymock
recipeList:
- org.openrewrite.java.testing.easymock.EasyMockVerifyToMockitoVerify
- org.openrewrite.java.RemoveMethodInvocations:
methodPattern: org.easymock.IExpectationSetters times(..)
Expand Down Expand Up @@ -156,4 +170,3 @@ recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.easymock.TestSubject
newFullyQualifiedTypeName: org.mockito.InjectMocks
- org.openrewrite.java.testing.mockito.MockitoBestPractices
19 changes: 11 additions & 8 deletions src/main/resources/META-INF/rewrite/recipes.csv

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/main/resources/META-INF/rewrite/testcontainers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ displayName: Move container classes to their Testcontainers 2 packages
description: Change Testcontainers container classes to their new package locations in Testcontainers 2.x.
preconditions:
- org.openrewrite.Singleton
- org.openrewrite.java.search.HasType:
fullyQualifiedTypeName: org.testcontainers..*
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.testcontainers.containers.BigQueryEmulatorContainer
Expand Down
22 changes: 18 additions & 4 deletions src/main/resources/META-INF/rewrite/truth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ recipeList:
onlyIfUsing: com.google.common.truth.*
acceptTransitive: true

- org.openrewrite.java.testing.truth.TruthCodeToAssertJ

- org.openrewrite.java.dependencies.RemoveDependency:
groupId: com.google.truth
artifactId: truth
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.truth.TruthCodeToAssertJ
displayName: Migrate Google Truth code to AssertJ
description: Convert Google Truth assertions, subject types and their methods to AssertJ equivalents.
preconditions:
- org.openrewrite.java.search.HasType:
fullyQualifiedTypeName: com.google.common.truth..*
tags:
- testing
- truth
- assertj
recipeList:
# Handle Truth's assert_() static method
- org.openrewrite.java.testing.truth.TruthAssertToAssertThat
# Handle assertWithMessage conversions
Expand Down Expand Up @@ -220,7 +238,3 @@ recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.google.common.truth.Truth
newFullyQualifiedTypeName: org.assertj.core.api.Assertions

- org.openrewrite.java.dependencies.RemoveDependency:
groupId: com.google.truth
artifactId: truth
179 changes: 96 additions & 83 deletions src/main/resources/META-INF/rewrite/wiremock4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,102 @@ recipeList:
artifactId: jetty-xml
version: 12.1.x
onlyIfUsing: org.eclipse.jetty.xml.*
- org.openrewrite.java.testing.wiremock.Wiremock4RelocatedTypes
- org.openrewrite.java.testing.wiremock.ReplaceRemovedConstructors
- org.openrewrite.java.testing.wiremock.ReplaceSettersWithTransform
- org.openrewrite.java.testing.wiremock.MigrateStubMappingUuidToId
- org.openrewrite.java.testing.wiremock.MigrateContentTypeHeaderCharset
- org.openrewrite.java.testing.wiremock.MigrateRequestMethodIsOneOf
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.github.tomakehurst.wiremock.stubbing.StubMapping getUuid()
newMethodName: getId
# `value()` widened its return type to `Object` in 4.x; `getName()` still answers a `String`
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.github.tomakehurst.wiremock.http.RequestMethod value()
newMethodName: getName
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.wiremock.RemoveDuplicateContentTypeHeaders
displayName: Keep a single `Content-Type` response header while still on WireMock 3
description: >-
Collapse duplicate `Content-Type` response headers in both stub files and the Java DSL, but only where the
module still depends on WireMock 3.x. Jetty 11 already served a single value there, so dropping the rest
changes nothing; against 4.x the extra values really do reach the client, and removing them would.
tags:
- testing
- wiremock
preconditions:
- org.openrewrite.java.dependencies.search.ModuleHasDependency:
groupIdPattern: org.wiremock
artifactIdPattern: wiremock*
version: 3.x
recipeList:
- org.openrewrite.java.testing.wiremock.RemoveDuplicateContentTypeHeader
- org.openrewrite.java.testing.wiremock.RemoveDuplicateContentTypeStubHeader
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.wiremock.MigrateJettyEE10ToEE11
displayName: Move Jetty EE10 usages to EE11 alongside `wiremock-jetty12`
description: >-
WireMock 3's `wiremock-jetty12` module ran on Jetty's EE10 servlet environment, whereas WireMock 4.x runs on EE11,
so EE10 types such as the `ServletContextHandler` handed to `NotFoundHandler` no longer line up. Move EE10 packages
and dependencies over to their EE11 counterparts, but only in modules depending on `wiremock-jetty12`, where EE10
arrived through WireMock in the first place.
tags:
- testing
- wiremock
- jetty
preconditions:
- org.openrewrite.java.dependencies.search.ModuleHasDependency:
groupIdPattern: org.wiremock
artifactIdPattern: wiremock-jetty12
recipeList:
- org.openrewrite.java.ChangePackage:
oldPackageName: org.eclipse.jetty.ee10
newPackageName: org.eclipse.jetty.ee11
recursive: true
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.eclipse.jetty.ee10
oldArtifactId: jetty-ee10-servlet
newGroupId: org.eclipse.jetty.ee11
newArtifactId: jetty-ee11-servlet
newVersion: 12.1.x
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.eclipse.jetty.ee10
oldArtifactId: jetty-ee10-servlets
newGroupId: org.eclipse.jetty.ee11
newArtifactId: jetty-ee11-servlets
newVersion: 12.1.x
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.eclipse.jetty.ee10
oldArtifactId: jetty-ee10-webapp
newGroupId: org.eclipse.jetty.ee11
newArtifactId: jetty-ee11-webapp
newVersion: 12.1.x
# WireMock 4.x only puts these on the runtime classpath. `onlyIfUsing` is matched against the sources as they
# were before `ChangePackage` ran, hence the EE10 packages.
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.eclipse.jetty.ee11
artifactId: jetty-ee11-webapp
version: 12.1.x
onlyIfUsing: org.eclipse.jetty.ee10.webapp.*
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.eclipse.jetty.ee11
artifactId: jetty-ee11-servlets
version: 12.1.x
onlyIfUsing: org.eclipse.jetty.ee10.servlets.*
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.wiremock.Wiremock4RelocatedTypes
displayName: Move WireMock types to their 4.x packages
description: Change WireMock types that moved packages in WireMock 4.x, such as the Jetty, servlet and Apache HTTP client classes.
preconditions:
- org.openrewrite.java.search.HasType:
fullyQualifiedTypeName: com.github.tomakehurst.wiremock..*
tags:
- testing
- wiremock
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty11.CertificateGeneratingSslContextFactory
newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.jetty.ssl.CertificateGeneratingSslContextFactory
Expand Down Expand Up @@ -215,86 +311,3 @@ recipeList:
oldFullyQualifiedTypeName: com.github.tomakehurst.wiremock.http.MimeType
newFullyQualifiedTypeName: com.github.tomakehurst.wiremock.common.entity.MimeType
ignoreDefinition: true
- org.openrewrite.java.testing.wiremock.ReplaceRemovedConstructors
- org.openrewrite.java.testing.wiremock.ReplaceSettersWithTransform
- org.openrewrite.java.testing.wiremock.MigrateStubMappingUuidToId
- org.openrewrite.java.testing.wiremock.MigrateContentTypeHeaderCharset
- org.openrewrite.java.testing.wiremock.MigrateRequestMethodIsOneOf
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.github.tomakehurst.wiremock.stubbing.StubMapping getUuid()
newMethodName: getId
# `value()` widened its return type to `Object` in 4.x; `getName()` still answers a `String`
- org.openrewrite.java.ChangeMethodName:
methodPattern: com.github.tomakehurst.wiremock.http.RequestMethod value()
newMethodName: getName
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.wiremock.RemoveDuplicateContentTypeHeaders
displayName: Keep a single `Content-Type` response header while still on WireMock 3
description: >-
Collapse duplicate `Content-Type` response headers in both stub files and the Java DSL, but only where the
module still depends on WireMock 3.x. Jetty 11 already served a single value there, so dropping the rest
changes nothing; against 4.x the extra values really do reach the client, and removing them would.
tags:
- testing
- wiremock
preconditions:
- org.openrewrite.java.dependencies.search.ModuleHasDependency:
groupIdPattern: org.wiremock
artifactIdPattern: wiremock*
version: 3.x
recipeList:
- org.openrewrite.java.testing.wiremock.RemoveDuplicateContentTypeHeader
- org.openrewrite.java.testing.wiremock.RemoveDuplicateContentTypeStubHeader
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.wiremock.MigrateJettyEE10ToEE11
displayName: Move Jetty EE10 usages to EE11 alongside `wiremock-jetty12`
description: >-
WireMock 3's `wiremock-jetty12` module ran on Jetty's EE10 servlet environment, whereas WireMock 4.x runs on EE11,
so EE10 types such as the `ServletContextHandler` handed to `NotFoundHandler` no longer line up. Move EE10 packages
and dependencies over to their EE11 counterparts, but only in modules depending on `wiremock-jetty12`, where EE10
arrived through WireMock in the first place.
tags:
- testing
- wiremock
- jetty
preconditions:
- org.openrewrite.java.dependencies.search.ModuleHasDependency:
groupIdPattern: org.wiremock
artifactIdPattern: wiremock-jetty12
recipeList:
- org.openrewrite.java.ChangePackage:
oldPackageName: org.eclipse.jetty.ee10
newPackageName: org.eclipse.jetty.ee11
recursive: true
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.eclipse.jetty.ee10
oldArtifactId: jetty-ee10-servlet
newGroupId: org.eclipse.jetty.ee11
newArtifactId: jetty-ee11-servlet
newVersion: 12.1.x
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.eclipse.jetty.ee10
oldArtifactId: jetty-ee10-servlets
newGroupId: org.eclipse.jetty.ee11
newArtifactId: jetty-ee11-servlets
newVersion: 12.1.x
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.eclipse.jetty.ee10
oldArtifactId: jetty-ee10-webapp
newGroupId: org.eclipse.jetty.ee11
newArtifactId: jetty-ee11-webapp
newVersion: 12.1.x
# WireMock 4.x only puts these on the runtime classpath. `onlyIfUsing` is matched against the sources as they
# were before `ChangePackage` ran, hence the EE10 packages.
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.eclipse.jetty.ee11
artifactId: jetty-ee11-webapp
version: 12.1.x
onlyIfUsing: org.eclipse.jetty.ee10.webapp.*
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.eclipse.jetty.ee11
artifactId: jetty-ee11-servlets
version: 12.1.x
onlyIfUsing: org.eclipse.jetty.ee10.servlets.*
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,39 @@ fun myTest() {
);
}

@Test
void removeReturnTypeFromTestNGTestMethod() {
//language=kotlin
rewriteRun(
spec -> spec.parser(KotlinParser.builder()
.classpathFromResources(new InMemoryExecutionContext(),
"testng-7")),
kotlin(
"""
import org.testng.annotations.Test

class ATest {
@Test
fun myTest(): String {
println("test")
return "done"
}
}
""",
"""
import org.testng.annotations.Test

class ATest {
@Test
fun myTest() {
println("test")
}
}
"""
)
);
}

@Test
void removeReturnTypeAndPreserveReturnStatement() {
//language=kotlin
Expand Down
Loading