Skip to content

Commit

Permalink
Adopt TypeTable (#676)
Browse files Browse the repository at this point in the history
* Adopt TypeTable

* Unpin minor versions in jar references

* Refresh TypeTable and include testng as referenced

* Unpin JUnit 4 minor version

* Unpin JUnit 4 minor version in JMockitTestUtils

* Pin powermock to specific version to fix tests
  • Loading branch information
timtebeek authored Feb 16, 2025
1 parent a7fee68 commit d4f5d15
Show file tree
Hide file tree
Showing 163 changed files with 1,341 additions and 1,341 deletions.
32 changes: 17 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,29 @@ group = "org.openrewrite.recipe"
description = "A rewrite module automating best practices and major version migrations for popular Java test frameworks like JUnit and Mockito"

recipeDependencies {
parserClasspath("org.assertj:assertj-core:3.+")
parserClasspath("junit:junit:latest.release")
parserClasspath("pl.pragmatists:JUnitParams:1.+")
parserClasspath("org.junit.jupiter:junit-jupiter-api:latest.release")
parserClasspath("org.junit.jupiter:junit-jupiter-params:latest.release")
parserClasspath("org.hamcrest:hamcrest:latest.release")
parserClasspath("com.github.database-rider:rider-junit5:1.44.0")
parserClasspath("com.github.tomakehurst:wiremock-jre8:2.35.0")
parserClasspath("com.squareup.okhttp3:mockwebserver:3.14.9")
parserClasspath("com.squareup.okhttp3:mockwebserver:4.10.0")
parserClasspath("junit:junit:4.+")
parserClasspath("org.apiguardian:apiguardian-api:1.1.2")
parserClasspath("com.github.tomakehurst:wiremock-jre8:2.35.0")
parserClasspath("org.assertj:assertj-core:3.+")
parserClasspath("org.hamcrest:hamcrest:3.+")
parserClasspath("org.jmockit:jmockit:1.22") // last version with NonStrictExpectations
parserClasspath("org.jmockit:jmockit:1.49")
parserClasspath("org.junit.jupiter:junit-jupiter-api:5.+")
parserClasspath("org.junit.jupiter:junit-jupiter-params:5.+")
parserClasspath("org.mockito:mockito-all:1.10.19")
parserClasspath("org.mockito:mockito-core:3.+")
parserClasspath("org.mockito:mockito-core:5.+")
parserClasspath("org.mockito:mockito-junit-jupiter:5.+")
parserClasspath("org.jmockit:jmockit:1.49")
parserClasspath("org.jmockit:jmockit:1.22") // last version with NonStrictExpectations
parserClasspath("org.mockito:mockito-junit-jupiter:3.+")
parserClasspath("org.powermock:powermock-api-mockito:1.7.+")
parserClasspath("org.powermock:powermock-core:1.7.+")
parserClasspath("com.squareup.okhttp3:mockwebserver:4.10.0")
parserClasspath("org.springframework:spring-test:6.1.12")
parserClasspath("com.github.database-rider:rider-junit5:1.44.0")
parserClasspath("org.mockito:mockito-junit-jupiter:5.+")
parserClasspath("org.powermock:powermock-api-mockito:1.6.5")
parserClasspath("org.powermock:powermock-api-support:1.6.5")
parserClasspath("org.powermock:powermock-core:1.6.5")
parserClasspath("org.springframework:spring-test:6.1.+")
parserClasspath("org.testng:testng:7.+")
parserClasspath("pl.pragmatists:JUnitParams:1.+")
}

val rewriteVersion = rewriteRecipe.rewriteVersion.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private List<Object> getUnitInfo(String name, int argValue) {
private J.MethodInvocation applyTemplate(ExecutionContext ctx, J.MethodInvocation m, String template, Object... parameters) {
J.MethodInvocation invocation = JavaTemplate.builder(template)
.contextSensitive()
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), m.getCoordinates().replace(), parameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
if (args.size() == 2) {
return JavaTemplate.builder("assertThat(#{anyArray()}).containsExactly(#{anyArray()});")
.staticImports(ASSERTJ + ".assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), md.getCoordinates().replace(), actual, expected);
}
Expand All @@ -75,15 +75,15 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
// assert is using floating points with a delta and no message.
return JavaTemplate.builder("assertThat(#{anyArray()}).containsExactly(#{anyArray()}, within(#{any()}));")
.staticImports(ASSERTJ + ".assertThat", ASSERTJ + ".within")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), md.getCoordinates().replace(), actual, expected, args.get(2));
}
if (args.size() == 3) {
Expression message = args.get(2);
return JavaTemplate.builder("assertThat(#{anyArray()}).as(#{any()}).containsExactly(#{anyArray()});")
.staticImports(ASSERTJ + ".assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), md.getCoordinates().replace(), actual, message, expected);
}
Expand All @@ -94,7 +94,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
Expression message = args.get(3);
return JavaTemplate.builder("assertThat(#{anyArray()}).as(#{any()}).containsExactly(#{anyArray()}, within(#{}));")
.staticImports(ASSERTJ + ".assertThat", ASSERTJ + ".within")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), md.getCoordinates().replace(), actual, message, expected, args.get(2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
if (args.size() == 2) {
return JavaTemplate.builder("assertThat(#{any()}).isEqualTo(#{any()});")
.staticImports(ASSERTJ + ".assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, expected);
}
Expand All @@ -75,15 +75,15 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
return JavaTemplate.builder("assertThat(#{any()}).as(#{any()}).isEqualTo(#{any()});")
.staticImports(ASSERTJ + ".assertThat")
.imports("java.util.function.Supplier")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, message, expected);
}
if (args.size() == 3) {
maybeAddImport(ASSERTJ, "within", false);
return JavaTemplate.builder("assertThat(#{any()}).isCloseTo(#{any()}, within(#{any()}));")
.staticImports(ASSERTJ + ".assertThat", ASSERTJ + ".within")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, expected, args.get(2));
}
Expand All @@ -95,7 +95,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
return JavaTemplate.builder("assertThat(#{any()}).as(#{any()}).isCloseTo(#{any()}, within(#{any()}));")
.staticImports(ASSERTJ + ".assertThat", ASSERTJ + ".within")
.imports("java.util.function.Supplier")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, message, expected, args.get(2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
if (args.size() == 1) {
return JavaTemplate.builder("assertThat(#{any(boolean)}).isFalse();")
.staticImports("org.assertj.core.api.Assertions.assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual);
}

Expression message = args.get(1);
return JavaTemplate.builder("assertThat(#{any(boolean)}).as(#{any()}).isFalse();")
.staticImports("org.assertj.core.api.Assertions.assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
if (mi.getArguments().size() == 2) {
return JavaTemplate.builder("assertThat(#{any()}).isInstanceOf(#{any()});")
.staticImports("org.assertj.core.api.Assertions.assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), method.getCoordinates().replace(), actual, expected);
}

Expression messageOrSupplier = mi.getArguments().get(2);
return JavaTemplate.builder("assertThat(#{any()}).as(#{any()}).isInstanceOf(#{any()});")
.staticImports("org.assertj.core.api.Assertions.assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), method.getCoordinates().replace(), actual, messageOrSupplier, expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
if (args.size() == 2) {
return JavaTemplate.builder("assertThat(#{any()}).isNotEqualTo(#{any()});")
.staticImports(ASSERTJ + ".assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, expected);
}
if (args.size() == 3 && isFloatingPointType(args.get(2))) {
maybeAddImport(ASSERTJ, "within", false);
return JavaTemplate.builder("assertThat(#{any()}).isNotCloseTo(#{any()}, within(#{any()}));")
.staticImports(ASSERTJ + ".assertThat", ASSERTJ + ".within")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, expected, args.get(2));
}
if (args.size() == 3) {
Expression message = args.get(2);
return JavaTemplate.builder("assertThat(#{any()}).as(#{any()}).isNotEqualTo(#{any()});")
.staticImports(ASSERTJ + ".assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, message, expected);
}
Expand All @@ -92,7 +92,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
Expression message = args.get(3);
return JavaTemplate.builder("assertThat(#{any()}).as(#{any()}).isNotCloseTo(#{any()}, within(#{any()}));")
.staticImports(ASSERTJ + ".assertThat", ASSERTJ + ".within")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), method.getCoordinates().replace(), actual, message, expected, args.get(2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
if (args.size() == 1) {
return JavaTemplate.builder("assertThat(#{any()}).isNotNull();")
.staticImports("org.assertj.core.api.Assertions.assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual);

Expand All @@ -70,7 +70,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
Expression message = args.get(1);
return JavaTemplate.builder("assertThat(#{any()}).as(#{any()}).isNotNull();")
.staticImports("org.assertj.core.api.Assertions.assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
if (args.size() == 1) {
return JavaTemplate.builder("assertThat(#{any()}).isNull();")
.staticImports("org.assertj.core.api.Assertions.assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual);
}

Expression message = args.get(1);
return JavaTemplate.builder("assertThat(#{any()}).as(#{any()}).isNull();")
.staticImports("org.assertj.core.api.Assertions.assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
if (args.size() == 2) {
return JavaTemplate.builder("assertThat(#{any()}).isSameAs(#{any()});")
.staticImports("org.assertj.core.api.Assertions.assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, expected);
}

Expression message = args.get(2);
return JavaTemplate.builder("assertThat(#{any()}).as(#{any()}).isSameAs(#{any()});")
.staticImports("org.assertj.core.api.Assertions.assertThat")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.build()
.apply(getCursor(), mi.getCoordinates().replace(), actual, message, expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
if (executable != null) {
mi = JavaTemplate
.builder("assertThatExceptionOfType(#{any(java.lang.Class)}).isThrownBy(#{any(org.assertj.core.api.ThrowableAssert.ThrowingCallable)})")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3"))
.staticImports("org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType")
.build()
.apply(getCursor(), mi.getCoordinates().replace(), mi.getArguments().get(0), executable);
Expand Down
Loading

0 comments on commit d4f5d15

Please sign in to comment.