diff --git a/build.gradle.kts b/build.gradle.kts index 6447c9476..89a83ac1f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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() diff --git a/src/main/java/org/openrewrite/java/testing/assertj/AdoptAssertJDurationAssertions.java b/src/main/java/org/openrewrite/java/testing/assertj/AdoptAssertJDurationAssertions.java index 2ec09e704..b6bed6445 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/AdoptAssertJDurationAssertions.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/AdoptAssertJDurationAssertions.java @@ -201,7 +201,7 @@ private List 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); diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java index f06236fe6..e7462b686 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java @@ -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); } @@ -75,7 +75,7 @@ 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)); } @@ -83,7 +83,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu 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); } @@ -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)); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java index 4642b90cc..c9a823dd5 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java @@ -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); } @@ -75,7 +75,7 @@ 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); } @@ -83,7 +83,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu 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)); } @@ -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)); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThat.java index 001731805..7ba8cd73a 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThat.java @@ -61,7 +61,7 @@ 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); } @@ -69,7 +69,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu 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); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThat.java index 2fc554cf0..e04f85c45 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThat.java @@ -59,7 +59,7 @@ 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); } @@ -67,7 +67,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu 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); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java index 33697e1f1..2f41faf31 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java @@ -66,7 +66,7 @@ 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); } @@ -74,7 +74,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu 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)); } @@ -82,7 +82,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu 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); } @@ -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)); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThat.java index 60fd2a94a..26ddb81e9 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThat.java @@ -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); @@ -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); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThat.java index 828b88ec5..adc62e8bf 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThat.java @@ -61,7 +61,7 @@ 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); } @@ -69,7 +69,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu 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); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThat.java index 10c30597b..b839afdbd 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThat.java @@ -62,7 +62,7 @@ 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); } @@ -70,7 +70,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu 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); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertThrowsToAssertExceptionType.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertThrowsToAssertExceptionType.java index 31317f128..11d1fd63a 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertThrowsToAssertExceptionType.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertThrowsToAssertExceptionType.java @@ -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); diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThat.java index 22c25b25a..247aa2d43 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThat.java @@ -61,7 +61,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu if (args.size() == 1) { return JavaTemplate.builder("assertThat(#{any(boolean)}).isTrue();") .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); } @@ -69,7 +69,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu Expression message = args.get(1); return JavaTemplate.builder("assertThat(#{any()}).as(#{any(String)}).isTrue();") .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); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFail.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFail.java index a391bed81..a3662fd7c 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFail.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFail.java @@ -59,18 +59,18 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu // fail(), fail(String), fail(Supplier), fail(Throwable) if (args.get(0) instanceof J.Empty) { mi = JavaTemplate.builder(ASSERTJ + ".fail(\"\");") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) .build() .apply(getCursor(), mi.getCoordinates().replace()); } else if (args.get(0) instanceof J.Literal || TypeUtils.isAssignableTo("java.lang.String", args.get(0).getType())) { mi = JavaTemplate.builder(ASSERTJ + ".fail(#{any()});") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) .build() .apply(getCursor(), mi.getCoordinates().replace(), args.get(0)); } else { mi = JavaTemplate.builder(ASSERTJ + ".fail(\"\", #{any()});") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) .build() .apply(getCursor(), mi.getCoordinates().replace(), args.get(0)); } @@ -78,7 +78,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu // fail(String, Throwable) String anyArgs = String.join(",", Collections.nCopies(args.size(), "#{any()}")); mi = JavaTemplate.builder(ASSERTJ + ".fail(" + anyArgs + ");") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) .build() .apply(getCursor(), mi.getCoordinates().replace(), args.toArray()); } @@ -105,7 +105,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu String anyArgs = String.join(",", Collections.nCopies(arguments.size(), "#{any()}")); return JavaTemplate.builder("fail(" + anyArgs + ");") .staticImports(ASSERTJ + ".fail") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) .build() .apply(getCursor(), mi.getCoordinates().replace(), arguments.toArray()); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertion.java b/src/main/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertion.java index c41818855..574cf08e3 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertion.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertion.java @@ -93,7 +93,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu // Assume zero argument replacement method return JavaTemplate.builder("#{any()}." + dedicatedAssertion + "()") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) .build() .apply(getCursor(), mi.getCoordinates().replace(), mi.getSelect()); } diff --git a/src/main/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertion.java b/src/main/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertion.java index 591c3d2a6..9fc533223 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertion.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertion.java @@ -118,7 +118,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation methodInvocat String template = getStringTemplateAndAppendArguments(assertThatArg, mi, arguments); return JavaTemplate.builder(String.format(template, dedicatedAssertion)) .contextSensitive() - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5.9", "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5", "assertj-core-3")) .build() .apply(getCursor(), mi.getCoordinates().replace(), arguments.toArray()); } diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBoolean.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBoolean.java index eadbe09b5..d8e392e7c 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBoolean.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBoolean.java @@ -49,7 +49,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsNullToAssertNull.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsNullToAssertNull.java index 4db87dc6f..c8bdc8cdf 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsNullToAssertNull.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertEqualsNullToAssertNull.java @@ -51,7 +51,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseEqualsToAssertNotEquals.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseEqualsToAssertNotEquals.java index d5b56e394..1b1ada942 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseEqualsToAssertNotEquals.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseEqualsToAssertNotEquals.java @@ -49,7 +49,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseNegationToAssertTrue.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseNegationToAssertTrue.java index 2fa82d589..3a387acd9 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseNegationToAssertTrue.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseNegationToAssertTrue.java @@ -48,7 +48,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseNullToAssertNotNull.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseNullToAssertNotNull.java index 02bb7804a..bcae354d0 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseNullToAssertNotNull.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertFalseNullToAssertNotNull.java @@ -74,14 +74,14 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) .contextSensitive() .staticImports("org.junit.jupiter.api.Assertions.assertNotNull") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .classpathFromResources(ctx, "junit-jupiter-api-5")) .build(); } else { t = JavaTemplate.builder(sb.toString()) .contextSensitive() .imports("org.junit.jupiter.api.Assertions") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .classpathFromResources(ctx, "junit-jupiter-api-5")) .build(); } return t.apply(updateCursor(mi), mi.getCoordinates().replace(), args); diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertNotEqualsBooleanToAssertBoolean.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertNotEqualsBooleanToAssertBoolean.java index 29d2a22c0..f5425143b 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertNotEqualsBooleanToAssertBoolean.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertNotEqualsBooleanToAssertBoolean.java @@ -49,7 +49,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueComparisonToAssertEquals.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueComparisonToAssertEquals.java index 0a6450fcc..88f56cb62 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueComparisonToAssertEquals.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueComparisonToAssertEquals.java @@ -51,7 +51,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueEqualsToAssertEquals.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueEqualsToAssertEquals.java index 2f7e5dfb5..d05b0ebe5 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueEqualsToAssertEquals.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueEqualsToAssertEquals.java @@ -50,7 +50,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueNegationToAssertFalse.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueNegationToAssertFalse.java index dd023f1a1..97c3fcc56 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueNegationToAssertFalse.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueNegationToAssertFalse.java @@ -48,7 +48,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueNullToAssertNull.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueNullToAssertNull.java index 996491ede..a99fc3acf 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueNullToAssertNull.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertTrueNullToAssertNull.java @@ -74,14 +74,14 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) .contextSensitive() .staticImports("org.junit.jupiter.api.Assertions.assertNull") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .classpathFromResources(ctx, "junit-jupiter-api-5")) .build(); } else { t = JavaTemplate.builder(sb.toString()) .contextSensitive() .imports("org.junit.jupiter.api.Assertions") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .classpathFromResources(ctx, "junit-jupiter-api-5")) .build(); } return t.apply(updateCursor(mi), mi.getCoordinates().replace(), args); diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java b/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java index 59e3c2e13..818d86b59 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java @@ -127,7 +127,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex md = JavaTemplate.builder("assertDoesNotThrow(() -> #{any()});") .staticImports("org.junit.jupiter.api.Assertions.assertDoesNotThrow") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .classpathFromResources(ctx, "junit-jupiter-api-5")) .build() .apply(updateCursor(md), md.getCoordinates().replaceBody(), body); } diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToAssertJ.java b/src/main/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToAssertJ.java index 36c60b976..b3548e833 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToAssertJ.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToAssertJ.java @@ -50,7 +50,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); maybeRemoveImport("org.hamcrest.MatcherAssert.assertThat"); return JavaTemplate.builder("assertThat(#{any(boolean)}).as(#{any(String)}).isTrue()") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) .staticImports("org.assertj.core.api.Assertions.assertThat") .build() .apply(getCursor(), mi.getCoordinates().replace(), booleanArgument, reasonArgument); diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5.java b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5.java index 77226397a..47d69796c 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5.java @@ -88,7 +88,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation mi, Execution (reason == null ? ")" : ", #{any(java.lang.String)})"); JavaTemplate template = JavaTemplate.builder(templateString) - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5")) .staticImports("org.junit.jupiter.api.Assertions." + (logicalContext ? "assertInstanceOf" : "assertFalse")) .build(); diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJ.java b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJ.java index 2308df43c..e81cccfa8 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJ.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJ.java @@ -106,7 +106,7 @@ private J.MethodInvocation replace(J.MethodInvocation mi, ExecutionContext ctx) (reasonArgument != null ? ".as(#{any(String)})" : "") + ".%s(%s)", actual, assertion, getArgumentsTemplate(matcherArgumentMethod))) - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) .staticImports( "org.assertj.core.api.Assertions.assertThat", "org.assertj.core.api.Assertions.within") diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java index a97f1388d..2aa2dd698 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5.java @@ -169,7 +169,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu String assertion = logicalContext ? replacement.junitPositive : replacement.junitNegative; String templateString = assertion + "(" + replacement.template + (reason == null ? ")" : ", #{any(java.lang.String)})"); JavaTemplate template = JavaTemplate.builder(templateString) - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5")) .staticImports("org.junit.jupiter.api.Assertions." + assertion) .build(); diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJ.java b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJ.java index 336e714fd..b1f315aaf 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJ.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJ.java @@ -104,7 +104,7 @@ private J.MethodInvocation handleTwoArgumentCase(J.MethodInvocation mi, Expressi .collect(Collectors.joining(", ")); JavaTemplate template = JavaTemplate.builder(String.format("assertThat(%s).%s(%s)", actual, assertion, argumentsTemplate)) - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) .staticImports("org.assertj.core.api.Assertions.assertThat") .build(); maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); @@ -136,7 +136,7 @@ private J.MethodInvocation handleThreeArgumentCase(J.MethodInvocation mi, Expres .collect(Collectors.joining(", ")); JavaTemplate template = JavaTemplate.builder(String.format("assertThat(%s).as(#{any(String)}).%s(%s)", actual, assertion, argumentsTemplate)) - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3.24")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) .staticImports("org.assertj.core.api.Assertions.assertThat") .build(); maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestOfMatchersToAssertJ.java b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestOfMatchersToAssertJ.java index 2a4d324a4..a3001befd 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestOfMatchersToAssertJ.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestOfMatchersToAssertJ.java @@ -102,9 +102,9 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation methodInvocat .contextSensitive() .staticImports("org.assertj.core.api.Assertions.assertThat") .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, - "assertj-core-3.24", - "hamcrest-2.2", - "junit-jupiter-api-5.9")) + "assertj-core-3", + "hamcrest-3", + "junit-jupiter-api-5")) .build() .apply(getCursor(), mi.getCoordinates().replace(), parameters.toArray()); } diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherVisitor.java b/src/main/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherVisitor.java index 90c28170a..4c19544df 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherVisitor.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherVisitor.java @@ -57,7 +57,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation mi, Execution result = mi.getArguments().get(0).withPrefix(mi.getPrefix()); } else { JavaTemplate template = JavaTemplate.builder("equalTo(#{any(java.lang.Object)})") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "hamcrest-2.2")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "hamcrest-3")) .staticImports("org.hamcrest.Matchers.equalTo") .build(); maybeAddImport("org.hamcrest.Matchers", "equalTo"); diff --git a/src/main/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockito.java b/src/main/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockito.java index 43098f83a..d03315edb 100644 --- a/src/main/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockito.java +++ b/src/main/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockito.java @@ -144,7 +144,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration md, Execut J.ClassDeclaration cd = maybeAddMethodWithAnnotation(this, cdRef.get(), ctx, true, "tearDown", "@org.junit.After", "@After", - "junit-4.13", + "junit-4", "org.junit.After", ""); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java b/src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java index 81eae7593..1fded9564 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java @@ -90,7 +90,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex if (!isAnnotationType && !alreadyNested && hasTestMethods(cd)) { cd = JavaTemplate.builder("@Nested") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .classpathFromResources(ctx, "junit-jupiter-api-5")) .imports(NESTED) .build() .apply(getCursor(), cd.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName))); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/AddMissingTestBeforeAfterAnnotations.java b/src/main/java/org/openrewrite/java/testing/junit5/AddMissingTestBeforeAfterAnnotations.java index 1c68313bf..0d3a9a6d6 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/AddMissingTestBeforeAfterAnnotations.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/AddMissingTestBeforeAfterAnnotations.java @@ -83,7 +83,7 @@ private J.MethodDeclaration maybeAddMissingAnnotation(J.MethodDeclaration method if (la.needsAnnotation(method, superMethod)) { maybeAddImport(la.newAnnotation); return JavaTemplate.builder(la.newAnnotationSimple) - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5")) .imports(la.newAnnotation) .build() .apply(getCursor(), method.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName))); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/AddParameterizedTestAnnotation.java b/src/main/java/org/openrewrite/java/testing/junit5/AddParameterizedTestAnnotation.java index 3e293cbbd..682e7daf4 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/AddParameterizedTestAnnotation.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/AddParameterizedTestAnnotation.java @@ -74,7 +74,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration md, Execut // Add parameterized test annotation at the start JavaCoordinates coordinates = m.getCoordinates().addAnnotation((o1, o2) -> -1); m = JavaTemplate.builder("@ParameterizedTest") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-params-5.9")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-params-5")) .imports("org.junit.jupiter.params.ParameterizedTest") .build() .apply(getCursor(), coordinates); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/AssertTrueInstanceofToAssertInstanceOf.java b/src/main/java/org/openrewrite/java/testing/junit5/AssertTrueInstanceofToAssertInstanceOf.java index 89523b3e9..b4cc7eeb9 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/AssertTrueInstanceofToAssertInstanceOf.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/AssertTrueInstanceofToAssertInstanceOf.java @@ -95,7 +95,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu JavaTemplate template = JavaTemplate .builder("assertInstanceOf(#{}.class, #{any(java.lang.Object)}" + (reason != null ? ", #{any(java.lang.String)})" : ")")) - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5.9", "junit-4.13")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5", "junit-4")) .staticImports("org.junit.jupiter.api.Assertions.assertInstanceOf") .build(); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java index dbc2323e3..7043d0ab0 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java @@ -67,7 +67,7 @@ public static class ExpectedExceptionToAssertThrowsVisitor extends JavaIsoVisito private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9", "hamcrest-2.2"); + .classpathFromResources(ctx, "junit-jupiter-api-5", "hamcrest-3"); } return javaParser; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java b/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java index ef09edfe0..aafdfc384 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java @@ -181,7 +181,7 @@ private static class ParametersNoArgsImplicitMethodSource extends JavaIsoVisitor private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9", "hamcrest-2.2", "junit-jupiter-params-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5", "hamcrest-3", "junit-jupiter-params-5"); } return javaParser; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java b/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java index 1df0ad8d1..9c63c9da8 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java @@ -138,7 +138,7 @@ private J.MethodDeclaration updateMethodDeclarationAnnotationAndModifier(J.Metho if (FindAnnotations.find(methodDeclaration.withBody(null), "@" + fullyQualifiedAnnotation).isEmpty()) { md = JavaTemplate.builder(annotation) .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .classpathFromResources(ctx, "junit-jupiter-api-5")) .imports(fullyQualifiedAnnotation).build() .apply(getCursor(), methodDeclaration.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName))); md = maybeAddPublicModifier(md); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/MockitoJUnitToMockitoExtension.java b/src/main/java/org/openrewrite/java/testing/junit5/MockitoJUnitToMockitoExtension.java index a89436fde..74424702c 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/MockitoJUnitToMockitoExtension.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/MockitoJUnitToMockitoExtension.java @@ -105,7 +105,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex cd = JavaTemplate.builder("@ExtendWith(MockitoExtension.class)") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9", "mockito-junit-jupiter-3.12")) + .classpathFromResources(ctx, "junit-jupiter-api-5", "mockito-junit-jupiter-3.12")) .imports("org.junit.jupiter.api.extension.ExtendWith", "org.mockito.junit.jupiter.MockitoExtension") .build() .apply(updateCursor(cd), cd.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName))); @@ -121,7 +121,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex if (!strictness.contains("STRICT_STUBS")) { cd = JavaTemplate.builder("@MockitoSettings(strictness = " + strictness + ")") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9", "mockito-junit-jupiter-3.12")) + .classpathFromResources(ctx, "junit-jupiter-api-5", "mockito-junit-jupiter-3.12")) .imports("org.mockito.junit.jupiter.MockitoSettings", "org.mockito.quality.Strictness") .build() .apply(updateCursor(cd), cd.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName))); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java b/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java index fe0663ea7..40f3e991a 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java @@ -183,7 +183,7 @@ public ParameterizedRunnerToParameterizedTestsVisitor(J.ClassDeclaration scope, "@ParameterizedTest"; JavaParser.Builder javaParserBuilder = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9", "junit-jupiter-params-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5", "junit-jupiter-params-5"); this.parameterizedTestTemplate = JavaTemplate.builder(parameterizedTestAnnotationTemplate) .javaParser(javaParserBuilder) diff --git a/src/main/java/org/openrewrite/java/testing/junit5/RemoveTryCatchFailBlocks.java b/src/main/java/org/openrewrite/java/testing/junit5/RemoveTryCatchFailBlocks.java index b0b05fc36..59edcf832 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/RemoveTryCatchFailBlocks.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/RemoveTryCatchFailBlocks.java @@ -132,7 +132,7 @@ private J.MethodInvocation replaceWithAssertDoesNotThrowWithoutStringExpression( return JavaTemplate.builder("Assertions.assertDoesNotThrow(() -> #{any()})") .contextSensitive() .imports("org.junit.jupiter.api.Assertions") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5")) .build() .apply(getCursor(), try_.getCoordinates().replace(), try_.getBody()); } @@ -156,7 +156,7 @@ private J.MethodInvocation replaceWithAssertDoesNotThrowWithStringExpression(Exe return JavaTemplate.builder("Assertions.assertDoesNotThrow(() -> #{any()}, #{any(String)})") .contextSensitive() .imports("org.junit.jupiter.api.Assertions") - .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5.9")) + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "junit-jupiter-api-5")) .build() .apply(getCursor(), try_.getCoordinates().replace(), try_.getBody(), failCallArgument); } diff --git a/src/main/java/org/openrewrite/java/testing/junit5/RunnerToExtension.java b/src/main/java/org/openrewrite/java/testing/junit5/RunnerToExtension.java index b6e5cda48..030cd6c0b 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/RunnerToExtension.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/RunnerToExtension.java @@ -77,7 +77,7 @@ private JavaTemplate getExtendsWithTemplate(ExecutionContext ctx) { if (extendsWithTemplate == null) { extendsWithTemplate = JavaTemplate.builder("@ExtendWith(#{}.class)") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9") + .classpathFromResources(ctx, "junit-jupiter-api-5") .dependsOn("package " + extensionType.getPackageName() + ";\n" + "import org.junit.jupiter.api.extension.Extension;\n" + "public class " + extensionType.getClassName() + " implements Extension {}")) diff --git a/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java b/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java index 7c2eff177..a9da2a05b 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java @@ -55,7 +55,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; @@ -163,7 +163,7 @@ private static class AddNewFolderMethod extends JavaIsoVisitor private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; @@ -242,7 +242,7 @@ private static class TranslateNewFolderMethodInvocation extends JavaVisitor javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java b/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java index 42b10a8f4..ba2afe2d2 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java @@ -59,7 +59,7 @@ private static class TestRuleToTestInfoVisitor extends JavaIsoVisitor javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } @@ -166,7 +166,7 @@ private static class BeforeMethodToTestInfoVisitor extends JavaIsoVisitor javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java b/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java index 0b688d0cb..d90065e5e 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java @@ -75,7 +75,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-4.13", "junit-jupiter-api-5.9", "apiguardian-api-1.1", + .classpathFromResources(ctx, "junit-4", "junit-jupiter-api-5", "apiguardian-api-1.1", "mockwebserver-3.14"); } return javaParser; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java index 3e7be4aad..440d10473 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java @@ -60,7 +60,7 @@ private static class UpdateTestAnnotationVisitor extends JavaIsoVisitor javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9", "apiguardian-api-1.1"); + .classpathFromResources(ctx, "junit-jupiter-api-5", "apiguardian-api-1.1"); } return javaParser; } @@ -190,7 +190,7 @@ private static class ChangeTestAnnotation extends JavaIsoVisitor javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9", "apiguardian-api-1.1"); + .classpathFromResources(ctx, "junit-jupiter-api-5", "apiguardian-api-1.1"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java b/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java index 6995c053d..44bd74aa3 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java @@ -51,7 +51,7 @@ public TreeVisitor getVisitor() { private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { javaParser = JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "junit-jupiter-api-5.9"); + .classpathFromResources(ctx, "junit-jupiter-api-5"); } return javaParser; } diff --git a/src/main/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockito.java b/src/main/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockito.java index ad7fcb32d..e3d3fcd8a 100644 --- a/src/main/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockito.java +++ b/src/main/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockito.java @@ -362,12 +362,12 @@ private void initTestFrameworkInfo(boolean useTestNg) { setUpMethodAnnotationName = "BeforeEach"; tearDownMethodAnnotationName = "AfterEach"; annotationPackage = "org.junit.jupiter.api"; - additionalClasspathResource = "junit-jupiter-api-5.9"; + additionalClasspathResource = "junit-jupiter-api-5"; } else { setUpMethodAnnotationName = "BeforeMethod"; tearDownMethodAnnotationName = "AfterMethod"; annotationPackage = "org.testng.annotations"; - additionalClasspathResource = "testng-7.7"; + additionalClasspathResource = "testng-7"; tearDownMethodAnnotationParameters = "(alwaysRun = true)"; } diff --git a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsToAssertThat.java index feaf9594c..4bb25e339 100644 --- a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsToAssertThat.java @@ -68,7 +68,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu return JavaTemplate.builder("assertThat(#{any()}).isEqualTo(#{any()});") .staticImports("org.assertj.core.api.Assertions.assertThat") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "assertj-core-3.24")) + .classpathFromResources(ctx, "assertj-core-3")) .build() .apply(getCursor(), method.getCoordinates().replace(), actual, expected); } else if (args.size() == 3 && !isFloatingPointType(args.get(2))) { @@ -77,7 +77,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu .staticImports("org.assertj.core.api.Assertions.assertThat") .imports("java.util.function.Supplier") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "assertj-core-3.24")) + .classpathFromResources(ctx, "assertj-core-3")) .build() .apply( getCursor(), @@ -92,7 +92,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu return JavaTemplate.builder("assertThat(#{any()}).isCloseTo(#{any()}, within(#{any()}));") .staticImports("org.assertj.core.api.Assertions.assertThat", "org.assertj.core.api.Assertions.within") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "assertj-core-3.24")) + .classpathFromResources(ctx, "assertj-core-3")) .build() .apply(getCursor(), method.getCoordinates().replace(), actual, expected, args.get(2)); @@ -107,7 +107,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu .staticImports("org.assertj.core.api.Assertions.assertThat", "org.assertj.core.api.Assertions.within") .imports("java.util.function.Supplier") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "assertj-core-3.24")) + .classpathFromResources(ctx, "assertj-core-3")) .build() .apply( getCursor(), diff --git a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotEqualsToAssertThat.java index 56b2856b5..983c80631 100644 --- a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotEqualsToAssertThat.java @@ -63,7 +63,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu method = JavaTemplate.builder("assertThat(#{any()}).isNotEqualTo(#{any()});") .staticImports("org.assertj.core.api.Assertions.assertThat") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "assertj-core-3.24")) + .classpathFromResources(ctx, "assertj-core-3")) .build() .apply( getCursor(), @@ -76,7 +76,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu method = JavaTemplate.builder("assertThat(#{any()}).as(#{any(String)}).isNotEqualTo(#{any()});") .staticImports("org.assertj.core.api.Assertions.assertThat") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "assertj-core-3.24")) + .classpathFromResources(ctx, "assertj-core-3")) .build() .apply( getCursor(), @@ -89,7 +89,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu method = JavaTemplate.builder("assertThat(#{any()}).isNotCloseTo(#{any()}, within(#{any()}));") .staticImports("org.assertj.core.api.Assertions.assertThat", "org.assertj.core.api.Assertions.within") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "assertj-core-3.24")) + .classpathFromResources(ctx, "assertj-core-3")) .build() .apply( getCursor(), @@ -104,7 +104,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu method = JavaTemplate.builder("assertThat(#{any()}).as(#{any(String)}).isNotCloseTo(#{any()}, within(#{any()}));") .staticImports("org.assertj.core.api.Assertions.assertThat", "org.assertj.core.api.Assertions.within") .javaParser(JavaParser.fromJavaVersion() - .classpathFromResources(ctx, "assertj-core-3.24")) + .classpathFromResources(ctx, "assertj-core-3")) .build() .apply( getCursor(), diff --git a/src/main/resources/META-INF/rewrite/classpath.tsv.zip b/src/main/resources/META-INF/rewrite/classpath.tsv.zip new file mode 100644 index 000000000..e6f6e46a2 Binary files /dev/null and b/src/main/resources/META-INF/rewrite/classpath.tsv.zip differ diff --git a/src/main/resources/META-INF/rewrite/classpath/JUnitParams-1.1.1.jar b/src/main/resources/META-INF/rewrite/classpath/JUnitParams-1.1.1.jar deleted file mode 100644 index 04d574a42..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/JUnitParams-1.1.1.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/apiguardian-api-1.1.2.jar b/src/main/resources/META-INF/rewrite/classpath/apiguardian-api-1.1.2.jar deleted file mode 100644 index 2b678e154..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/apiguardian-api-1.1.2.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/assertj-core-3.24.2.jar b/src/main/resources/META-INF/rewrite/classpath/assertj-core-3.24.2.jar deleted file mode 100644 index ac377b8cc..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/assertj-core-3.24.2.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/hamcrest-2.2.jar b/src/main/resources/META-INF/rewrite/classpath/hamcrest-2.2.jar deleted file mode 100644 index 71065788d..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/hamcrest-2.2.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/jmockit-1.22.jar b/src/main/resources/META-INF/rewrite/classpath/jmockit-1.22.jar deleted file mode 100644 index 9b3cc6718..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/jmockit-1.22.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/jmockit-1.49.jar b/src/main/resources/META-INF/rewrite/classpath/jmockit-1.49.jar deleted file mode 100644 index 3306c225f..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/jmockit-1.49.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/junit-4.13.2.jar b/src/main/resources/META-INF/rewrite/classpath/junit-4.13.2.jar deleted file mode 100644 index 6da55d8b8..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/junit-4.13.2.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/junit-jupiter-api-5.9.2.jar b/src/main/resources/META-INF/rewrite/classpath/junit-jupiter-api-5.9.2.jar deleted file mode 100644 index ceba67e66..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/junit-jupiter-api-5.9.2.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/junit-jupiter-params-5.9.2.jar b/src/main/resources/META-INF/rewrite/classpath/junit-jupiter-params-5.9.2.jar deleted file mode 100644 index ddc5df201..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/junit-jupiter-params-5.9.2.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/junit-platform-suite-api-1.9.2.jar b/src/main/resources/META-INF/rewrite/classpath/junit-platform-suite-api-1.9.2.jar deleted file mode 100644 index b5f6d0171..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/junit-platform-suite-api-1.9.2.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/mockito-all-1.10.19.jar b/src/main/resources/META-INF/rewrite/classpath/mockito-all-1.10.19.jar deleted file mode 100644 index c831489cd..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/mockito-all-1.10.19.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/mockito-core-3.12.4.jar b/src/main/resources/META-INF/rewrite/classpath/mockito-core-3.12.4.jar deleted file mode 100644 index 0b328fa36..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/mockito-core-3.12.4.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/mockito-core-5.14.2.jar b/src/main/resources/META-INF/rewrite/classpath/mockito-core-5.14.2.jar deleted file mode 100644 index f40502548..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/mockito-core-5.14.2.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/mockito-junit-jupiter-3.12.4.jar b/src/main/resources/META-INF/rewrite/classpath/mockito-junit-jupiter-3.12.4.jar deleted file mode 100644 index 640dcc86e..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/mockito-junit-jupiter-3.12.4.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/mockwebserver-3.14.9.jar b/src/main/resources/META-INF/rewrite/classpath/mockwebserver-3.14.9.jar deleted file mode 100644 index 9da8d9c88..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/mockwebserver-3.14.9.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/mockwebserver-4.10.0.jar b/src/main/resources/META-INF/rewrite/classpath/mockwebserver-4.10.0.jar deleted file mode 100644 index d29e3cea8..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/mockwebserver-4.10.0.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/powermock-api-mockito-1.6.5.jar b/src/main/resources/META-INF/rewrite/classpath/powermock-api-mockito-1.6.5.jar deleted file mode 100644 index 322267f31..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/powermock-api-mockito-1.6.5.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/powermock-api-support-1.6.5.jar b/src/main/resources/META-INF/rewrite/classpath/powermock-api-support-1.6.5.jar deleted file mode 100644 index b0eefeec4..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/powermock-api-support-1.6.5.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/powermock-core-1.6.5.jar b/src/main/resources/META-INF/rewrite/classpath/powermock-core-1.6.5.jar deleted file mode 100644 index a189056d8..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/powermock-core-1.6.5.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/rider-junit5-1.44.0.jar b/src/main/resources/META-INF/rewrite/classpath/rider-junit5-1.44.0.jar deleted file mode 100644 index 8c4bbfc62..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/rider-junit5-1.44.0.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/testng-7.7.1.jar b/src/main/resources/META-INF/rewrite/classpath/testng-7.7.1.jar deleted file mode 100644 index 4ceb8648e..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/testng-7.7.1.jar and /dev/null differ diff --git a/src/main/resources/META-INF/rewrite/classpath/wiremock-jre8-2.35.0.jar b/src/main/resources/META-INF/rewrite/classpath/wiremock-jre8-2.35.0.jar deleted file mode 100644 index fca59032b..000000000 Binary files a/src/main/resources/META-INF/rewrite/classpath/wiremock-jre8-2.35.0.jar and /dev/null differ diff --git a/src/test/java/org/openrewrite/java/testing/assertj/AdoptAssertJDurationAssertionsTest.java b/src/test/java/org/openrewrite/java/testing/assertj/AdoptAssertJDurationAssertionsTest.java index 7e6dd8fed..85030d706 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/AdoptAssertJDurationAssertionsTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/AdoptAssertJDurationAssertionsTest.java @@ -33,7 +33,7 @@ public void defaults(RecipeSpec spec) { .recipe(new AdoptAssertJDurationAssertions()) .parser(JavaParser.fromJavaVersion() .logCompilationWarningsAndErrors(true) - .classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")); + .classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3")); } @Test @@ -45,9 +45,9 @@ void getSecondsToHasSeconds() { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB).getSeconds()).isEqualTo(1); @@ -57,9 +57,9 @@ void testMethod(Temporal timestampA, Temporal timestampB) { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB)).hasSeconds(1); @@ -78,9 +78,9 @@ void getNanoToHasNanos() { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB).getNano()).isEqualTo(1); @@ -90,9 +90,9 @@ void testMethod(Temporal timestampA, Temporal timestampB) { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB)).hasNanos(1); @@ -111,9 +111,9 @@ void isEqualToZeroToIsZero() { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB).getNano()).isEqualTo(0); @@ -123,9 +123,9 @@ void testMethod(Temporal timestampA, Temporal timestampB) { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB).getNano()).isZero(); @@ -144,9 +144,9 @@ void isEqualToVariable() { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { int zero = 0; @@ -157,9 +157,9 @@ void testMethod(Temporal timestampA, Temporal timestampB) { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { int zero = 0; @@ -179,9 +179,9 @@ void isGreaterThanZeroToIsPositive() { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB).getSeconds()).isGreaterThan(0); @@ -191,9 +191,9 @@ void testMethod(Temporal timestampA, Temporal timestampB) { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB).getSeconds()).isPositive(); @@ -212,9 +212,9 @@ void isLessThanZeroToIsNegative() { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB).getSeconds()).isLessThan(0); @@ -224,9 +224,9 @@ void testMethod(Temporal timestampA, Temporal timestampB) { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB).getSeconds()).isNegative(); @@ -253,9 +253,9 @@ void simplifyDurationAssertions(String before, String after) { //language=java String template = """ import java.time.Duration; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Duration time) { assertThat(time).%s; @@ -272,9 +272,9 @@ void doNotSimplifyNonLiteralMultiplication() { java( """ import java.time.Duration; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Duration time, int variable) { assertThat(time).hasHours(19 + 5); @@ -298,9 +298,9 @@ void shouldRetainAsDescription() { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB).getSeconds()).as("description").isEqualTo(1); @@ -310,9 +310,9 @@ void testMethod(Temporal timestampA, Temporal timestampB) { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB)).as("description").hasSeconds(1); @@ -331,9 +331,9 @@ void shouldRetainWhiteSpace() { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB).getSeconds()) @@ -344,9 +344,9 @@ void testMethod(Temporal timestampA, Temporal timestampB) { """ import java.time.Duration; import java.time.temporal.Temporal; - + import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod(Temporal timestampA, Temporal timestampB) { assertThat(Duration.between(timestampA, timestampB)) @@ -365,7 +365,7 @@ void shouldNotMatchUnrelatedToDurations() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class Foo { void testMethod() { assertThat(bar()).isEqualTo(0); diff --git a/src/test/java/org/openrewrite/java/testing/assertj/AssertJBestPracticesTest.java b/src/test/java/org/openrewrite/java/testing/assertj/AssertJBestPracticesTest.java index 8d229935a..2544ff040 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/AssertJBestPracticesTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/AssertJBestPracticesTest.java @@ -38,7 +38,7 @@ class AssertJBestPracticesTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec.parser( JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) + .classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3")) .recipeFromResources("org.openrewrite.java.testing.assertj.Assertj"); } diff --git a/src/test/java/org/openrewrite/java/testing/assertj/CollapseConsecutiveAssertThatStatementsTest.java b/src/test/java/org/openrewrite/java/testing/assertj/CollapseConsecutiveAssertThatStatementsTest.java index d740f2fb8..3d30f0362 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/CollapseConsecutiveAssertThatStatementsTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/CollapseConsecutiveAssertThatStatementsTest.java @@ -32,7 +32,7 @@ class CollapseConsecutiveAssertThatStatementsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) + .classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3")) .recipe(new CollapseConsecutiveAssertThatStatements()); } diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThatTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThatTest.java index efeadbc76..420f9a589 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThatTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThatTest.java @@ -32,7 +32,7 @@ class JUnitAssertArrayEqualsToAssertThatTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new JUnitAssertArrayEqualsToAssertThat()); } @@ -250,9 +250,9 @@ void floatCloseToWithNoMessage() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertArrayEquals; - + public class MyTest { @Test public void test() { @@ -265,10 +265,10 @@ private float[] notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; - + public class MyTest { @Test public void test() { diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThatTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThatTest.java index 74204c97a..8cd6523e5 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThatTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThatTest.java @@ -33,7 +33,7 @@ class JUnitAssertEqualsToAssertThatTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new JUnitAssertEqualsToAssertThat()); } @@ -245,9 +245,9 @@ void floatCloseToWithNoMessage() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertEquals; - + public class MyTest { @Test public void test() { @@ -260,10 +260,10 @@ private Float notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; - + public class MyTest { @Test public void test() { @@ -286,9 +286,9 @@ void floatCloseToWithMessage() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertEquals; - + public class MyTest { @Test public void test() { @@ -301,10 +301,10 @@ private float notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; - + public class MyTest { @Test public void test() { @@ -328,7 +328,7 @@ void fullyQualifiedMethodWithMessage() { """ import org.junit.jupiter.api.Test; import java.io.File; - + public class MyTest { @Test public void test() { @@ -342,9 +342,9 @@ private File notification() { """ import org.junit.jupiter.api.Test; import java.io.File; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { @Test public void test() { @@ -370,13 +370,13 @@ void shouldImportWhenCustomClassIsUsed() { """ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; - + class ATest { @Test void testEquals() { Assertions.assertEquals(new OwnClass(), new OwnClass()); } - + public record OwnClass(String a) { public OwnClass() {this("1");} } @@ -384,15 +384,15 @@ public record OwnClass(String a) { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void testEquals() { assertThat(new OwnClass()).isEqualTo(new OwnClass()); } - + public record OwnClass(String a) { public OwnClass() {this("1");} } diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThatTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThatTest.java index f82733259..3dcd68437 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThatTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThatTest.java @@ -32,7 +32,7 @@ class JUnitAssertFalseToAssertThatTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new JUnitAssertFalseToAssertThat()); } diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThatTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThatTest.java index 1e4e1d357..095264899 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThatTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThatTest.java @@ -30,7 +30,7 @@ class JUnitAssertInstanceOfToAssertThatTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new JUnitAssertInstanceOfToAssertThat()); } diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThatTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThatTest.java index 18a96509a..7068acb70 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThatTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThatTest.java @@ -32,7 +32,7 @@ class JUnitAssertNotEqualsToAssertThatTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new JUnitAssertNotEqualsToAssertThat()); } @@ -245,9 +245,9 @@ void floatCloseToWithNoMessage() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertNotEquals; - + public class MyTest { @Test public void test() { @@ -260,10 +260,10 @@ private Float notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; - + public class MyTest { @Test public void test() { diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThatTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThatTest.java index 95c5f5204..00c9bf0a4 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThatTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThatTest.java @@ -33,7 +33,7 @@ class JUnitAssertNotNullToAssertThatTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new JUnitAssertNotNullToAssertThat()); } @@ -179,9 +179,9 @@ private String notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { @Test public void test() { @@ -206,10 +206,10 @@ void mixedReferences() { java( """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertNotNull; - + public class MyTest { @Test public void test() { @@ -224,9 +224,9 @@ private String notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.*; - + public class MyTest { @Test public void test() { @@ -252,7 +252,7 @@ void importAddedForCustomArguments() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertNotNull; class TTest { @@ -267,7 +267,7 @@ public void testClass() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; class TTest { diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThatTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThatTest.java index 9d7d0d0b6..c2ba8f3ae 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThatTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThatTest.java @@ -32,7 +32,7 @@ class JUnitAssertNullToAssertThatTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new JUnitAssertNullToAssertThat()); } @@ -84,9 +84,9 @@ void singleStaticMethodWithMessageString() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertNull; - + public class MyTest { @Test public void test() { @@ -99,9 +99,9 @@ private String notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { @Test public void test() { @@ -178,9 +178,9 @@ private String notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { @Test public void test() { @@ -205,10 +205,10 @@ void mixedReferences() { java( """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertNull; - + public class MyTest { @Test public void test() { @@ -223,9 +223,9 @@ private String notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.*; - + public class MyTest { @Test public void test() { diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThatTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThatTest.java index 65aac0fa0..9873e3b01 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThatTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThatTest.java @@ -32,7 +32,7 @@ class JUnitAssertSameToAssertThatTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new JUnitAssertSameToAssertThat()); } @@ -44,7 +44,7 @@ void singleStaticMethodNoMessage() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertSame; public class MyTest { @@ -185,9 +185,9 @@ private String notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { @Test public void test() { @@ -213,10 +213,10 @@ void mixedReferences() { java( """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertSame; - + public class MyTest { @Test public void test() { @@ -232,9 +232,9 @@ private String notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.*; - + public class MyTest { @Test public void test() { diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertThrowsToAssertExceptionTypeTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertThrowsToAssertExceptionTypeTest.java index e67680792..e1b0b0025 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertThrowsToAssertExceptionTypeTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertThrowsToAssertExceptionTypeTest.java @@ -31,7 +31,7 @@ class JUnitAssertThrowsToAssertExceptionTypeTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "hamcrest-3")) .recipe(new JUnitAssertThrowsToAssertExceptionType()); } diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThatTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThatTest.java index 2ef186c9a..b1afe2aad 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThatTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThatTest.java @@ -32,7 +32,7 @@ class JUnitAssertTrueToAssertThatTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new JUnitAssertTrueToAssertThat()); } @@ -45,9 +45,9 @@ void singleStaticMethodNoMessage() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertTrue; - + public class MyTest { @Test public void test() { @@ -60,9 +60,9 @@ private Integer notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { @Test public void test() { @@ -85,9 +85,9 @@ void singleStaticMethodWithMessageString() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.*; - + public class MyTest { @Test public void test() { @@ -100,9 +100,9 @@ private Integer notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { @Test public void test() { @@ -125,9 +125,9 @@ void singleStaticMethodWithMessageSupplier() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.*; - + public class MyTest { @Test public void test() { @@ -140,9 +140,9 @@ private Integer notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { @Test public void test() { @@ -180,9 +180,9 @@ private Integer notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { @Test public void test() { @@ -207,10 +207,10 @@ void mixedReferences() { java( """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertTrue; - + public class MyTest { @Test public void test() { @@ -225,9 +225,9 @@ private Integer notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.*; - + public class MyTest { @Test public void test() { @@ -252,9 +252,9 @@ void leaveBooleanSuppliersAlone() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertTrue; - + public class MyTest { @Test public void test() { @@ -273,10 +273,10 @@ private Integer notification() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; - + public class MyTest { @Test public void test() { diff --git a/src/test/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFailTest.java b/src/test/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFailTest.java index a9f609b3c..af7cc51a2 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFailTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFailTest.java @@ -32,7 +32,7 @@ class JUnitFailToAssertJFailTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new JUnitFailToAssertJFail()); } @@ -197,7 +197,7 @@ public void test() { import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.fail; - + public class MyTest { @Test public void test() { @@ -219,9 +219,9 @@ void mixedReferences() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.fail; - + public class MyTest { @Test public void test() { @@ -236,7 +236,7 @@ public void test() { import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.fail; - + public class MyTest { @Test public void test() { @@ -260,7 +260,7 @@ void stringVariableArgument() { """ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; - + public class OpenrewriteTest { @Test public void smokeTest() { @@ -271,9 +271,9 @@ public void smokeTest() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.fail; - + public class OpenrewriteTest { @Test public void smokeTest() { diff --git a/src/test/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertionTest.java b/src/test/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertionTest.java index ce848b23d..177c419f9 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertionTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertionTest.java @@ -27,7 +27,7 @@ class SimplifyAssertJAssertionTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")); + spec.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3")); } @Test diff --git a/src/test/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertionTest.java b/src/test/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertionTest.java index b21233b35..6e34451cd 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertionTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertionTest.java @@ -30,7 +30,7 @@ class SimplifyChainedAssertJAssertionTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")); + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3")); } @DocumentExample @@ -42,7 +42,7 @@ void stringIsEmpty() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat("hello world".isEmpty()).isTrue(); @@ -51,7 +51,7 @@ void testMethod() { """, """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat("hello world").isEmpty(); @@ -71,7 +71,7 @@ void stringIsEmptyDescribedAs() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod(String actual) { assertThat(actual.isEmpty()).as("Reason").isTrue(); @@ -80,7 +80,7 @@ void testMethod(String actual) { """, """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod(String actual) { assertThat(actual).as("Reason").isEmpty(); @@ -102,12 +102,12 @@ void chainedRecipes() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat(getString().isEmpty()).isTrue(); } - + String getString() { return "hello world"; } @@ -115,12 +115,12 @@ String getString() { """, """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat(getString()).isEmpty(); } - + String getString() { return "hello world"; } @@ -141,14 +141,14 @@ void chainedRecipesOfDifferingTypes() { java( """ import java.nio.file.Path; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void string(String actual) { assertThat(actual.startsWith("prefix")).isTrue(); } - + void path(Path actual) { assertThat(actual.startsWith("prefix")).isTrue(); } @@ -156,14 +156,14 @@ void path(Path actual) { """, """ import java.nio.file.Path; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void string(String actual) { assertThat(actual).startsWith("prefix"); } - + void path(Path actual) { assertThat(actual).startsWithRaw(Path.of("prefix")); } @@ -181,13 +181,13 @@ void assertThatArgHasArgument() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { String expected = "hello world"; assertThat(getString().equalsIgnoreCase(expected)).isTrue(); } - + String getString() { return "hello world"; } @@ -195,13 +195,13 @@ String getString() { """, """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { String expected = "hello world"; assertThat(getString()).isEqualToIgnoringCase(expected); } - + String getString() { return "hello world"; } @@ -219,13 +219,13 @@ void replacementHasArgument() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { int length = 5; assertThat(getString().length()).isEqualTo(length); } - + String getString() { return "hello world"; } @@ -233,13 +233,13 @@ String getString() { """, """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { int length = 5; assertThat(getString()).hasSize(length); } - + String getString() { return "hello world"; } @@ -258,12 +258,12 @@ void normalCase() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat(getString().trim()).isEmpty(); } - + String getString() { return "hello world"; } @@ -271,12 +271,12 @@ String getString() { """, """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat(getString()).isBlank(); } - + String getString() { return "hello world"; } @@ -297,7 +297,7 @@ void stringContains() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat("hello world".contains("lo wo")).isTrue(); @@ -307,7 +307,7 @@ void testMethod() { """, """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat("hello world").contains("lo wo"); @@ -328,13 +328,13 @@ void stringContainsObjectMethod() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class Pojo { public String getString() { return "lo wo"; } } - + class MyTest { void testMethod() { var pojo = new Pojo(); @@ -344,13 +344,13 @@ void testMethod() { """, """ import static org.assertj.core.api.Assertions.assertThat; - + class Pojo { public String getString() { return "lo wo"; } } - + class MyTest { void testMethod() { var pojo = new Pojo(); @@ -371,16 +371,16 @@ void mapMethodDealsWithTwoArguments() { """ import java.util.Collections; import java.util.Map; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { String key = "key"; String value = "value"; assertThat(getMap().get(key)).isEqualTo(value); } - + Map getMap() { return Collections.emptyMap(); } @@ -389,16 +389,16 @@ Map getMap() { """ import java.util.Collections; import java.util.Map; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { String key = "key"; String value = "value"; assertThat(getMap()).containsEntry(key, value); } - + Map getMap() { return Collections.emptyMap(); } @@ -416,9 +416,9 @@ void keySetContainsWithMultipleArguments() { java( """ import java.util.Map; - + import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod(Map map) { // we don't yet support `containsKeys` @@ -438,12 +438,12 @@ void isNotEmptyTest() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat(getString().isEmpty()).isFalse(); } - + String getString() { return "hello world"; } @@ -451,12 +451,12 @@ String getString() { """, """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat(getString()).isNotEmpty(); } - + String getString() { return "hello world"; } @@ -474,12 +474,12 @@ void doesNoRunOnWrongCombination() { java( """ import static org.assertj.core.api.Assertions.assertThat; - + class MyTest { void testMethod() { assertThat(getString().isBlank()).isFalse(); } - + String getString() { return "hello world"; } @@ -506,7 +506,7 @@ void simplifyPresenceAssertion() { """ import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; - + class Test { void simpleTest(Optional o) { assertThat(o.isPresent()).isTrue(); @@ -519,7 +519,7 @@ void simpleTest(Optional o) { """ import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; - + class Test { void simpleTest(Optional o) { assertThat(o).isPresent(); @@ -545,7 +545,7 @@ void simplifiyEqualityAssertion() { """ import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; - + class Test { void simpleTest(Optional o) { assertThat(o.get()).isEqualTo("foo"); @@ -556,7 +556,7 @@ void simpleTest(Optional o) { """ import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; - + class Test { void simpleTest(Optional o) { assertThat(o).contains("foo"); diff --git a/src/test/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertionsTest.java b/src/test/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertionsTest.java index 4405c6152..6a2549c9d 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertionsTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertionsTest.java @@ -39,7 +39,7 @@ class SimplifyChainedAssertJAssertionsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) + .classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3")) .recipe(Environment.builder() .scanRuntimeClasspath("org.openrewrite.java.testing.assertj") .build() diff --git a/src/test/java/org/openrewrite/java/testing/assertj/StaticImportsTest.java b/src/test/java/org/openrewrite/java/testing/assertj/StaticImportsTest.java index c68a7a657..77769f484 100644 --- a/src/test/java/org/openrewrite/java/testing/assertj/StaticImportsTest.java +++ b/src/test/java/org/openrewrite/java/testing/assertj/StaticImportsTest.java @@ -32,7 +32,7 @@ class StaticImportsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3.24")) + .classpathFromResources(new InMemoryExecutionContext(), "assertj-core-3")) .recipe(Environment.builder() .scanRuntimeClasspath("org.openrewrite.java.testing.junit5") .build() @@ -66,7 +66,7 @@ void method() { """, """ import java.util.List; - + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBooleanTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBooleanTest.java index f478944f7..faeb6e156 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBooleanTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsBooleanToAssertBooleanTest.java @@ -30,7 +30,7 @@ class AssertEqualsBooleanToAssertBooleanTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertEqualsBooleanToAssertBoolean()); } @@ -43,7 +43,7 @@ void assertEqualsFalseToToAssertFalse() { java( """ import static org.junit.jupiter.api.Assertions.assertEquals; - + public class Test { void test() { String a = "a"; @@ -57,7 +57,7 @@ void test() { """, """ import static org.junit.jupiter.api.Assertions.assertFalse; - + public class Test { void test() { String a = "a"; @@ -82,7 +82,7 @@ void preserveStyleOfStaticImportOrNot() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; @@ -93,7 +93,7 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsNullToAssertNullTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsNullToAssertNullTest.java index 5869406bd..5cbf7b0fd 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsNullToAssertNullTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertEqualsNullToAssertNullTest.java @@ -29,7 +29,7 @@ class AssertEqualsNullToAssertNullTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertEqualsNullToAssertNull()); } @@ -42,7 +42,7 @@ void simplifyToAssertNull() { java( """ import static org.junit.jupiter.api.Assertions.assertEquals; - + public class Test { void test() { String s = null; @@ -55,7 +55,7 @@ void test() { """, """ import static org.junit.jupiter.api.Assertions.assertNull; - + public class Test { void test() { String s = null; @@ -79,7 +79,7 @@ void preserveStyleOfStaticImportOrNot() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String s = null; @@ -92,7 +92,7 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String s = null; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseEqualToAssertNotEqualsTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseEqualToAssertNotEqualsTest.java index b5e5ba284..ce658c043 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseEqualToAssertNotEqualsTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseEqualToAssertNotEqualsTest.java @@ -29,7 +29,7 @@ class AssertFalseEqualToAssertNotEqualsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertFalseEqualsToAssertNotEquals()); } @@ -42,7 +42,7 @@ void assertFalseToAssertNotEquals() { java( """ import static org.junit.jupiter.api.Assertions.assertFalse; - + public class Test { void test() { String a = "a"; @@ -54,7 +54,7 @@ void test() { """, """ import static org.junit.jupiter.api.Assertions.assertNotEquals; - + public class Test { void test() { String a = "a"; @@ -77,7 +77,7 @@ void preserveStyleOfStaticImportOrNot() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; @@ -88,7 +88,7 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; @@ -110,7 +110,7 @@ void retainEqualsAndedWithSomethingElse() { """ import java.util.Arrays; import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseNegationToAssertTrueTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseNegationToAssertTrueTest.java index b146756dd..d9db7f84b 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseNegationToAssertTrueTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseNegationToAssertTrueTest.java @@ -29,7 +29,7 @@ class AssertFalseNegationToAssertTrueTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertFalseNegationToAssertTrue()); } @@ -42,7 +42,7 @@ void assertTrueNegationToAssertFalse() { java( """ import static org.junit.jupiter.api.Assertions.assertFalse; - + public class Test { void test() { boolean a = true; @@ -53,7 +53,7 @@ void test() { """, """ import static org.junit.jupiter.api.Assertions.assertTrue; - + public class Test { void test() { boolean a = true; @@ -75,7 +75,7 @@ void preserveStyleOfStaticImportOrNot() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { boolean a = true; @@ -86,7 +86,7 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { boolean a = true; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseNullToAssertNotNullTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseNullToAssertNotNullTest.java index 2261ed5d6..dfa9b44ac 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseNullToAssertNotNullTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertFalseNullToAssertNotNullTest.java @@ -29,7 +29,7 @@ class AssertFalseNullToAssertNotNullTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertFalseNullToAssertNotNull()); } @@ -42,13 +42,13 @@ void simplifyToAssertNull() { java( """ import static org.junit.jupiter.api.Assertions.assertFalse; - + public class Test { void test() { String a = null; assertFalse(a == null); assertFalse(a == null, "message"); - + String b = null; assertFalse(null == b); assertFalse(null == b, "message"); @@ -57,13 +57,13 @@ void test() { """, """ import static org.junit.jupiter.api.Assertions.assertNotNull; - + public class Test { void test() { String a = null; assertNotNull(a); assertNotNull(a, "message"); - + String b = null; assertNotNull(b); assertNotNull(b, "message"); @@ -83,13 +83,13 @@ void preserveStyleOfStaticImportOrNot() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = null; Assertions.assertFalse(a == null); Assertions.assertFalse(a == null, "message"); - + String b = null; Assertions.assertFalse(null == b); Assertions.assertFalse(null == b, "message"); @@ -98,13 +98,13 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = null; Assertions.assertNotNull(a); Assertions.assertNotNull(a, "message"); - + String b = null; Assertions.assertNotNull(b); Assertions.assertNotNull(b, "message"); @@ -122,7 +122,7 @@ void comparableComparedToZero() { java( """ import static org.junit.jupiter.api.Assertions.assertFalse; - + public class Test { void test() { Integer a = 0; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertLiteralBooleanToFailTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertLiteralBooleanToFailTest.java index cffc27609..b4d6af232 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertLiteralBooleanToFailTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertLiteralBooleanToFailTest.java @@ -29,7 +29,7 @@ class AssertLiteralBooleanToFailTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertLiteralBooleanToFailRecipe()); } diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertNotEqualsBooleanToAssertBooleanTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertNotEqualsBooleanToAssertBooleanTest.java index 577123536..6df61a11c 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertNotEqualsBooleanToAssertBooleanTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertNotEqualsBooleanToAssertBooleanTest.java @@ -30,7 +30,7 @@ class AssertNotEqualsBooleanToAssertBooleanTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertNotEqualsBooleanToAssertBoolean()); } @@ -43,7 +43,7 @@ void assertNotEqualsFalseToToAssertTrue() { java( """ import static org.junit.jupiter.api.Assertions.assertNotEquals; - + public class Test { void test() { String a = "a"; @@ -57,7 +57,7 @@ void test() { """, """ import static org.junit.jupiter.api.Assertions.assertTrue; - + public class Test { void test() { String a = "a"; @@ -82,7 +82,7 @@ void preserveStyleOfStaticImportOrNot() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; @@ -93,7 +93,7 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueComparisonToAssertEqualsTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueComparisonToAssertEqualsTest.java index 9ae55c714..22ed061f1 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueComparisonToAssertEqualsTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueComparisonToAssertEqualsTest.java @@ -30,7 +30,7 @@ class AssertTrueComparisonToAssertEqualsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertTrueComparisonToAssertEquals()); } @@ -43,7 +43,7 @@ void assertTrueComparisonToAssertEqualsTest() { java( """ import static org.junit.jupiter.api.Assertions.assertTrue; - + public class Test { void test() { int a = 1; @@ -54,7 +54,7 @@ void test() { """, """ import static org.junit.jupiter.api.Assertions.assertEquals; - + public class Test { void test() { int a = 1; @@ -76,7 +76,7 @@ void preserveStyleOfStaticImportOrNot() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { int a = 1; @@ -87,7 +87,7 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { int a = 1; @@ -109,7 +109,7 @@ void preserveMessage() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { int a = 1; @@ -120,7 +120,7 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { int a = 1; @@ -142,7 +142,7 @@ void doNotChangeToEqualsWhenCheckingOnObjectIdentityWithStrings() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; @@ -164,7 +164,7 @@ void doNotChangeToEqualsWhenCheckingOnObjectIdentityWithObjects() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { Object a = new Object(); diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueEqualsToAssertEqualsTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueEqualsToAssertEqualsTest.java index 05cc7b554..9098ba156 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueEqualsToAssertEqualsTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueEqualsToAssertEqualsTest.java @@ -29,7 +29,7 @@ class AssertTrueEqualsToAssertEqualsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertTrueEqualsToAssertEquals()); } @@ -42,7 +42,7 @@ void assertTrueToAssertEquals() { java( """ import static org.junit.jupiter.api.Assertions.assertTrue; - + public class Test { void test() { String a = "a"; @@ -54,7 +54,7 @@ void test() { """, """ import static org.junit.jupiter.api.Assertions.assertEquals; - + public class Test { void test() { String a = "a"; @@ -77,7 +77,7 @@ void preserveStyleOfStaticImportOrNot() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; @@ -89,7 +89,7 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; @@ -113,7 +113,7 @@ void retainArraysEquals() { """ import java.util.Arrays; import org.junit.jupiter.api.Assertions; - + public class Test { void test() { int[] a = {1, 2, 3}; @@ -135,7 +135,7 @@ void retainEqualsAndedWithSomethingElse() { """ import java.util.Arrays; import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = "a"; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueNegationToAssertFalseTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueNegationToAssertFalseTest.java index 8c699f317..6a8f97bd3 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueNegationToAssertFalseTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueNegationToAssertFalseTest.java @@ -29,7 +29,7 @@ class AssertTrueNegationToAssertFalseTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertTrueNegationToAssertFalse()); } @@ -42,7 +42,7 @@ void assertTrueNegationToAssertFalse() { java( """ import static org.junit.jupiter.api.Assertions.assertTrue; - + public class Test { void test() { boolean a = false; @@ -53,7 +53,7 @@ void test() { """, """ import static org.junit.jupiter.api.Assertions.assertFalse; - + public class Test { void test() { boolean a = false; @@ -75,7 +75,7 @@ void preserveStyleOfStaticImportOrNot() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { boolean a = false; @@ -86,7 +86,7 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { boolean a = false; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueNullToAssertNullTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueNullToAssertNullTest.java index 303c5b55d..a429ec363 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueNullToAssertNullTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertTrueNullToAssertNullTest.java @@ -29,7 +29,7 @@ class AssertTrueNullToAssertNullTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertTrueNullToAssertNull()); } @@ -42,13 +42,13 @@ void simplifyToAssertNull() { java( """ import static org.junit.jupiter.api.Assertions.assertTrue; - + public class Test { void test() { String a = null; assertTrue(a == null); assertTrue(a == null, "message"); - + String b = null; assertTrue(null == b); assertTrue(null == b, "message"); @@ -57,13 +57,13 @@ void test() { """, """ import static org.junit.jupiter.api.Assertions.assertNull; - + public class Test { void test() { String a = null; assertNull(a); assertNull(a, "message"); - + String b = null; assertNull(b); assertNull(b, "message"); @@ -83,13 +83,13 @@ void preserveStyleOfStaticImportOrNot() { java( """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = null; Assertions.assertTrue(a == null); Assertions.assertTrue(a == null, "message"); - + String b = null; Assertions.assertTrue(null == b); Assertions.assertTrue(null == b, "message"); @@ -98,13 +98,13 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + public class Test { void test() { String a = null; Assertions.assertNull(a); Assertions.assertNull(a, "message"); - + String b = null; Assertions.assertNull(b); Assertions.assertNull(b, "message"); @@ -122,7 +122,7 @@ void comparableComparedToZero() { java( """ import static org.junit.jupiter.api.Assertions.assertTrue; - + public class Test { void test() { Integer a = 0; diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/AssertionsArgumentOrderTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/AssertionsArgumentOrderTest.java index f75a8f6ff..536a931ab 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/AssertionsArgumentOrderTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/AssertionsArgumentOrderTest.java @@ -30,7 +30,7 @@ class AssertionsArgumentOrderTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec.recipe(new AssertionsArgumentOrder()) .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "testng-7.7", "junit-4.13")); + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "testng-7", "junit-4")); } @DocumentExample diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/RemoveEmptyTestsTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/RemoveEmptyTestsTest.java index e7d52f92e..864575a03 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/RemoveEmptyTestsTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/RemoveEmptyTestsTest.java @@ -29,8 +29,7 @@ class RemoveEmptyTestsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipe(new RemoveEmptyTests()); } diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefixTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefixTest.java index 5ffdc36dd..ebf3a7ee7 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefixTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefixTest.java @@ -31,7 +31,7 @@ class RemoveTestPrefixTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), - "junit-jupiter-api-5.9", "junit-jupiter-params-5.9")) + "junit-jupiter-api-5", "junit-jupiter-params-5")) .recipe(new RemoveTestPrefix()); } diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/SimplifyTestThrowsTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/SimplifyTestThrowsTest.java index 7409237c4..bb506b3ca 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/SimplifyTestThrowsTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/SimplifyTestThrowsTest.java @@ -29,7 +29,7 @@ class SimplifyTestThrowsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), - "junit-jupiter-api-5.9", "junit-jupiter-params-5.9")) + "junit-jupiter-api-5", "junit-jupiter-params-5")) .recipe(new SimplifyTestThrows()); } @@ -87,7 +87,7 @@ void noThrowsDeclaration() { java( """ import org.junit.jupiter.api.Test; - + class ATest { @Test void noThrows() { @@ -105,7 +105,7 @@ void usesGeneralExceptionAlready() { java( """ import org.junit.jupiter.api.Test; - + class ATest { @Test void throwsEx() throws Exception { diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertionsTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertionsTest.java index 996ebb801..4639cbe85 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertionsTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertionsTest.java @@ -34,7 +34,7 @@ class TestsShouldIncludeAssertionsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "junit-jupiter-api-5.9", "mockito-all-1.10", "hamcrest-2.2", "assertj-core-3.24", "spring-test-6.1.12") + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "junit-jupiter-api-5", "mockito-all-1.10", "hamcrest-3", "assertj-core-3", "spring-test-6.1") .dependsOn( List.of( //language=java @@ -70,9 +70,9 @@ public void methodTest() { """, """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - + public class AaTest { @Test public void methodTest() { @@ -94,11 +94,11 @@ void hasAssertDoesNotThrowAssertion() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - + public class AaTest { - + @Test public void methodTest() { assertDoesNotThrow(() -> { @@ -119,11 +119,11 @@ void assertJAssertion() { java( """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + public class MyTest { - + @Test public void test() { assertThat(notification()).isEqualTo(1); @@ -144,10 +144,10 @@ void hamcrestAssertion() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; - + public class ATest { @Test public void methodTest() { @@ -189,16 +189,16 @@ void methodBodyContainsMethodInvocationWithAssert() { """ import java.util.Set; import org.junit.jupiter.api.Test; - + import static org.junit.Assert.assertTrue; - + public class TestClass { @Test public void methodTest() { Set s = Set.of("hello"); testContains(s, "hello"); } - + private static void testContains(Set set, String word) { assertTrue(set.contains(word)); } @@ -218,9 +218,9 @@ void usesAdditionalAssertion() { java( """ package org.foo; - + import java.util.Set; - + public class TestUtil { public static void testContains(Set set, String word) { } @@ -233,7 +233,7 @@ public static void testContains(Set set, String word) { import java.util.Set; import org.foo.TestUtil; import org.junit.jupiter.api.Test; - + public class TestClass { @Test public void doesNotChange() { @@ -249,10 +249,10 @@ public void changes() { """ import java.util.Set; import org.foo.TestUtil; - + import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import org.junit.jupiter.api.Test; - + public class TestClass { @Test public void doesNotChange() { @@ -283,11 +283,11 @@ void hasMockitoVerify() { import static org.mockito.Mockito.when; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; - + class AaTest { @Mock MyMathService myMathService; - + @Test public void verifyTest() { when(myMathService.addIntegers("1", "2")).thenReturn(3); @@ -309,16 +309,16 @@ void hasMockitoVerifyNoInteractions() { import org.junit.jupiter.api.Test; import org.mockito.Mock; import static org.mockito.Mockito.*; - + class AaTest { @Mock org.learning.math.MyMathService myMathService; - + @Test public void noMore() { verifyNoMoreInteractions(myMathService); } - + @Test public void zero() { verifyZeroInteractions(myMathService); @@ -340,11 +340,11 @@ void hasMockitoDoesNotValidate() { import org.learning.math.MyMathService; import static org.mockito.Mockito.when; import org.learning.math.Stuff; - + class AaTest { @Mock MyMathService myMathService; - + @Test public void methodTest() { when(myMathService.addIntegers("1", "2")).thenReturn(3); @@ -356,15 +356,15 @@ public void methodTest() { import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.learning.math.MyMathService; - + import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.Mockito.when; import org.learning.math.Stuff; - + class AaTest { @Mock MyMathService myMathService; - + @Test public void methodTest() { assertDoesNotThrow(() -> { @@ -386,10 +386,10 @@ void hasMockRestServiceServerVerify() { """ import org.junit.jupiter.api.Test; import org.springframework.test.web.client.MockRestServiceServer; - + class AaTest { private MockRestServiceServer mockServer; - + @Test public void verifyTest() { mockServer.verify(); diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublicTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublicTest.java index d67145f84..445993975 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublicTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublicTest.java @@ -31,7 +31,7 @@ class TestsShouldNotBePublicTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "junit-jupiter-params-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "junit-jupiter-params-5")) .recipe(new TestsShouldNotBePublic(false)); } diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToAssertJTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToAssertJTest.java index 58e91f094..d8baeec7a 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToAssertJTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/AssertThatBooleanToAssertJTest.java @@ -31,9 +31,9 @@ public void defaults(RecipeSpec spec) { .recipe(new AssertThatBooleanToAssertJ()) .parser(JavaParser.fromJavaVersion() .classpathFromResources(new InMemoryExecutionContext(), - "junit-jupiter-api-5.9", - "hamcrest-2.2", - "assertj-core-3.24")); + "junit-jupiter-api-5", + "hamcrest-3", + "assertj-core-3")); } @Test @@ -44,9 +44,9 @@ void assertThatBoolean() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; - + class ATest { @Test void test() { @@ -56,9 +56,9 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java index 5cb3db550..226fccfb7 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestInstanceOfToJUnit5Test.java @@ -30,7 +30,7 @@ class HamcrestInstanceOfToJUnit5Test implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "hamcrest-3")) .recipe(new HamcrestInstanceOfToJUnit5()) .typeValidationOptions(all().immutableExecutionContext(false)); } diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestIsMatcherToAssertJTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestIsMatcherToAssertJTest.java index 9e965737b..6d21eef1e 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestIsMatcherToAssertJTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestIsMatcherToAssertJTest.java @@ -29,9 +29,9 @@ class HamcrestIsMatcherToAssertJTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec.parser(JavaParser.fromJavaVersion() .classpathFromResources(new InMemoryExecutionContext(), - "junit-jupiter-api-5.9", - "hamcrest-2.2", - "assertj-core-3.24")) + "junit-jupiter-api-5", + "hamcrest-3", + "assertj-core-3")) .recipe(new HamcrestIsMatcherToAssertJ()); } @@ -45,7 +45,7 @@ void isMatcher() { import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; - + class ATest { @Test void testEquals() { @@ -57,9 +57,9 @@ void testEquals() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void testEquals() { @@ -82,7 +82,7 @@ void isMatcherWithReason() { import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; - + class ATest { @Test void testEquals() { @@ -95,9 +95,9 @@ void testEquals() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void testEquals() { @@ -123,7 +123,7 @@ void isMatcherWithMatcher() { import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void test() { @@ -146,7 +146,7 @@ void isObjectArray() { import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; - + class ATest { @Test void testEquals() { @@ -158,9 +158,9 @@ void testEquals() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void testEquals() { @@ -183,7 +183,7 @@ void isPrimitiveArray() { import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; - + class ATest { @Test void testEquals() { @@ -195,9 +195,9 @@ void testEquals() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void testEquals() { diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJTest.java index b81533bfe..573dd04e7 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJTest.java @@ -31,9 +31,9 @@ public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() .classpathFromResources(new InMemoryExecutionContext(), - "junit-jupiter-api-5.9", - "hamcrest-2.2", - "assertj-core-3.24")); + "junit-jupiter-api-5", + "hamcrest-3", + "assertj-core-3")); } @Nested @@ -49,7 +49,7 @@ void notMatcher() { import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.containsString; - + class ATest { @Test void test() { @@ -72,7 +72,7 @@ void isMatcher() { import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void test() { @@ -95,7 +95,7 @@ void anyOfVarargsMatcher() { import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void test() { @@ -119,7 +119,7 @@ void anyOfIterableMatcher() { import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void test() { @@ -142,10 +142,10 @@ void isEmpty() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.isEmptyString; - + class ATest { @Test void test() { @@ -156,9 +156,9 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -178,10 +178,10 @@ void coreMatchers() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.CoreMatchers.startsWith; - + class ATest { @Test void test() { @@ -192,9 +192,9 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -219,10 +219,10 @@ void equalToString() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void test() { @@ -234,9 +234,9 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -257,10 +257,10 @@ void equalToStringLiteral() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void test() { @@ -271,9 +271,9 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -303,10 +303,10 @@ class Biscuit { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void test() { @@ -318,9 +318,9 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -341,10 +341,10 @@ void lessThanNumber() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.lessThan; - + class ATest { @Test void test() { @@ -356,9 +356,9 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -380,12 +380,12 @@ void containsInAnyOrderWithArray() { java( """ import org.junit.jupiter.api.Test; - + import java.util.ArrayList; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; - + class ATest { @Test void test() { @@ -397,12 +397,12 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import java.util.ArrayList; import java.util.List; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -423,10 +423,10 @@ void closeToTest() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.closeTo; - + class ATest { @Test void replaceCloseTo() { @@ -436,10 +436,10 @@ void replaceCloseTo() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; - + class ATest { @Test void replaceCloseTo() { @@ -459,10 +459,10 @@ void closeToWorksWithBigDecimal() { """ import org.junit.jupiter.api.Test; import java.math.BigDecimal; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.closeTo; - + class ATest { @Test void replaceCloseTo() { @@ -476,10 +476,10 @@ void replaceCloseTo() { """ import org.junit.jupiter.api.Test; import java.math.BigDecimal; - + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; - + class ATest { @Test void replaceCloseTo() { @@ -504,10 +504,10 @@ void reasonAsLiteral() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void test() { @@ -519,9 +519,9 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -542,10 +542,10 @@ void reasonAsMethodCall() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void test() { @@ -553,7 +553,7 @@ void test() { String str2 = "Hello world!"; assertThat(reason(), str1, equalTo(str2)); } - + String reason() { return "Should match"; } @@ -561,9 +561,9 @@ String reason() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -571,7 +571,7 @@ void test() { String str2 = "Hello world!"; assertThat(str1).as(reason()).isEqualTo(str2); } - + String reason() { return "Should match"; } diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5Test.java b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5Test.java index e9c053289..a269811a4 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5Test.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToJUnit5Test.java @@ -30,7 +30,7 @@ class HamcrestMatcherToJUnit5Test implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "hamcrest-3")) .recipe(new HamcrestMatcherToJUnit5()); } diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJTest.java index b778eaba5..779f6b2b9 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJTest.java @@ -30,9 +30,9 @@ public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() .classpathFromResources(new InMemoryExecutionContext(), - "junit-jupiter-api-5.9", - "hamcrest-2.2", - "assertj-core-3.24")); + "junit-jupiter-api-5", + "hamcrest-3", + "assertj-core-3")); } @DocumentExample @@ -44,11 +44,11 @@ void notMatcher() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void test() { @@ -60,9 +60,9 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -84,11 +84,11 @@ void notMatcherWithReason() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; - + class ATest { @Test void test() { @@ -99,9 +99,9 @@ void test() { """, """ import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { @@ -122,13 +122,13 @@ void notMatcherWithCollection() { java( """ import java.util.List; - + import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.hasItem; - + class ATest { @Test void test() { @@ -140,11 +140,11 @@ void test() { """, """ import java.util.List; - + import org.junit.jupiter.api.Test; - + import static org.assertj.core.api.Assertions.assertThat; - + class ATest { @Test void test() { diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestOfMatchersToAssertJTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestOfMatchersToAssertJTest.java index a24bf9a17..56b2bb0ca 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestOfMatchersToAssertJTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/HamcrestOfMatchersToAssertJTest.java @@ -29,9 +29,9 @@ class HamcrestOfMatchersToAssertJTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), - "junit-jupiter-api-5.9", - "hamcrest-2.2", - "assertj-core-3.24")) + "junit-jupiter-api-5", + "hamcrest-3", + "assertj-core-3")) .recipe(new HamcrestOfMatchersToAssertJ()); } @@ -43,12 +43,12 @@ void allOfMigrate() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasLength; - + class MyTest { @Test void testMethod() { @@ -86,12 +86,12 @@ void allOfMigrateHasReason() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasLength; - + class MyTest { @Test void testMethod() { @@ -155,12 +155,12 @@ void anyOfMigrate() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasLength; - + class MyTest { @Test void testMethod() { @@ -198,12 +198,12 @@ void anyOfHasALotOfArguments() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasLength; - + class MyTest { @Test void testMethod() { @@ -269,12 +269,12 @@ void assertThatHasReasonArgument() { java( """ import org.junit.jupiter.api.Test; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasLength; - + class MyTest { @Test void testMethod() { @@ -289,7 +289,7 @@ void testMethod() { import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasLength; - + class MyTest { @Test void testMethod() { diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToAssertJTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToAssertJTest.java index 9057350f3..bac2ad68b 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToAssertJTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToAssertJTest.java @@ -47,9 +47,9 @@ public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() .classpathFromResources(new InMemoryExecutionContext(), - "junit-jupiter-api-5.9", - "hamcrest-2.2", - "assertj-core-3.24")) + "junit-jupiter-api-5", + "hamcrest-3", + "assertj-core-3")) .recipe(Environment.builder() .scanRuntimeClasspath("org.openrewrite.java.testing.hamcrest") .build() diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToJUnitTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToJUnitTest.java index c6f153049..f5bbf8f09 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToJUnitTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToJUnitTest.java @@ -30,7 +30,7 @@ class MigrateHamcrestToJUnitTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "hamcrest-3")) .recipeFromResource("/META-INF/rewrite/hamcrest.yml", "org.openrewrite.java.testing.hamcrest.MigrateHamcrestToJUnit5"); } diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveIsMatcherTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveIsMatcherTest.java index d664a56bf..4d9066380 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveIsMatcherTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveIsMatcherTest.java @@ -29,7 +29,7 @@ class RemoveIsMatcherTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "hamcrest-3")) .recipe(new RemoveIsMatcher()); } @@ -44,7 +44,7 @@ void isMatcher() { import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void testEquals() { @@ -57,7 +57,7 @@ void testEquals() { import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void testEquals() { @@ -78,7 +78,7 @@ void isNotCalledInAssertThat() { import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void testMethod() { @@ -100,7 +100,7 @@ void isNotDirectlyInAssertThat() { import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; - + class ATest { @Test void testMethod() { @@ -115,7 +115,7 @@ void testMethod() { import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.equalTo; - + class ATest { @Test void testMethod() { @@ -139,7 +139,7 @@ void noReplacementForOtherMethodInvocations() { import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; - + class ATest { @Test void testMethod() { @@ -147,7 +147,7 @@ void testMethod() { String str2 = "Hello world!"; foo(is(equalTo(str2))); } - + void foo(Matcher matcher) { } } diff --git a/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java b/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java index 738894394..52a69839a 100644 --- a/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java +++ b/src/test/java/org/openrewrite/java/testing/hamcrest/RemoveNotMatcherTest.java @@ -31,7 +31,7 @@ class RemoveNotMatcherTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "hamcrest-3")) .recipe(toRecipe(RemoveNotMatcherVisitor::new)) .typeValidationOptions(all().immutableExecutionContext(false)); } diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitTestUtils.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitTestUtils.java index 154160c4f..a8bb4c3b7 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitTestUtils.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitTestUtils.java @@ -23,8 +23,8 @@ public class JMockitTestUtils { static final String MOCKITO_CORE_DEPENDENCY = "mockito-core-3.12"; - static final String JUNIT_5_JUPITER_DEPENDENCY = "junit-jupiter-api-5.9"; - static final String JUNIT_4_DEPENDENCY = "junit-4.13.2"; + static final String JUNIT_5_JUPITER_DEPENDENCY = "junit-jupiter-api-5"; + static final String JUNIT_4_DEPENDENCY = "junit-4"; static final String JMOCKIT_DEPENDENCY = "jmockit-1.49"; static final String MOCKITO_JUPITER_DEPENDENCY = "mockito-junit-jupiter-3.12"; diff --git a/src/test/java/org/openrewrite/java/testing/junit5/AddMissingNestedTest.java b/src/test/java/org/openrewrite/java/testing/junit5/AddMissingNestedTest.java index b173ff594..a6c852963 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/AddMissingNestedTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/AddMissingNestedTest.java @@ -32,7 +32,7 @@ public void defaults(RecipeSpec spec) { spec.recipe(new AddMissingNested()) .parser(JavaParser.fromJavaVersion() .logCompilationWarningsAndErrors(true) - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")); + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")); } @DocumentExample @@ -43,7 +43,7 @@ void oneInnerClass() { java( """ import org.junit.jupiter.api.Test; - + public class RootTest { public class InnerTest { @Test @@ -55,7 +55,7 @@ public void test() { """ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; - + public class RootTest { @Nested public class InnerTest { @@ -76,19 +76,19 @@ void multipleInnerClasses() { java( """ import org.junit.jupiter.api.Test; - + public class RootTest { public class InnerTest { @Test public void test() { } } - + public class Inner2Test { @Test public void test() { } - + public class InnermostTest { @Test public void test() { @@ -100,7 +100,7 @@ public void test() { """ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; - + public class RootTest { @Nested public class InnerTest { @@ -108,13 +108,13 @@ public class InnerTest { public void test() { } } - + @Nested public class Inner2Test { @Test public void test() { } - + @Nested public class InnermostTest { @Test @@ -135,14 +135,14 @@ void doesNotAnnotationNonTestInnerClass() { java( """ import org.junit.jupiter.api.Test; - + public class RootTest { public class InnerTest { @Test public void test() { } } - + public static class Foo { public void bar() { } @@ -152,7 +152,7 @@ public void bar() { """ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; - + public class RootTest { @Nested public class InnerTest { @@ -160,7 +160,7 @@ public class InnerTest { public void test() { } } - + public static class Foo { public void bar() { } @@ -178,7 +178,7 @@ void removesStatic() { java( """ import org.junit.jupiter.api.Test; - + public class RootTest { public static class InnerTest { @Test @@ -190,7 +190,7 @@ public void test() { """ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; - + public class RootTest { @Nested public class InnerTest { @@ -211,15 +211,15 @@ void doesNotNestAnnotationType() { java( """ import static java.lang.annotation.RetentionPolicy.RUNTIME; - + import java.lang.annotation.Retention; import org.junit.jupiter.api.Test; - + public class SingleTest { @CustomTest public void test() { } - + @Retention(RUNTIME) @Test @interface CustomTest { diff --git a/src/test/java/org/openrewrite/java/testing/junit5/AddMissingTestBeforeAfterAnnotationsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/AddMissingTestBeforeAfterAnnotationsTest.java index 1317b2be2..fe1ca5ef7 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/AddMissingTestBeforeAfterAnnotationsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/AddMissingTestBeforeAfterAnnotationsTest.java @@ -28,7 +28,7 @@ class AddMissingTestBeforeAfterAnnotationsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "junit-jupiter-api-5")) .recipe(new AddMissingTestBeforeAfterAnnotations()); } @@ -41,7 +41,7 @@ void addMissingTestBeforeAfterAnnotationsIfOldFound() { import org.junit.After; import org.junit.Before; import org.junit.Test; - + public class AbstractTest { @Before public void before() { @@ -59,7 +59,7 @@ public void test() { ), java( """ - public class A extends AbstractTest { + public class A extends AbstractTest { public void before() { } @@ -74,7 +74,7 @@ public void test() { import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - + public class A extends AbstractTest { @BeforeEach public void before() { @@ -102,7 +102,7 @@ void addMissingTestBeforeAfterAnnotationsIfNewFound() { import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - + public class AbstractTest { @BeforeEach public void before() { @@ -120,7 +120,7 @@ public void test() { ), java( """ - public class A extends AbstractTest { + public class A extends AbstractTest { public void before() { } @@ -135,7 +135,7 @@ public void test() { import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - + public class A extends AbstractTest { @BeforeEach public void before() { @@ -163,7 +163,7 @@ void addMissingTestBeforeAfterAnnotationsIfExtended() { import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - + public class AbstractTest { @BeforeEach public void before() { @@ -196,7 +196,7 @@ public void test() { import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - + public class A extends AbstractTest { @BeforeEach public void before() { @@ -229,7 +229,7 @@ public void test() { import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - + public class B extends A { @BeforeEach public void before() { diff --git a/src/test/java/org/openrewrite/java/testing/junit5/AddParameterizedTestAnnotationTest.java b/src/test/java/org/openrewrite/java/testing/junit5/AddParameterizedTestAnnotationTest.java index eb25d9d0d..e1fa69d2b 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/AddParameterizedTestAnnotationTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/AddParameterizedTestAnnotationTest.java @@ -32,9 +32,9 @@ class AddParameterizedTestAnnotationTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "junit-jupiter-params-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "junit-jupiter-params-5")) .parser(KotlinParser.builder() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "junit-jupiter-params-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "junit-jupiter-params-5")) .recipe(new AddParameterizedTestAnnotation()); } @@ -49,7 +49,7 @@ void replaceTestWithParameterizedTest() { import org.junit.jupiter.api.Test; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; - + class NumbersTest { @Test @ValueSource(ints = {1, 3, 5, -3, 15, Integer.MAX_VALUE}) @@ -62,7 +62,7 @@ void testIsOdd(int number) { import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; - + class NumbersTest { @ParameterizedTest @ValueSource(ints = {1, 3, 5, -3, 15, Integer.MAX_VALUE}) @@ -113,7 +113,7 @@ void replaceTestWithParameterizedTestRegardlessOfOrder() { import org.junit.jupiter.api.Test; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; - + class NumbersTest { @ValueSource(ints = {1, 3, 5, -3, 15, Integer.MAX_VALUE}) @Test @@ -126,7 +126,7 @@ void testIsOdd(int number) { import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; - + class NumbersTest { @ParameterizedTest @ValueSource(ints = {1, 3, 5, -3, 15, Integer.MAX_VALUE}) @@ -150,7 +150,7 @@ void onlyReplacesWithValueSourceAnnotation() { java( """ import org.junit.jupiter.api.Test; - + class NumbersTest { @Test void printMessage() { @@ -170,7 +170,7 @@ void replacesCsvSource() { """ import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.api.Test; - + class TestClass { @Test @CsvSource({"test@test.com"}) @@ -182,7 +182,7 @@ void processUserData(String email) { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; - + class TestClass { @ParameterizedTest @CsvSource({"test@test.com"}) @@ -203,7 +203,7 @@ void replacesMethodSource() { """ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.provider.MethodSource; - + class TestClass { @Test @MethodSource() @@ -215,7 +215,7 @@ void foo() { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; - + class TestClass { @ParameterizedTest @MethodSource() @@ -237,7 +237,7 @@ void addMissingAnnotation() { import org.junit.jupiter.api.Test; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; - + class TestClass { @Test @ValueSource(ints = {1, 3, 5, -3, 15, Integer.MAX_VALUE}) @@ -250,7 +250,7 @@ void testIsOdd(int number) { import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; - + class TestClass { @ParameterizedTest @ValueSource(ints = {1, 3, 5, -3, 15, Integer.MAX_VALUE}) @@ -271,7 +271,7 @@ void replacesNullSource() { """ import org.junit.jupiter.params.provider.NullSource; import org.junit.jupiter.api.Test; - + class TestClass { @Test @NullSource @@ -283,7 +283,7 @@ void processUserData(String email) { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullSource; - + class TestClass { @ParameterizedTest @NullSource @@ -304,7 +304,7 @@ void replacesEmptySource() { """ import org.junit.jupiter.params.provider.EmptySource; import org.junit.jupiter.api.Test; - + class TestClass { @Test @EmptySource @@ -316,7 +316,7 @@ void processUserData(String email) { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EmptySource; - + class TestClass { @ParameterizedTest @EmptySource @@ -337,7 +337,7 @@ void replacesNullAndEmptySource() { """ import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.api.Test; - + class TestClass { @Test @NullAndEmptySource @@ -349,7 +349,7 @@ void processUserData(String email) { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullAndEmptySource; - + class TestClass { @ParameterizedTest @NullAndEmptySource @@ -370,7 +370,7 @@ void replacesEnumSource() { """ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.api.Test; - + class TestClass { enum time { MORNING, @@ -378,7 +378,7 @@ enum time { AFTERNOON, MIDNIGHT } - + @Test @EnumSource void processTime(time timeOfDay) { @@ -389,7 +389,7 @@ void processTime(time timeOfDay) { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; - + class TestClass { enum time { MORNING, @@ -397,7 +397,7 @@ enum time { AFTERNOON, MIDNIGHT } - + @ParameterizedTest @EnumSource void processTime(time timeOfDay) { @@ -418,7 +418,7 @@ void replacesCsvFileSource() { import org.junit.jupiter.params.provider.CsvFileSource; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; - + class TestClass { @Test @CsvFileSource(files = "src/test/resources/two-column.csv", numLinesToSkip = 1) @@ -432,7 +432,7 @@ void testWithCsvFileSourceFromFile(String country, int reference) { import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvFileSource; import static org.junit.jupiter.api.Assertions.*; - + class TestClass { @ParameterizedTest @CsvFileSource(files = "src/test/resources/two-column.csv", numLinesToSkip = 1) @@ -459,7 +459,7 @@ void replacesArgumentSource() { import org.junit.jupiter.api.Test; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.*; - + class TestClass { @Test @ArgumentsSource(MyArgumentsProvider.class) @@ -482,7 +482,7 @@ public Stream provideArguments(ExtensionContext context) { import org.junit.jupiter.params.provider.ArgumentsSource; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.*; - + class TestClass { @ParameterizedTest @ArgumentsSource(MyArgumentsProvider.class) diff --git a/src/test/java/org/openrewrite/java/testing/junit5/AssertThrowsOnLastStatementTest.java b/src/test/java/org/openrewrite/java/testing/junit5/AssertThrowsOnLastStatementTest.java index 29a6e4678..46011570a 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/AssertThrowsOnLastStatementTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/AssertThrowsOnLastStatementTest.java @@ -32,7 +32,7 @@ public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() //.logCompilationWarningsAndErrors(true) - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new AssertThrowsOnLastStatement()); } @@ -44,12 +44,12 @@ void applyToLastStatementWithDeclaringVariableThreeLines() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; - + class MyTest { - + @Test public void test() { Throwable exception = assertThrows(IllegalArgumentException.class, () -> { @@ -65,12 +65,12 @@ void foo() { """, """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; - + class MyTest { - + @Test public void test() { foo(); @@ -94,12 +94,12 @@ void applyToLastStatementWithDeclaringVariableThreeLinesHasLineBefore() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; - + class MyTest { - + @Test public void test() { System.out.println("bla"); @@ -116,12 +116,12 @@ void foo() { """, """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; - + class MyTest { - + @Test public void test() { System.out.println("bla"); @@ -146,11 +146,11 @@ void applyToLastStatementNoDeclaringVariableTwoLinesNoLinesAfter() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertThrows; - + class MyTest { - + @Test public void test() { assertThrows(IllegalArgumentException.class, () -> { @@ -164,11 +164,11 @@ void foo() { """, """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertThrows; - + class MyTest { - + @Test public void test() { System.out.println("foo"); @@ -190,11 +190,11 @@ void applyToLastStatementHasMessage() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertThrows; - + class MyTest { - + @Test public void test() { assertThrows(IllegalArgumentException.class, () -> { @@ -208,11 +208,11 @@ void foo() { """, """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertThrows; - + class MyTest { - + @Test public void test() { System.out.println("foo"); @@ -235,12 +235,12 @@ void makeNoChangesAsOneLine() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; - + class MyTest { - + @Test public void test() { Throwable exception = assertThrows(IllegalArgumentException.class, () -> foo()); @@ -262,16 +262,16 @@ void bodyNull() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.*; - + class MyTest { - + @Test void test() { assertThrows(IllegalStateException.class, () -> System.out.println("foo")); } - + interface InnerInterface { String createParser(String input); } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/AssertToAssertionsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/AssertToAssertionsTest.java index dc601966a..dd961fb60 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/AssertToAssertionsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/AssertToAssertionsTest.java @@ -35,7 +35,7 @@ class AssertToAssertionsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "hamcrest-3")) .recipe(new AssertToAssertions()); } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/AssertTrueInstanceofToAssertInstanceOfTest.java b/src/test/java/org/openrewrite/java/testing/junit5/AssertTrueInstanceofToAssertInstanceOfTest.java index 8d588e483..0950df14f 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/AssertTrueInstanceofToAssertInstanceOfTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/AssertTrueInstanceofToAssertInstanceOfTest.java @@ -29,7 +29,7 @@ class AssertTrueInstanceofToAssertInstanceOfTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9", "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5", "junit-4")) .recipe(new AssertTrueInstanceofToAssertInstanceOf()); } @@ -43,9 +43,9 @@ void jUnit5() { import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; - + import static org.junit.jupiter.api.Assertions.assertTrue; - + class ATest { @Test void testJUnit5() { @@ -58,9 +58,9 @@ void testJUnit5() { import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; - + import static org.junit.jupiter.api.Assertions.assertInstanceOf; - + class ATest { @Test void testJUnit5() { @@ -81,9 +81,9 @@ void jUnit5WithReason() { import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; - + import static org.junit.jupiter.api.Assertions.assertTrue; - + class ATest { @Test void testJUnit5() { @@ -96,9 +96,9 @@ void testJUnit5() { import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; - + import static org.junit.jupiter.api.Assertions.assertInstanceOf; - + class ATest { @Test void testJUnit5() { @@ -119,9 +119,9 @@ void jUnit4() { import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; - + import static org.junit.Assert.assertTrue; - + class ATest { @Test void testJUnit5() { @@ -134,9 +134,9 @@ void testJUnit5() { import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; - + import static org.junit.jupiter.api.Assertions.assertInstanceOf; - + class ATest { @Test void testJUnit5() { @@ -157,9 +157,9 @@ void jUnit4WithReason() { import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; - + import static org.junit.Assert.assertTrue; - + class ATest { @Test void testJUnit5() { @@ -172,9 +172,9 @@ void testJUnit5() { import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; - + import static org.junit.jupiter.api.Assertions.assertInstanceOf; - + class ATest { @Test void testJUnit5() { diff --git a/src/test/java/org/openrewrite/java/testing/junit5/AssumeToAssumptionsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/AssumeToAssumptionsTest.java index a0cf14ccd..04b3d6aa1 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/AssumeToAssumptionsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/AssumeToAssumptionsTest.java @@ -31,7 +31,7 @@ class AssumeToAssumptionsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "hamcrest-2.2")); + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "hamcrest-3")); } @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/54") @@ -46,7 +46,7 @@ void assumeToAssumptions() { java( """ import org.junit.Assume; - + class Test { void test() { Assume.assumeTrue("One is one", true); @@ -55,7 +55,7 @@ void test() { """, """ import org.junit.jupiter.api.Assumptions; - + class Test { void test() { Assumptions.assumeTrue(true, "One is one"); diff --git a/src/test/java/org/openrewrite/java/testing/junit5/CategoryToTagTest.java b/src/test/java/org/openrewrite/java/testing/junit5/CategoryToTagTest.java index bdd5ee1d7..b04d9a0c4 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/CategoryToTagTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/CategoryToTagTest.java @@ -30,7 +30,7 @@ class CategoryToTagTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipe(new CategoryToTag()); } @@ -46,11 +46,11 @@ void categoriesHavingJAssignmentArguments() { @Category(value = SlowTests.class) public class B { - + } @Category(value = {SlowTests.class, FastTests.class}) public class C { - + } """, """ @@ -58,13 +58,13 @@ public class C { @Tag("SlowTests") public class B { - + } - + @Tag("SlowTests") @Tag("FastTests") public class C { - + } """ ) @@ -143,7 +143,7 @@ public class B { @Test public void b() { } - + @Test public void d() { } @@ -160,7 +160,7 @@ public class B { @Test public void b() { } - + @Test public void d() { } @@ -181,9 +181,9 @@ void maintainAnnotationPositionAmongOtherAnnotations() { """ import lombok.Data; import org.junit.experimental.categories.Category; - + import java.lang.annotation.Documented; - + @Documented @Category({FastTests.class, SlowTests.class}) @Data @@ -194,15 +194,15 @@ public class B { """ import lombok.Data; import org.junit.jupiter.api.Tag; - + import java.lang.annotation.Documented; - + @Documented @Tag("FastTests") @Tag("SlowTests") @Data public class B { - + } """ ) @@ -217,26 +217,26 @@ void removesDefunctImport() { java( """ package a; - + public interface FastTests {} """ ), java( """ package b; - + import a.FastTests; import org.junit.experimental.categories.Category; - + @Category({FastTests.class}) public class B { } """, """ package b; - + import org.junit.jupiter.api.Tag; - + @Tag("FastTests") public class B { } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/CleanupAssertionsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/CleanupAssertionsTest.java index 52f0d6ce1..9f55c972f 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/CleanupAssertionsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/CleanupAssertionsTest.java @@ -30,7 +30,7 @@ class CleanupAssertionsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipeFromResources("org.openrewrite.java.testing.junit5.CleanupAssertions"); } @@ -74,7 +74,7 @@ void assertFalseNegatedEqualsToAssertEquals() { """ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; - + class ExampleTest { @Test void test() { diff --git a/src/test/java/org/openrewrite/java/testing/junit5/CleanupJUnitImportsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/CleanupJUnitImportsTest.java index 08c9e112c..507a41b61 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/CleanupJUnitImportsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/CleanupJUnitImportsTest.java @@ -32,9 +32,9 @@ class CleanupJUnitImportsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .parser(KotlinParser.builder() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipe(new CleanupJUnitImports()); } @@ -46,7 +46,7 @@ void removesUnusedImport() { java( """ import org.junit.Test; - + public class MyTest {} """, """ @@ -76,7 +76,7 @@ void leavesOtherImportsAlone() { import java.util.Arrays; import java.util.Collections; import java.util.HashSet; - + public class MyTest { } """ @@ -102,7 +102,7 @@ void leavesUsedJUnitImportAlone() { java( """ import org.junit.Test; - + public class MyTest { @Test public void foo() {} diff --git a/src/test/java/org/openrewrite/java/testing/junit5/EnclosedToNestedTest.java b/src/test/java/org/openrewrite/java/testing/junit5/EnclosedToNestedTest.java index 764017615..439e4e03f 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/EnclosedToNestedTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/EnclosedToNestedTest.java @@ -30,7 +30,7 @@ class EnclosedToNestedTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipeFromResources("org.openrewrite.java.testing.junit5.JUnit4to5Migration"); } @@ -44,7 +44,7 @@ void oneInnerClass() { import org.junit.Test; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; - + @RunWith(Enclosed.class) public class RootTest { public static class InnerTest { @@ -57,7 +57,7 @@ public void test() { """ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; - + public class RootTest { @Nested public class InnerTest { @@ -80,7 +80,7 @@ void multipleInnerClasses() { import org.junit.Test; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; - + @RunWith(Enclosed.class) public class RootTest { public static class InnerTest { @@ -88,12 +88,12 @@ public static class InnerTest { public void test() { } } - + public static class Inner2Test { @Test public void test() { } - + public static class InnermostTest { @Test public void test() { @@ -105,7 +105,7 @@ public void test() { """ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; - + public class RootTest { @Nested public class InnerTest { @@ -113,13 +113,13 @@ public class InnerTest { public void test() { } } - + @Nested public class Inner2Test { @Test public void test() { } - + @Nested public class InnermostTest { @Test @@ -142,7 +142,7 @@ void recognizesTestAnnotationWithArguments() { import org.junit.Test; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; - + @RunWith(Enclosed.class) public class RootTest { public static class InnerTest { @@ -156,9 +156,9 @@ public void test() { import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; - + import java.util.concurrent.TimeUnit; - + public class RootTest { @Nested public class InnerTest { @@ -182,7 +182,7 @@ void doesNotAnnotateNonTestInnerClasses() { import org.junit.Test; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; - + @RunWith(Enclosed.class) public class RootTest { public static class InnerTest { @@ -190,7 +190,7 @@ public static class InnerTest { public void test() { } } - + public static class Foo { public void bar() { } @@ -200,7 +200,7 @@ public void bar() { """ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; - + public class RootTest { @Nested public class InnerTest { @@ -208,7 +208,7 @@ public class InnerTest { public void test() { } } - + public static class Foo { public void bar() { } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrowsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrowsTest.java index e8434f643..a5e324aab 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrowsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrowsTest.java @@ -33,7 +33,7 @@ public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() .logCompilationWarningsAndErrors(true) - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "hamcrest-3")) .recipe(new ExpectedExceptionToAssertThrows()); } @@ -48,7 +48,7 @@ void leavesOtherRulesAlone() { import org.junit.rules.ExpectedException; class MyTest { - + @Rule TemporaryFolder tempDir = new TemporaryFolder(); @@ -82,7 +82,7 @@ void expectedExceptionRule() { import org.junit.rules.ExpectedException; class MyTest { - + @Rule ExpectedException thrown = ExpectedException.none(); @@ -98,12 +98,12 @@ void foo() { """, """ import org.junit.Test; - + import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; - + class MyTest { - + @Test public void testEmptyPath() { Throwable exception = assertThrows(IllegalArgumentException.class, () -> @@ -129,11 +129,11 @@ void removeExpectedExceptionAndLeaveMethodAlone() { import org.junit.Rule; import org.junit.rules.ExpectedException; - + public class SimpleExpectedExceptionTest { @Rule public ExpectedException thrown = ExpectedException.none(); - + public void doNotChange() { final String noChanges = "atAll"; } @@ -143,7 +143,7 @@ public void doNotChange() { package org.openrewrite.java.testing.junit5; public class SimpleExpectedExceptionTest { - + public void doNotChange() { final String noChanges = "atAll"; } @@ -163,11 +163,11 @@ void refactorExceptClass() { import org.junit.Rule; import org.junit.rules.ExpectedException; - + public class SimpleExpectedExceptionTest { @Rule public ExpectedException thrown = ExpectedException.none(); - + public void throwsExceptionWithSpecificType() { thrown.expect(NullPointerException.class); throw new NullPointerException(); @@ -176,11 +176,11 @@ public void throwsExceptionWithSpecificType() { """, """ package org.openrewrite.java.testing.junit5; - + import static org.junit.jupiter.api.Assertions.assertThrows; - + public class SimpleExpectedExceptionTest { - + public void throwsExceptionWithSpecificType() { assertThrows(NullPointerException.class, () -> { throw new NullPointerException(); @@ -203,13 +203,13 @@ void refactorExceptWithMatcher() { import org.junit.Rule; import org.junit.rules.ExpectedException; - + import static org.hamcrest.Matchers.isA; public class SimpleExpectedExceptionTest { @Rule public ExpectedException thrown = ExpectedException.none(); - + public void throwsExceptionWithSpecificType() { thrown.expect(isA(NullPointerException.class)); throw new NullPointerException(); @@ -218,13 +218,13 @@ public void throwsExceptionWithSpecificType() { """, """ package org.openrewrite.java.testing.junit5; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.isA; import static org.junit.jupiter.api.Assertions.assertThrows; - + public class SimpleExpectedExceptionTest { - + public void throwsExceptionWithSpecificType() { Throwable exception = assertThrows(Exception.class, () -> { throw new NullPointerException(); @@ -246,14 +246,14 @@ void refactorExpectMessageString() { java( """ package org.openrewrite.java.testing.junit5; - + import org.junit.Rule; import org.junit.rules.ExpectedException; - + public class SimpleExpectedExceptionTest { @Rule public ExpectedException thrown = ExpectedException.none(); - + public void statementsBeforeExpected() { int[] a = new int[] { 1 }; thrown.expect(IndexOutOfBoundsException.class); @@ -264,12 +264,12 @@ public void statementsBeforeExpected() { """, """ package org.openrewrite.java.testing.junit5; - + import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; - + public class SimpleExpectedExceptionTest { - + public void statementsBeforeExpected() { Throwable exception = assertThrows(IndexOutOfBoundsException.class, () -> { int[] a = new int[]{1}; @@ -291,16 +291,16 @@ void refactorExpectMessageWithMatcher() { java( """ package org.openrewrite.java.testing.junit5; - + import org.junit.Rule; import org.junit.rules.ExpectedException; import static org.hamcrest.Matchers.containsString; - + public class ExampleTests { @Rule public ExpectedException thrown = ExpectedException.none(); - + public void expectMessageWithMatcher() { this.thrown.expectMessage(containsString("rewrite expectMessage")); throw new NullPointerException("rewrite expectMessage with hamcrest matcher."); @@ -309,13 +309,13 @@ public void expectMessageWithMatcher() { """, """ package org.openrewrite.java.testing.junit5; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertThrows; - + public class ExampleTests { - + public void expectMessageWithMatcher() { Throwable exception = assertThrows(Exception.class, () -> { throw new NullPointerException("rewrite expectMessage with hamcrest matcher."); @@ -336,16 +336,16 @@ void refactorExpectCauseWithMatchers() { java( """ package org.openrewrite.java.testing.junit5; - + import org.junit.Rule; import org.junit.rules.ExpectedException; import static org.hamcrest.Matchers.nullValue; - + public class ExampleTests { @Rule public ExpectedException thrown = ExpectedException.none(); - + public void expectCause() { this.thrown.expectCause(nullValue()); throw new NullPointerException("rewrite expectMessage with hamcrest matcher."); @@ -354,13 +354,13 @@ public void expectCause() { """, """ package org.openrewrite.java.testing.junit5; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.nullValue; import static org.junit.jupiter.api.Assertions.assertThrows; - + public class ExampleTests { - + public void expectCause() { Throwable exception = assertThrows(Exception.class, () -> { throw new NullPointerException("rewrite expectMessage with hamcrest matcher."); @@ -381,16 +381,16 @@ void refactorExpectException() { java( """ package org.openrewrite.java.testing.junit5; - + import org.junit.Rule; import org.junit.rules.ExpectedException; import static org.hamcrest.Matchers.*; - + public class ExampleTests { @Rule public ExpectedException thrown = ExpectedException.none(); - + public void expectExceptionUseCases() { this.thrown.expect(isA(NullPointerException.class)); this.thrown.expectMessage(containsString("rewrite expectMessage")); @@ -401,13 +401,13 @@ public void expectExceptionUseCases() { """, """ package org.openrewrite.java.testing.junit5; - + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertThrows; - + public class ExampleTests { - + public void expectExceptionUseCases() { Throwable exception = assertThrows(Exception.class, () -> { throw new NullPointerException("rewrite expectMessage with hamcrest matcher."); @@ -436,7 +436,7 @@ void expectedCheckedExceptionThrowsRemoved() { import org.junit.rules.ExpectedException; class MyTest { - + @Rule ExpectedException thrown = ExpectedException.none(); @@ -455,9 +455,9 @@ void foo() throws IOException { import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.Test; - + class MyTest { - + @Test public void testEmptyPath() { assertThrows(IOException.class, () -> diff --git a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5BestPracticesTest.java b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5BestPracticesTest.java index 64678e4bf..e8dac1052 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5BestPracticesTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5BestPracticesTest.java @@ -32,7 +32,7 @@ class JUnit5BestPracticesTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipe(Environment.builder() .scanRuntimeClasspath("org.openrewrite.java.testing") .build() @@ -163,7 +163,7 @@ public class Example { @Test public void something() { } - + @Ignore("not ready yet") @Test public void somethingElse() { @@ -179,7 +179,7 @@ class Example { @Test void something() { } - + @Disabled("not ready yet") @Test void somethingElse() { diff --git a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java index b79d389ab..315b8ef96 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java @@ -40,7 +40,7 @@ class JUnit5MigrationTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipe(Environment.builder() .scanRuntimeClasspath("org.openrewrite.java.testing.junit5") .build() @@ -83,7 +83,7 @@ void assertThatReceiver() { rewriteRun( spec -> spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "hamcrest-2.2")), + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "hamcrest-3")), java( """ import org.junit.Assert; @@ -449,7 +449,7 @@ void addMockitoJupiterDependencyIfExtendWithPresent() { rewriteRun( spec -> spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "mockito-all-1.10")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "mockito-all-1.10")) .recipe(Environment.builder() .scanRuntimeClasspath("org.openrewrite.java.testing.junit5") .build() diff --git a/src/test/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterizedTest.java b/src/test/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterizedTest.java index 0e4cba2c4..405b0aba5 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterizedTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterizedTest.java @@ -31,7 +31,7 @@ class JUnitParamsRunnerToParameterizedTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "JUnitParams-1.1", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "JUnitParams-1.1", "hamcrest-3")) .recipe(new JUnitParamsRunnerToParameterized()); } @@ -46,24 +46,24 @@ void hasAssociatedMethodSource() { import org.junit.runner.RunWith; import junitparams.JUnitParamsRunner; import junitparams.Parameters; - + @RunWith(JUnitParamsRunner.class) public class PersonTests { - + @Test @Parameters public void personIsAdult(int age, boolean valid) { } - + private Object[] parametersForPersonIsAdult() { return new Object[]{new Object[]{13, false}, new Object[]{17, false}}; } - + @Test @Parameters public void personIsChild(int age, boolean valid) { } - + private Object[] parametersForPersonIsChild() { return new Object[]{new Object[]{3, false}, new Object[]{7, false}}; } @@ -72,23 +72,23 @@ private Object[] parametersForPersonIsChild() { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; - + public class PersonTests { - + @ParameterizedTest @MethodSource("parametersForPersonIsAdult") public void personIsAdult(int age, boolean valid) { } - + private static Object[] parametersForPersonIsAdult() { return new Object[]{new Object[]{13, false}, new Object[]{17, false}}; } - + @ParameterizedTest @MethodSource("parametersForPersonIsChild") public void personIsChild(int age, boolean valid) { } - + private static Object[] parametersForPersonIsChild() { return new Object[]{new Object[]{3, false}, new Object[]{7, false}}; } @@ -110,39 +110,39 @@ void hasSpecifiedMethodSource() { import junitparams.Parameters; import junitparams.NamedParameters; import junitparams.naming.TestCaseName; - + @RunWith(JUnitParamsRunner.class) public class PersonTests { - + @Test @Parameters(method = "youngAdultPersonParams") @TestCaseName("persons-age: {0} is-young-adult: {1}") public void personIsAdult(int age, boolean valid) { } - + private Object[] youngAdultPersonParams() { return new Object[]{new Object[]{13, false}, new Object[]{17, false}}; } - + @Test @Parameters(named = "named-params") @TestCaseName("persons-age: {0} is-young-adult: {1}") public void personIsNamedAdult(int age, boolean valid) { } - + @NamedParameters("named-params") private Object[] namedPeopleParams() { return new Object[]{new Object[]{13, false}, new Object[]{17, false}}; } - + @Test @Parameters(method = "named2,named3") public void paramsInMultipleMethods(String p1, Integer p2) { } - + private Object named2() { return new Object[]{"AAA", 1}; } - + private Object named3() { return new Object[]{"BBB", 2}; } @@ -151,36 +151,36 @@ private Object named3() { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; - + public class PersonTests { - + @ParameterizedTest(name = "persons-age: {0} is-young-adult: {1}") @MethodSource("youngAdultPersonParams") public void personIsAdult(int age, boolean valid) { } - + private static Object[] youngAdultPersonParams() { return new Object[]{new Object[]{13, false}, new Object[]{17, false}}; } - + @ParameterizedTest(name = "persons-age: {0} is-young-adult: {1}") @MethodSource("namedPeopleParams") public void personIsNamedAdult(int age, boolean valid) { } - - + + private static Object[] namedPeopleParams() { return new Object[]{new Object[]{13, false}, new Object[]{17, false}}; } - + @ParameterizedTest @MethodSource({"named2", "named3"}) public void paramsInMultipleMethods(String p1, Integer p2) { } - + private static Object named2() { return new Object[]{"AAA", 1}; } - + private static Object named3() { return new Object[]{"BBB", 2}; } @@ -200,9 +200,9 @@ void enumSourceNotConverted() { import org.junit.runner.RunWith; import junitparams.JUnitParamsRunner; import junitparams.Parameters; - + enum PersonType {MALE, FEMALE} - + @RunWith(JUnitParamsRunner.class) class EnumSourceTests { @Test @@ -215,9 +215,9 @@ public void enumsAsParamsInMethod(PersonType person) { } import org.junit.runner.RunWith; import junitparams.JUnitParamsRunner; import junitparams.Parameters; - + enum PersonType {MALE, FEMALE} - + @RunWith(JUnitParamsRunner.class) class EnumSourceTests { @Test diff --git a/src/test/java/org/openrewrite/java/testing/junit5/LifecycleNonPrivateTest.java b/src/test/java/org/openrewrite/java/testing/junit5/LifecycleNonPrivateTest.java index b1391537a..8d8e42125 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/LifecycleNonPrivateTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/LifecycleNonPrivateTest.java @@ -31,7 +31,7 @@ class LifecycleNonPrivateTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new LifecycleNonPrivate()); } @@ -43,7 +43,7 @@ void beforeEachPrivate() { java( """ import org.junit.jupiter.api.BeforeEach; - + class MyTest { @BeforeEach private void beforeEach() { @@ -54,7 +54,7 @@ private void unaffected() { """, """ import org.junit.jupiter.api.BeforeEach; - + class MyTest { @BeforeEach void beforeEach() { @@ -74,7 +74,7 @@ void afterAllPrivate() { java( """ import org.junit.jupiter.api.AfterAll; - + class MyTest { @AfterAll private static void afterAll() { @@ -85,7 +85,7 @@ private void unaffected() { """, """ import org.junit.jupiter.api.AfterAll; - + class MyTest { @AfterAll static void afterAll() { @@ -107,7 +107,7 @@ void beforeEachAfterAllUnchanged() { """ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; - + class MyTest { @BeforeEach void beforeEach() { diff --git a/src/test/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCaseTest.java b/src/test/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCaseTest.java index 650b7f0e4..82a17c163 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCaseTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCaseTest.java @@ -30,7 +30,7 @@ class MigrateJUnitTestCaseTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "hamcrest-3")) .recipe(new MigrateJUnitTestCase()); } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterizedTest.java b/src/test/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterizedTest.java index 096e2aab3..b4a2f1954 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterizedTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterizedTest.java @@ -32,7 +32,7 @@ class ParameterizedRunnerToParameterizedTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "hamcrest-3")) .recipe(new ParameterizedRunnerToParameterized()); } @@ -63,28 +63,28 @@ public void setLastName(String lastName) { java( """ package abc; - + import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.*; import org.junit.runners.Parameterized.Parameters; - + import java.util.Arrays; import java.util.List; - + @RunWith(Parameterized.class) public class VetTests { - + private String firstName; private String lastName; private Integer id; - + public VetTests(String firstName, String lastName, Integer id) { this.firstName = firstName; this.lastName = lastName; this.id = id; } - + @Test public void testSerialization() { Vet vet = new Vet(); @@ -92,7 +92,7 @@ public void testSerialization() { vet.setLastName(lastName); vet.setId(id); } - + @Parameters(name="{index}: {0} {1} - {2}") public static List parameters() { return Arrays.asList( @@ -103,25 +103,25 @@ public static List parameters() { """, """ package abc; - + import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; - + import java.util.Arrays; import java.util.List; - + public class VetTests { - + private String firstName; private String lastName; private Integer id; - + public void initVetTests(String firstName, String lastName, Integer id) { this.firstName = firstName; this.lastName = lastName; this.id = id; } - + @MethodSource("parameters") @ParameterizedTest(name = "{index}: {0} {1} - {2}") public void testSerialization(String firstName, String lastName, Integer id) { @@ -131,7 +131,7 @@ public void testSerialization(String firstName, String lastName, Integer id) { vet.setLastName(lastName); vet.setId(id); } - + public static List parameters() { return Arrays.asList( new Object[] { "Otis", "TheDog", 124 }, @@ -155,23 +155,23 @@ void parameterizedTestToParameterizedTestsWithMethodSource() { import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; - + import java.util.Arrays; import java.util.List; - + @RunWith(Parameterized.class) public class VetTests { - + private String firstName; private String lastName; private Integer id; - + public VetTests(String firstName, String lastName, Integer id) { this.firstName = firstName; this.lastName = lastName; this.id = id; } - + @Test public void testSerialization() { Vet vet = new Vet(); @@ -179,7 +179,7 @@ public void testSerialization() { vet.setLastName(lastName); vet.setId(id); } - + @Parameters public static List parameters() { return Arrays.asList( @@ -191,22 +191,22 @@ public static List parameters() { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; - + import java.util.Arrays; import java.util.List; - + public class VetTests { - + private String firstName; private String lastName; private Integer id; - + public void initVetTests(String firstName, String lastName, Integer id) { this.firstName = firstName; this.lastName = lastName; this.id = id; } - + @MethodSource("parameters") @ParameterizedTest public void testSerialization(String firstName, String lastName, Integer id) { @@ -216,7 +216,7 @@ public void testSerialization(String firstName, String lastName, Integer id) { vet.setLastName(lastName); vet.setId(id); } - + public static List parameters() { return Arrays.asList( new Object[] { "Otis", "TheDog", 124 }, @@ -269,27 +269,27 @@ public void checkName() { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; - + import java.util.Arrays; import java.util.List; import java.util.Map; - + public class RewriteTests { public String name; public String nickName; public Integer id; public Map stuff; - + public static List parameters() { return Arrays.asList(new Object[]{124, "Otis", "TheDog", Map.of("toys", "ball", "treats", "bacon")}, new Object[]{126, "Garfield", "TheBoss", Map.of("toys", "yarn", "treats", "fish")}); } - + @MethodSource("parameters") @ParameterizedTest(name = "{index}: {0} {1} - {2}") public void checkName(Integer id, String name, String nickName, Map stuff) { initRewriteTests(id, name, nickName, stuff); } - + public void initRewriteTests(Integer id, String name, String nickName, Map stuff) { this.id = id; this.name = name; @@ -311,29 +311,29 @@ void paramsAreFinalFields() { """ import java.util.ArrayList; import java.util.List; - + import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; - + @RunWith(Parameterized.class) public class DateFormatTests { private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.S z"; private final String input; private final String output; private final int hour; - + public DateFormatTests(String pattern, String input, String output, int hourForTest) { this.output = output; this.input = input; hour = hourForTest; } - + @Test public void testDateFormat() { } - + @Parameters public static List data() { List params = new ArrayList<>(); @@ -345,28 +345,28 @@ public static List data() { """ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; - + import java.util.ArrayList; import java.util.List; - + public class DateFormatTests { private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.S z"; private String input; private String output; private int hour; - + public void initDateFormatTests(String pattern, String input, String output, int hourForTest) { this.output = output; this.input = input; hour = hourForTest; } - + @MethodSource("data") @ParameterizedTest public void testDateFormat(String pattern, String input, String output, int hourForTest) { initDateFormatTests(pattern, input, output, hourForTest); } - + public static List data() { List params = new ArrayList<>(); params.add(new Object[]{DATE_FORMAT, "1970-01-01 11:20:34.0 GMT", "1970-01-01 11:20:34.0 GMT", 11}); @@ -532,7 +532,7 @@ void parameterizedTestWithEmptyConstructor() { import java.util.Arrays; import java.util.Collection; import org.junit.runners.Parameterized; - + class SampleTestClass { @Parameterized.Parameter(value = 0) public int num1; @@ -540,10 +540,10 @@ class SampleTestClass { public int num2; @Parameterized.Parameter(value = 2) public int num3; - + public SampleTestClass() { } - + @Parameterized.Parameters public static Collection data() { return Arrays.asList(new Object[][]{ @@ -556,22 +556,22 @@ public static Collection data() { """ import java.util.Arrays; import java.util.Collection; - + class SampleTestClass { public int num1; public int num2; public int num3; - + public SampleTestClass() { } - + public static Collection data() { return Arrays.asList(new Object[][]{ {1, 2, 3}, {4, 5, 6} }); } - + public void initSampleTestClass(int num1, int num2, int num3) { this.num1 = num1; this.num2 = num2; diff --git a/src/test/java/org/openrewrite/java/testing/junit5/RemoveDuplicateTestTemplatesTest.java b/src/test/java/org/openrewrite/java/testing/junit5/RemoveDuplicateTestTemplatesTest.java index f54098fde..78e2d8aa0 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/RemoveDuplicateTestTemplatesTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/RemoveDuplicateTestTemplatesTest.java @@ -30,7 +30,7 @@ class RemoveDuplicateTestTemplatesTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new RemoveDuplicateTestTemplates()); } @@ -45,7 +45,7 @@ void removeDuplicate() { import org.junit.jupiter.api.Test; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.DisplayName; - + class MyTest { @Test @RepeatedTest(3) @@ -58,7 +58,7 @@ void testMethod() { """ import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.DisplayName; - + class MyTest { @RepeatedTest(3) @DisplayName("When an entry does not exist, it should be created and initialized to 0") @@ -80,7 +80,7 @@ void removeDuplicateOnly() { import org.junit.jupiter.api.Test; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.DisplayName; - + class MyTest { @Test @RepeatedTest(3) @@ -104,7 +104,7 @@ void testMethodC() { import org.junit.jupiter.api.Test; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.DisplayName; - + class MyTest { @RepeatedTest(3) @DisplayName("When an entry does not exist, it should be created and initialized to 0") @@ -136,7 +136,7 @@ void removesWhenOutOfOrder() { import org.junit.jupiter.api.Test; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.DisplayName; - + class MyTest { @DisplayName("When an entry does not exist, it should be created and initialized to 0") @RepeatedTest(3) @@ -149,7 +149,7 @@ void testMethod() { """ import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.DisplayName; - + class MyTest { @DisplayName("When an entry does not exist, it should be created and initialized to 0") @RepeatedTest(3) @@ -169,7 +169,7 @@ void doesNotRemoveWithOnlyTest() { java( """ import org.junit.jupiter.api.Test; - + class MyTest { @Test void testMethod() { @@ -188,7 +188,7 @@ void doesNotRemoveWithOnlyRepeatedTest() { java( """ import org.junit.jupiter.api.RepeatedTest; - + class MyTest { @RepeatedTest(3) void testMethod() { diff --git a/src/test/java/org/openrewrite/java/testing/junit5/RemoveObsoleteRunnersTest.java b/src/test/java/org/openrewrite/java/testing/junit5/RemoveObsoleteRunnersTest.java index db611c4fc..1892e22bb 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/RemoveObsoleteRunnersTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/RemoveObsoleteRunnersTest.java @@ -32,7 +32,7 @@ class RemoveObsoleteRunnersTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipe(new RemoveObsoleteRunners( List.of( "org.junit.runners.JUnit4", @@ -50,7 +50,7 @@ void removesRunWithJunit4() { """ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; - + @RunWith(JUnit4.class) public class Foo { } @@ -71,7 +71,7 @@ void removeRunWithBlockRunner() { """ import org.junit.runner.RunWith; import org.junit.runners.BlockJUnit4ClassRunner; - + @RunWith(BlockJUnit4ClassRunner.class) public class Foo { } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/RemoveTryCatchFailBlocksTest.java b/src/test/java/org/openrewrite/java/testing/junit5/RemoveTryCatchFailBlocksTest.java index 40e522b0b..b5c2c524e 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/RemoveTryCatchFailBlocksTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/RemoveTryCatchFailBlocksTest.java @@ -30,9 +30,7 @@ class RemoveTryCatchFailBlocksTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), - "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new RemoveTryCatchFailBlocks()); } @@ -81,7 +79,7 @@ void removeStaticImportFail() { java( """ import org.junit.jupiter.api.Test; - + import static org.junit.jupiter.api.Assertions.fail; class MyTest { @@ -586,7 +584,7 @@ void failHasBinaryWithGetMessage() { import org.junit.jupiter.api.Test; import java.io.FileOutputStream; import java.io.IOException; - + class MyTest { @Test public void testMethod() { diff --git a/src/test/java/org/openrewrite/java/testing/junit5/RunnerToExtensionTest.java b/src/test/java/org/openrewrite/java/testing/junit5/RunnerToExtensionTest.java index 2f1b81f96..854289cac 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/RunnerToExtensionTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/RunnerToExtensionTest.java @@ -32,7 +32,7 @@ class RunnerToExtensionTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "mockito-all-1.10")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "mockito-all-1.10")) .recipe(new RunnerToExtension( List.of("org.mockito.runners.MockitoJUnitRunner"), "org.mockito.junit.jupiter.MockitoExtension" @@ -49,7 +49,7 @@ void mockito() { """ import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; - + @RunWith(MockitoJUnitRunner.class) public class MyTest { } @@ -57,7 +57,7 @@ public class MyTest { """ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; - + @ExtendWith(MockitoExtension.class) public class MyTest { } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/StaticImportsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/StaticImportsTest.java index 5dd8fe9e6..65b2c47fd 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/StaticImportsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/StaticImportsTest.java @@ -30,7 +30,7 @@ class StaticImportsTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(Environment.builder() .scanRuntimeClasspath("org.openrewrite.java.testing") .build() diff --git a/src/test/java/org/openrewrite/java/testing/junit5/TempDirNonFinalTest.java b/src/test/java/org/openrewrite/java/testing/junit5/TempDirNonFinalTest.java index c39604dc1..6cebd5962 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/TempDirNonFinalTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/TempDirNonFinalTest.java @@ -30,7 +30,7 @@ class TempDirNonFinalTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new TempDirNonFinal()); } @@ -42,9 +42,9 @@ void tempDirStaticFinalFile() { java( """ import org.junit.jupiter.api.io.TempDir; - + import java.io.File; - + class MyTest { @TempDir static final File tempDir; @@ -52,9 +52,9 @@ class MyTest { """, """ import org.junit.jupiter.api.io.TempDir; - + import java.io.File; - + class MyTest { @TempDir static File tempDir; @@ -72,9 +72,9 @@ void tempDirStaticFinalPath() { java( """ import org.junit.jupiter.api.io.TempDir; - + import java.nio.file.Path; - + class MyTest { @TempDir static final Path tempDir; @@ -82,9 +82,9 @@ class MyTest { """, """ import org.junit.jupiter.api.io.TempDir; - + import java.nio.file.Path; - + class MyTest { @TempDir static Path tempDir; @@ -104,9 +104,9 @@ void tempDirFileParameter() { import java.io.File; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - + import java.nio.file.Path; - + class MyTest { @Test void fileTest(@TempDir final File tempDir) { @@ -125,9 +125,9 @@ void tempDirStaticFile() { java( """ import org.junit.jupiter.api.io.TempDir; - + import java.io.File; - + class MyTest { @TempDir static File tempDir; @@ -145,9 +145,9 @@ void tempDirStaticPath() { java( """ import org.junit.jupiter.api.io.TempDir; - + import java.nio.file.Path; - + class MyTest { @TempDir static Path tempDir; diff --git a/src/test/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDirTest.java b/src/test/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDirTest.java index b9f0ed155..c2fe7ec55 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDirTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDirTest.java @@ -35,9 +35,9 @@ class TemporaryFolderToTempDirTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .parser(GroovyParser.builder() - .classpathFromResource(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResource(new InMemoryExecutionContext(), "junit-4")) .recipe(new TemporaryFolderToTempDir()); } @@ -50,11 +50,11 @@ void spockTest() { """ import org.junit.Rule import org.junit.rules.TemporaryFolder - + class AbstractIntegrationTest { @Rule TemporaryFolder temporaryFolder = new TemporaryFolder() - + def setup() { projectDir = temporaryFolder.root buildFile = temporaryFolder.newFile('build.gradle') @@ -65,11 +65,11 @@ def setup() { """ import org.junit.Rule import org.junit.rules.TemporaryFolder - + class AbstractIntegrationTest { @TempDir File temporaryFolder - + def setup() { projectDir = temporaryFolder.root buildFile = File.createTempFile('build.gradle', null, temporaryFolder) @@ -104,7 +104,7 @@ public void tearDown() { """, """ import org.junit.jupiter.api.io.TempDir; - + import java.io.File; public class MyTest { @@ -129,9 +129,9 @@ void temporaryFolderInstantiatedWithParentFolder() { """ import org.junit.Rule; import org.junit.rules.TemporaryFolder; - + import java.io.File; - + class MyTest { File parentDir = new File("foo"); @Rule @@ -140,9 +140,9 @@ class MyTest { """, """ import org.junit.jupiter.api.io.TempDir; - + import java.io.File; - + class MyTest { File parentDir = new File("foo"); @TempDir @@ -161,20 +161,20 @@ void basicReplace() { """ import org.junit.ClassRule; import org.junit.rules.TemporaryFolder; - + class MyTest { - + @ClassRule public static TemporaryFolder tempDir = new TemporaryFolder(); } """, """ import org.junit.jupiter.api.io.TempDir; - + import java.io.File; - + class MyTest { - + @TempDir public static File tempDir; } @@ -191,20 +191,20 @@ void multiVarReplace() { """ import org.junit.ClassRule; import org.junit.rules.TemporaryFolder; - + class MyTest { - + @ClassRule static TemporaryFolder tempDir1 = new TemporaryFolder(), tempDir2 = new TemporaryFolder(); } """, """ import org.junit.jupiter.api.io.TempDir; - + import java.io.File; - + class MyTest { - + @TempDir static File tempDir1, tempDir2; } @@ -221,7 +221,7 @@ void getRoot() { """ import org.junit.Rule; import org.junit.rules.TemporaryFolder; - + import java.io.File; class MyTest { @@ -236,7 +236,7 @@ void foo() { """, """ import org.junit.jupiter.api.io.TempDir; - + import java.io.File; class MyTest { @@ -261,12 +261,12 @@ void newFolder() { """ import org.junit.Rule; import org.junit.rules.TemporaryFolder; - + import java.io.File; import java.io.IOException; - + class MyTest { - + @Rule TemporaryFolder tempDir1 = new TemporaryFolder(); @@ -280,16 +280,16 @@ void foo() throws IOException { import java.io.File; import java.io.IOException; - + class MyTest { - + @TempDir File tempDir1; - + void foo() throws IOException { File file1 = newFolder(tempDir1, "junit"); } - + private static File newFolder(File root, String... subDirs) throws IOException { String subFolder = String.join("/", subDirs); File result = new File(root, subFolder); @@ -313,7 +313,7 @@ void newFolderWithArgs() { import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.Rule; - + import java.io.File; import java.io.IOException; @@ -384,18 +384,18 @@ void newFolderWithParams() { import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; - + import java.io.File; import java.io.IOException; - + class MyTest { - + @Rule TemporaryFolder tempDir1 = new TemporaryFolder(); String s1 = "foo"; String s2 = "bar"; String s3 = "baz"; - + @Test public void someTest() { File subDir = tempDir1.newFolder("sub"); @@ -406,24 +406,24 @@ public void someTest() { """ import org.junit.Test; import org.junit.jupiter.api.io.TempDir; - + import java.io.File; import java.io.IOException; - + class MyTest { - + @TempDir File tempDir1; String s1 = "foo"; String s2 = "bar"; String s3 = "baz"; - + @Test public void someTest() { File subDir = newFolder(tempDir1, "sub"); File subDirs = newFolder(tempDir1, s1, s2, s3); } - + private static File newFolder(File root, String... subDirs) throws IOException { String subFolder = String.join("/", subDirs); File result = new File(root, subFolder); @@ -446,14 +446,14 @@ void usingMethodRule() { """ import org.junit.Rule;import org.junit.Test; import org.junit.rules.TemporaryFolder; - + import java.io.File; import java.io.IOException; - + public class MyTest { @Rule TemporaryFolder tempFolder = new TemporaryFolder(); - + @Test public void newNamedFileIsCreatedUnderRootFolder() throws IOException { final String fileName = "SampleFile.txt"; @@ -465,14 +465,14 @@ public void newNamedFileIsCreatedUnderRootFolder() throws IOException { """ import org.junit.Test; import org.junit.jupiter.api.io.TempDir; - + import java.io.File; import java.io.IOException; - + public class MyTest { @TempDir File tempFolder; - + @Test public void newNamedFileIsCreatedUnderRootFolder() throws IOException { final String fileName = "SampleFile.txt"; @@ -494,7 +494,7 @@ void multipleTemporaryFoldersInMethodBody() { import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; - + import java.io.File; import java.io.IOException; public class MyTest { @@ -517,7 +517,7 @@ public void newNamedFileIsCreatedUnderRootFolder() throws IOException { """ import org.junit.Test; import org.junit.jupiter.api.io.TempDir; - + import java.io.File; import java.io.IOException; @@ -562,7 +562,7 @@ public static void init() { """, """ import org.junit.jupiter.api.io.TempDir; - + import java.io.File; public class MyTest { @@ -590,7 +590,7 @@ void why() { doSomething(new TemporaryFolder()); } void doSomething(TemporaryFolder tempFolder) { - + } } """ @@ -611,7 +611,7 @@ void why() { doSomething(t); } void doSomething(TemporaryFolder tempFolder) { - + } } """ @@ -637,7 +637,7 @@ public class TempDirTest { @Rule public TemporaryFolder folder = new TemporaryFolder(); - + @Test public void testPath() throws IOException { Path newFolder = folder.newFolder().toPath(); @@ -655,7 +655,7 @@ public class TempDirTest { @TempDir public File folder; - + @Test public void testPath() throws IOException { Path newFolder = newFolder(folder, "junit").toPath(); diff --git a/src/test/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfoTest.java b/src/test/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfoTest.java index 7d5c453aa..8744ebca0 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfoTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfoTest.java @@ -31,7 +31,7 @@ class TestRuleToTestInfoTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipe(new TestRuleToTestInfo()); } @@ -59,7 +59,7 @@ private static class SomeInnerClass { """ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; - + import java.lang.reflect.Method; import java.util.Optional; @@ -116,7 +116,7 @@ private static class SomeInnerClass { """ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; - + import java.lang.reflect.Method; import java.util.Optional; diff --git a/src/test/java/org/openrewrite/java/testing/junit5/UpdateBeforeAfterAnnotationsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/UpdateBeforeAfterAnnotationsTest.java index 8077bcafe..a4b763544 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/UpdateBeforeAfterAnnotationsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/UpdateBeforeAfterAnnotationsTest.java @@ -35,9 +35,9 @@ class UpdateBeforeAfterAnnotationsTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .parser(KotlinParser.builder() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipe(new UpdateBeforeAfterAnnotations()); } @@ -99,9 +99,9 @@ void afterToAfterEach() { java( """ import org.junit.After; - + class Test { - + @After void after() { } @@ -109,9 +109,9 @@ void after() { """, """ import org.junit.jupiter.api.AfterEach; - + class Test { - + @AfterEach void after() { } @@ -128,9 +128,9 @@ void beforeClassToBeforeAll() { java( """ import org.junit.BeforeClass; - + class Test { - + @BeforeClass void beforeClass() { } @@ -138,9 +138,9 @@ void beforeClass() { """, """ import org.junit.jupiter.api.BeforeAll; - + class Test { - + @BeforeAll void beforeClass() { } @@ -157,7 +157,7 @@ void afterClassToAfterAll() { java( """ import org.junit.AfterClass; - + class Test { @AfterClass void afterClass() { @@ -166,7 +166,7 @@ void afterClass() { """, """ import org.junit.jupiter.api.AfterAll; - + class Test { @AfterAll void afterClass() { @@ -186,9 +186,9 @@ void convertsToPackageVisibility() { java( """ import org.junit.Before; - + class Test { - + @Before // comments public void before() { } @@ -196,9 +196,9 @@ public void before() { """, """ import org.junit.jupiter.api.BeforeEach; - + class Test { - + // comments @BeforeEach void before() { @@ -225,9 +225,9 @@ public class AbstractTest { java( """ import org.junit.Before; - + public class A extends AbstractTest { - + @Before public void setup() { } @@ -235,9 +235,9 @@ public void setup() { """, """ import org.junit.jupiter.api.BeforeEach; - + public class A extends AbstractTest { - + @BeforeEach public void setup() { } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/UpdateMockWebServerTest.java b/src/test/java/org/openrewrite/java/testing/junit5/UpdateMockWebServerTest.java index b47074ef7..385f2bad7 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/UpdateMockWebServerTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/UpdateMockWebServerTest.java @@ -32,7 +32,7 @@ public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() .logCompilationWarningsAndErrors(true) - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "junit-jupiter-api-5.9", "mockwebserver-3.14")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "junit-jupiter-api-5", "mockwebserver-3.14")) .recipe(new UpdateMockWebServer()); } @@ -53,12 +53,12 @@ class MyTest { """ import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.AfterEach; - + import java.io.IOException; - + class MyTest { public MockWebServer server = new MockWebServer(); - + @AfterEach void afterEachTest() throws IOException { server.close(); @@ -78,11 +78,11 @@ void mockWebServerRuleUpdatedExistingAfterEachStatement() { import okhttp3.mockwebserver.MockWebServer; import org.junit.Rule; import org.junit.jupiter.api.AfterEach; - + class MyTest { @Rule public MockWebServer server = new MockWebServer(); - + @AfterEach void afterEachTest() { } } @@ -90,12 +90,12 @@ void afterEachTest() { } """ import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.AfterEach; - + import java.io.IOException; - + class MyTest { public MockWebServer server = new MockWebServer(); - + @AfterEach void afterEachTest() throws IOException { server.close(); diff --git a/src/test/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotationTest.java b/src/test/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotationTest.java index 586b9f4c5..3c1b2969d 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotationTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotationTest.java @@ -31,7 +31,7 @@ class UpdateTestAnnotationTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipe(new UpdateTestAnnotation()); } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/UseAssertSameTest.java b/src/test/java/org/openrewrite/java/testing/junit5/UseAssertSameTest.java index 1623389f6..80d7ea11f 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/UseAssertSameTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/UseAssertSameTest.java @@ -29,7 +29,7 @@ class UseAssertSameTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api-5")) .recipe(new UseAssertSame()); } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/UseHamcrestAssertThatTest.java b/src/test/java/org/openrewrite/java/testing/junit5/UseHamcrestAssertThatTest.java index 7d6adfde4..8f8906365 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/UseHamcrestAssertThatTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/UseHamcrestAssertThatTest.java @@ -31,7 +31,7 @@ class UseHamcrestAssertThatTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "mockito-all-1.10", "hamcrest-2.2")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "mockito-all-1.10", "hamcrest-3")) .recipe(Environment.builder() .scanRuntimeClasspath("org.openrewrite.java.testing.junit5") .build() @@ -47,7 +47,7 @@ void assertAssertThatToHamcrestMatcherAssert() { """ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; - + class Test { void test() { assertThat(1 + 1, is(2)); @@ -57,7 +57,7 @@ void test() { """ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; - + class Test { void test() { assertThat(1 + 1, is(2)); diff --git a/src/test/java/org/openrewrite/java/testing/junit5/UseTestMethodOrderTest.java b/src/test/java/org/openrewrite/java/testing/junit5/UseTestMethodOrderTest.java index 48419d9ad..629fac62f 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/UseTestMethodOrderTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/UseTestMethodOrderTest.java @@ -30,7 +30,7 @@ class UseTestMethodOrderTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4")) .recipe(new UseTestMethodOrder()); } @@ -43,7 +43,7 @@ void nameAscending() { """ import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; - + @FixMethodOrder(MethodSorters.NAME_ASCENDING) class Test { } @@ -51,7 +51,7 @@ class Test { """ import org.junit.jupiter.api.MethodOrderer.MethodName; import org.junit.jupiter.api.TestMethodOrder; - + @TestMethodOrder(MethodName.class) class Test { } @@ -69,11 +69,11 @@ void defaultAndOmitted() { """ import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; - + @FixMethodOrder(MethodSorters.DEFAULT) class Test { } - + @FixMethodOrder class Test2 { } @@ -81,11 +81,11 @@ class Test2 { """ import org.junit.jupiter.api.MethodOrderer.MethodName; import org.junit.jupiter.api.TestMethodOrder; - + @TestMethodOrder(MethodName.class) class Test { } - + @TestMethodOrder(MethodName.class) class Test2 { } @@ -103,7 +103,7 @@ void jvmOrder() { """ import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; - + @FixMethodOrder(MethodSorters.JVM) class Test { } @@ -111,7 +111,7 @@ class Test { """ import org.junit.jupiter.api.MethodOrderer.MethodName; import org.junit.jupiter.api.TestMethodOrder; - + @TestMethodOrder(MethodName.class) class Test { } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/UseWiremockExtensionTest.java b/src/test/java/org/openrewrite/java/testing/junit5/UseWiremockExtensionTest.java index be67ab4d1..34053ea79 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/UseWiremockExtensionTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/UseWiremockExtensionTest.java @@ -33,7 +33,7 @@ class UseWiremockExtensionTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "wiremock-jre8-2.35")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "wiremock-jre8-2.35")) .recipe(new UseWiremockExtension()); } @@ -46,9 +46,9 @@ void optionsArg() { """ import com.github.tomakehurst.wiremock.junit.WireMockRule; import org.junit.Rule; - + import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; - + class Test { @Rule public WireMockRule wm = new WireMockRule(options().dynamicHttpsPort()); @@ -57,9 +57,9 @@ class Test { """ import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import org.junit.jupiter.api.extension.RegisterExtension; - + import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; - + class Test { @RegisterExtension public WireMockExtension wm = WireMockExtension.newInstance().options(options().dynamicHttpsPort()).build(); @@ -77,9 +77,9 @@ void failOnUnmatchedRequests() { """ import com.github.tomakehurst.wiremock.junit.WireMockRule; import org.junit.Rule; - + import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; - + class Test { @Rule public WireMockRule wm = new WireMockRule(options().dynamicHttpsPort(), false); @@ -88,9 +88,9 @@ class Test { """ import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import org.junit.jupiter.api.extension.RegisterExtension; - + import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; - + class Test { @RegisterExtension public WireMockExtension wm = WireMockExtension.newInstance().options(options().dynamicHttpsPort()).failOnUnmatchedRequests(false).build(); @@ -108,7 +108,7 @@ void port() { """ import com.github.tomakehurst.wiremock.junit.WireMockRule; import org.junit.Rule; - + class Test { @Rule public WireMockRule wm = new WireMockRule(7001); @@ -118,7 +118,7 @@ class Test { import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import org.junit.jupiter.api.extension.RegisterExtension; - + class Test { @RegisterExtension public WireMockExtension wm = WireMockExtension.newInstance().options(WireMockConfiguration.options().port(7001)).build(); @@ -136,7 +136,7 @@ void portAndHttpsPort() { """ import com.github.tomakehurst.wiremock.junit.WireMockRule; import org.junit.Rule; - + class Test { @Rule public WireMockRule wm = new WireMockRule(7001, 7002); @@ -146,7 +146,7 @@ class Test { import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import org.junit.jupiter.api.extension.RegisterExtension; - + class Test { @RegisterExtension public WireMockExtension wm = WireMockExtension.newInstance().options(WireMockConfiguration.options().port(7001).httpsPort(7002)).build(); diff --git a/src/test/java/org/openrewrite/java/testing/mockito/JunitMockitoUpgradeIntegrationTest.java b/src/test/java/org/openrewrite/java/testing/mockito/JunitMockitoUpgradeIntegrationTest.java index a4f60917a..69b0b793a 100755 --- a/src/test/java/org/openrewrite/java/testing/mockito/JunitMockitoUpgradeIntegrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/JunitMockitoUpgradeIntegrationTest.java @@ -36,7 +36,7 @@ class JunitMockitoUpgradeIntegrationTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "mockito-all-1.10", "junit-4.13", "hamcrest-2.2", "junit-jupiter-api-5.9")) + .classpathFromResources(new InMemoryExecutionContext(), "mockito-all-1.10", "junit-4", "hamcrest-3", "junit-jupiter-api-5")) .recipe(Environment.builder() .scanRuntimeClasspath("org.openrewrite.java.testing.junit5") .build() @@ -55,31 +55,31 @@ void replaceMockAnnotation() { java( """ package org.openrewrite.java.testing.junit5; - + import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; - + import java.util.List; - + import static org.mockito.Mockito.verify; - + public class MockitoTests { @Mock List mockedList; - + @Before public void initMocks() { MockitoAnnotations.initMocks(this); } - + @Test public void usingAnnotationBasedMock() { - + mockedList.add("one"); mockedList.clear(); - + verify(mockedList).add("one"); verify(mockedList).clear(); } @@ -87,31 +87,31 @@ public void usingAnnotationBasedMock() { """, """ package org.openrewrite.java.testing.junit5; - + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; - + import java.util.List; - + import static org.mockito.Mockito.verify; - + public class MockitoTests { @Mock List mockedList; - + @BeforeEach public void initMocks() { MockitoAnnotations.initMocks(this); } - + @Test public void usingAnnotationBasedMock() { - + mockedList.add("one"); mockedList.clear(); - + verify(mockedList).add("one"); verify(mockedList).clear(); } @@ -136,7 +136,7 @@ void replacesAnyVararg() { import static org.mockito.Matchers.anyVararg; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - + public class MockitoVarargMatcherTest { public static class Foo { public boolean acceptsVarargs(String ... strings) { return true; } @@ -153,7 +153,7 @@ public void usesVarargMatcher() { import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - + public class MockitoVarargMatcherTest { public static class Foo { public boolean acceptsVarargs(String ... strings) { return true; } @@ -182,11 +182,11 @@ void replacesGetArgumentAt() { package mockito.example; import org.junit.jupiter.api.Test; - + import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - + public class MockitoDoAnswer { @Test public void aTest() { @@ -199,11 +199,11 @@ public void aTest() { package mockito.example; import org.junit.jupiter.api.Test; - + import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - + public class MockitoDoAnswer { @Test public void aTest() { @@ -224,7 +224,7 @@ void removesRunWithJunit4() { """ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; - + @RunWith(JUnit4.class) public class Foo { } diff --git a/src/test/java/org/openrewrite/java/testing/mockito/MockitoJUnitToMockitoExtensionTest.java b/src/test/java/org/openrewrite/java/testing/mockito/MockitoJUnitToMockitoExtensionTest.java index 6075ac4df..1f8becff6 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/MockitoJUnitToMockitoExtensionTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/MockitoJUnitToMockitoExtensionTest.java @@ -32,7 +32,7 @@ public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() .classpathFromResources(new InMemoryExecutionContext(), - "mockito-core-3.12", "mockito-junit-jupiter-3.12", "junit-4.13", "hamcrest-2.2", "junit-jupiter-api-5.9")) + "mockito-core-3.12", "mockito-junit-jupiter-3.12", "junit-4", "hamcrest-3", "junit-jupiter-api-5")) .recipe(new MockitoJUnitToMockitoExtension()); } @@ -48,12 +48,12 @@ void leavesOtherRulesAlone() { import org.mockito.Mock; import org.mockito.junit.MockitoRule; import org.mockito.junit.MockitoJUnit; - + class MyTest { - + @Rule TemporaryFolder tempDir = new TemporaryFolder(); - + @Rule MockitoRule mockitoRule = MockitoJUnit.rule(); } @@ -66,11 +66,11 @@ class MyTest { import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; - + @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.WARN) class MyTest { - + @Rule TemporaryFolder tempDir = new TemporaryFolder(); } @@ -92,10 +92,10 @@ void leavesOtherAnnotationsAlone() { import org.mockito.Mock; import org.mockito.junit.MockitoRule; import org.mockito.junit.MockitoJUnit; - + @FixMethodOrder(MethodSorters.NAME_ASCENDING) class MyTest { - + @Rule MockitoRule mockitoRule = MockitoJUnit.rule(); } @@ -108,7 +108,7 @@ class MyTest { import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; - + @ExtendWith(MockitoExtension.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @MockitoSettings(strictness = Strictness.WARN) @@ -127,21 +127,21 @@ void refactorMockitoRule() { java( """ import java.util.List; - + import org.junit.Rule; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; - + class MyTest { - + @Rule MockitoRule mockitoRule = MockitoJUnit.rule(); - + @Mock private List list; - + public void exampleTest() { mockitoRule.strictness(Strictness.LENIENT); list.add(100); @@ -150,20 +150,20 @@ public void exampleTest() { """, """ import java.util.List; - + import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; - + @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) class MyTest { - + @Mock private List list; - + public void exampleTest() { list.add(100); } @@ -181,21 +181,21 @@ void refactorMockitoTestRule() { java( """ import java.util.List; - + import org.junit.Rule; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoTestRule; import org.mockito.quality.Strictness; - + class MyTest { - + @Rule MockitoTestRule mockitoTestRule = MockitoJUnit.rule(); - + @Mock private List list; - + public void exampleTest() { mockitoTestRule.strictness(Strictness.LENIENT); list.add(100); @@ -204,20 +204,20 @@ public void exampleTest() { """, """ import java.util.List; - + import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; - + @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) class MyTest { - + @Mock private List list; - + public void exampleTest() { list.add(100); } @@ -241,22 +241,22 @@ void onlyRefactorMockitoRule() { import org.mockito.junit.MockitoTestRule; import org.mockito.junit.VerificationCollector; import org.mockito.quality.Strictness; - + import java.util.List; - + import static org.mockito.Mockito.verify; - + class MyTest { - + @Rule VerificationCollector verificationCollectorRule = MockitoJUnit.collector(); - + @Rule MockitoTestRule mockitoTestRule = MockitoJUnit.rule(); - + @Mock private List list; - + @Test public void exampleTest() { verify(list).add(100); @@ -274,21 +274,21 @@ public void exampleTest() { import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; - + import java.util.List; - + import static org.mockito.Mockito.verify; - + @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.WARN) class MyTest { - + @Rule VerificationCollector verificationCollectorRule = MockitoJUnit.collector(); - + @Mock private List list; - + @Test public void exampleTest() { verify(list).add(100); @@ -308,20 +308,20 @@ void unchangedMockitoCollectorRule() { java( """ import java.util.List; - + import org.junit.Rule; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.VerificationCollector; - + class MyTest { - + @Rule VerificationCollector verificationCollectorRule = MockitoJUnit.collector(); - + @Mock private List list; - + public void exampleTest() { list.add(100); verificationCollectorRule.collectAndReport(); @@ -340,25 +340,25 @@ void unchangedMockitoCollectorDeclaredInMethod() { java( """ import java.util.List; - + import org.mockito.Mock; import org.mockito.exceptions.base.MockitoAssertionError; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.VerificationCollector; - + import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; - + class MyTest { - + public void unsupported() { VerificationCollector collector = MockitoJUnit.collector().assertLazily(); - + List mockList = mock(List.class); verify(mockList).add("one"); verify(mockList).clear(); - + try { collector.collectAndReport(); } catch (MockitoAssertionError error) { @@ -389,20 +389,20 @@ void leaveMockitoJUnitRunnerAlone() { import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoTestRule; import org.mockito.runners.MockitoJUnitRunner; - + import java.util.List; - + import static org.mockito.Mockito.verify; - + @RunWith(MockitoJUnitRunner.class) class MyTest { - + @Rule MockitoTestRule mockitoTestRule = MockitoJUnit.rule(); - + @Mock private List list; - + @Test public void exampleTest() { verify(list).add(100); @@ -414,17 +414,17 @@ public void exampleTest() { import org.junit.Test; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; - + import java.util.List; - + import static org.mockito.Mockito.verify; - + @RunWith(MockitoJUnitRunner.class) class MyTest { - + @Mock private List list; - + @Test public void exampleTest() { verify(list).add(100); @@ -449,20 +449,20 @@ void leaveExtendWithAlone() { import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoTestRule; - + import java.util.List; - + import static org.mockito.Mockito.verify; - + @ExtendWith(MockitoExtension.class) class MyTest { - + @Rule MockitoTestRule mockitoTestRule = MockitoJUnit.rule(); - + @Mock private List list; - + @Test public void exampleTest() { verify(list).add(100); @@ -474,17 +474,17 @@ public void exampleTest() { import org.junit.Test; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; - + import java.util.List; - + import static org.mockito.Mockito.verify; - + @ExtendWith(MockitoExtension.class) class MyTest { - + @Mock private List list; - + @Test public void exampleTest() { verify(list).add(100); @@ -507,19 +507,19 @@ void silentRuleAddMockitoSettings() { import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; - + import java.util.List; - + import static org.mockito.Mockito.when; - + public class MyTest { - + @Rule public MockitoRule rule = MockitoJUnit.rule().silent(); - + @Mock private List mockList; - + @Test public void testing() { when(mockList.add("one")).thenReturn(true); // this won't get called @@ -534,18 +534,18 @@ public void testing() { import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; - + import java.util.List; - + import static org.mockito.Mockito.when; - + @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) public class MyTest { - + @Mock private List mockList; - + @Test public void testing() { when(mockList.add("one")).thenReturn(true); // this won't get called @@ -570,19 +570,19 @@ void warnStrictnessRuleAddMockitoSettings() { import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; - + import java.util.List; - + import static org.mockito.Mockito.when; - + public class MyTest { - + @Rule public MockitoRule rule = MockitoJUnit.rule().strictness(Strictness.WARN); - + @Mock private List mockList; - + @Test public void testing() { when(mockList.add("one")).thenReturn(true); // this won't get called @@ -597,18 +597,18 @@ public void testing() { import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; - + import java.util.List; - + import static org.mockito.Mockito.when; - + @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.WARN) public class MyTest { - + @Mock private List mockList; - + @Test public void testing() { when(mockList.add("one")).thenReturn(true); // this won't get called @@ -632,20 +632,20 @@ void warnStrictnessRuleAddMockitoSettingsWithStaticImport() { import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; - + import java.util.List; - + import static org.mockito.Mockito.when; import static org.mockito.quality.Strictness.WARN; - + public class MyTest { - + @Rule public MockitoRule rule = MockitoJUnit.rule().strictness(WARN); - + @Mock private List mockList; - + @Test public void testing() { when(mockList.add("one")).thenReturn(true); // this won't get called @@ -660,18 +660,19 @@ public void testing() { import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; - + import java.util.List; - + import static org.mockito.Mockito.when; - + import static org.mockito.quality.Strictness.WARN; + @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.WARN) public class MyTest { - + @Mock private List mockList; - + @Test public void testing() { when(mockList.add("one")).thenReturn(true); // this won't get called @@ -696,19 +697,19 @@ void lenientStrictnessRuleAddMockitoSettings() { import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; - + import java.util.List; - + import static org.mockito.Mockito.when; - + public class MyTest { - + @Rule public MockitoRule rule = MockitoJUnit.rule().strictness(Strictness.LENIENT); - + @Mock private List mockList; - + @Test public void testing() { when(mockList.add("one")).thenReturn(true); // this won't get called @@ -723,18 +724,18 @@ public void testing() { import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; - + import java.util.List; - + import static org.mockito.Mockito.when; - + @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) public class MyTest { - + @Mock private List mockList; - + @Test public void testing() { when(mockList.add("one")).thenReturn(true); // this won't get called @@ -759,19 +760,19 @@ void strictRuleDoNotAddMockitoSettings() { import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.mockito.quality.Strictness; - + import java.util.List; - + import static org.mockito.Mockito.when; - + public class MyTest { - + @Rule public MockitoRule rule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS); - + @Mock private List mockList; - + @Test public void testing() { when(mockList.add("one")).thenReturn(true); // this won't get called @@ -784,17 +785,17 @@ public void testing() { import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; - + import java.util.List; - + import static org.mockito.Mockito.when; - + @ExtendWith(MockitoExtension.class) public class MyTest { - + @Mock private List mockList; - + @Test public void testing() { when(mockList.add("one")).thenReturn(true); // this won't get called diff --git a/src/test/java/org/openrewrite/java/testing/mockito/MockitoJunitRunnerSilentToExtensionTest.java b/src/test/java/org/openrewrite/java/testing/mockito/MockitoJunitRunnerSilentToExtensionTest.java index 9402e6f46..568f4469b 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/MockitoJunitRunnerSilentToExtensionTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/MockitoJunitRunnerSilentToExtensionTest.java @@ -30,7 +30,7 @@ class MockitoJunitRunnerSilentToExtensionTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .parser(JavaParser.fromJavaVersion() - .classpathFromResources(new InMemoryExecutionContext(), "junit-4.13", "mockito-core-3.12")) + .classpathFromResources(new InMemoryExecutionContext(), "junit-4", "mockito-core-3.12")) .recipe(new MockitoJUnitRunnerSilentToExtension()); } @@ -43,7 +43,7 @@ void migrateMockitoRunnerSilentToExtension() { """ import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; - + @RunWith(MockitoJUnitRunner.Silent.class) public class ExternalAPIServiceTest { } @@ -53,7 +53,7 @@ public class ExternalAPIServiceTest { import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; - + @MockitoSettings(strictness = Strictness.LENIENT) @ExtendWith(MockitoExtension.class) public class ExternalAPIServiceTest { diff --git a/src/test/java/org/openrewrite/java/testing/mockito/MockitoWhenOnStaticToMockStaticTest.java b/src/test/java/org/openrewrite/java/testing/mockito/MockitoWhenOnStaticToMockStaticTest.java index 6229c636a..5aac8345d 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/MockitoWhenOnStaticToMockStaticTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/MockitoWhenOnStaticToMockStaticTest.java @@ -33,7 +33,7 @@ public void defaults(RecipeSpec spec) { spec.recipe(new MockitoWhenOnStaticToMockStatic()) .parser(JavaParser.fromJavaVersion() .classpathFromResources(new InMemoryExecutionContext(), - "junit-4.13", + "junit-4", "mockito-core-3.12", "mockito-junit-jupiter-3.12" )); diff --git a/src/test/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockitoTest.java index 78198073e..cd6c5759b 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockitoTest.java @@ -35,12 +35,12 @@ public void defaults(RecipeSpec spec) { .logCompilationWarningsAndErrors(true) .classpathFromResources(new InMemoryExecutionContext(), "apiguardian-api-1.1", - "junit-4.13", - "junit-jupiter-api-5.9", + "junit-4", + "junit-jupiter-api-5", "mockito-core-3.12", - "powermock-api-mockito-1.6", - "powermock-core-1.6", - "testng-7.7" + "powermock-api-mockito-1", + "powermock-core-1", + "testng-7" )) .recipe(new PowerMockitoMockStaticToMockito()) .typeValidationOptions(TypeValidation.builder().cursorAcyclic(false).build()); @@ -54,15 +54,15 @@ void prepareForTestAnnotationIsReplacedBySingleField() { java( """ import static org.mockito.Mockito.mockStatic; - + import java.util.Calendar; - + import org.junit.jupiter.api.Test; import org.powermock.core.classloader.annotations.PrepareForTest; - + @PrepareForTest({Calendar.class}) public class MyTest { - + @Test void testStaticMethod() { mockStatic(Calendar.class); @@ -71,28 +71,28 @@ void testStaticMethod() { """, """ import static org.mockito.Mockito.mockStatic; - + import java.util.Calendar; - + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; - + public class MyTest { - + private MockedStatic mockedCalendar; - + @BeforeEach void setUpStaticMocks() { mockedCalendar = mockStatic(Calendar.class); } - + @AfterEach void tearDownStaticMocks() { mockedCalendar.closeOnDemand(); } - + @Test void testStaticMethod() { } @@ -109,16 +109,16 @@ void prepareForTestAnnotationIsReplacedByFields() { java( """ import static org.mockito.Mockito.mockStatic; - + import java.util.Calendar; import java.util.Currency; - + import org.junit.jupiter.api.Test; import org.powermock.core.classloader.annotations.PrepareForTest; - + @PrepareForTest({Calendar.class, Currency.class}) class MyTest { - + @Test void testStaticMethod() { mockStatic(Calendar.class); @@ -128,33 +128,33 @@ void testStaticMethod() { """, """ import static org.mockito.Mockito.mockStatic; - + import java.util.Calendar; import java.util.Currency; - + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; - + class MyTest { - + private MockedStatic mockedCurrency; - + private MockedStatic mockedCalendar; - + @BeforeEach void setUpStaticMocks() { mockedCurrency = mockStatic(Currency.class); mockedCalendar = mockStatic(Calendar.class); } - + @AfterEach void tearDownStaticMocks() { mockedCalendar.closeOnDemand(); mockedCurrency.closeOnDemand(); } - + @Test void testStaticMethod() { } @@ -171,15 +171,15 @@ void tearDownMethodHasCorrectPositionIfNoTestMethodIsPresent() { java( """ import static org.mockito.Mockito.mockStatic; - + import java.util.Calendar; - + import org.junit.jupiter.api.BeforeEach; import org.powermock.core.classloader.annotations.PrepareForTest; - + @PrepareForTest({Calendar.class}) class MyTest { - + @BeforeEach void testStaticMethod() { mockStatic(Calendar.class); @@ -188,22 +188,22 @@ void testStaticMethod() { """, """ import static org.mockito.Mockito.mockStatic; - + import java.util.Calendar; - + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.mockito.MockedStatic; - + class MyTest { - + private MockedStatic mockedCalendar; - + @BeforeEach void testStaticMethod() { mockedCalendar = mockStatic(Calendar.class); } - + @AfterEach void tearDownStaticMocks() { mockedCalendar.closeOnDemand(); @@ -221,38 +221,38 @@ void tearDownMethodOfTestNGHasAnnotationWithArgument() { java( """ import java.util.Calendar; - + import org.testng.annotations.Test; import org.powermock.core.classloader.annotations.PrepareForTest; - + @PrepareForTest({Calendar.class}) public class MyTest { - + @Test void testSomething() { } - + } """, """ import java.util.Calendar; - + import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + public class MyTest { - + @BeforeMethod void setUpStaticMocks() { } - + @AfterMethod(alwaysRun = true) void tearDownStaticMocks() { } - + @Test void testSomething() { } - + } """ ) @@ -266,41 +266,41 @@ void tearDownMethodOfTestNGWithAnnotationRemainsUntouched() { java( """ import java.util.Calendar; - + import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import org.powermock.core.classloader.annotations.PrepareForTest; - + @PrepareForTest({Calendar.class}) public class MyTest { - + @AfterMethod(groups = "irrelevant") void tearDown() {} - + @Test void testSomething() { } - + } """, """ import java.util.Calendar; - + import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + public class MyTest { - + @AfterMethod(groups = "irrelevant") void tearDown() {} - + @BeforeMethod void setUpStaticMocks() { } - + @Test void testSomething() { } - + } """ ) @@ -314,22 +314,22 @@ void tearDownMethodOfTestNGHasAnnotationWithSameArgumentsAsTheTestThatCallsMockS java( """ import java.util.Calendar; - + import static org.mockito.Mockito.*; - + import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.powermock.core.classloader.annotations.PrepareForTest; - + @PrepareForTest({Calendar.class}) public class MyTest { - + private Calendar calendarMock; - + @Test(groups = "irrelevant") void testSomethingIrrelevantForCheckin() { } - + @Test(groups = "checkin") void testStaticMethod() { calendarMock = mock(Calendar.class); @@ -340,33 +340,33 @@ void testStaticMethod() { """, """ import java.util.Calendar; - + import static org.mockito.Mockito.*; - + import org.mockito.MockedStatic; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + public class MyTest { - + private MockedStatic mockedCalendar; - + private Calendar calendarMock; - + @BeforeMethod(groups = "checkin") void setUpStaticMocks() { mockedCalendar = mockStatic(Calendar.class); } - + @AfterMethod(groups = "checkin") void tearDownStaticMocks() { mockedCalendar.closeOnDemand(); } - + @Test(groups = "irrelevant") void testSomethingIrrelevantForCheckin() { } - + @Test(groups = "checkin") void testStaticMethod() { calendarMock = mock(Calendar.class); @@ -385,19 +385,19 @@ void argumentOfWhenOnStaticMethodWithParametersIsReplacedByLambda() { java( """ import static org.mockito.Mockito.*; - + import java.util.Calendar; import java.util.Locale; - + import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; - + public class MyTest { - + private MockedStatic mockedCalendar; - + private Calendar calendarMock = mock(Calendar.class); - + @Test void testStaticMethod() { when(Calendar.getInstance(Locale.ENGLISH)).thenReturn(calendarMock); @@ -406,19 +406,19 @@ void testStaticMethod() { """, """ import static org.mockito.Mockito.*; - + import java.util.Calendar; import java.util.Locale; - + import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; - + public class MyTest { - + private MockedStatic mockedCalendar; - + private Calendar calendarMock = mock(Calendar.class); - + @Test void testStaticMethod() { mockedCalendar.when(() -> Calendar.getInstance(Locale.ENGLISH)).thenReturn(calendarMock); @@ -436,16 +436,16 @@ void argumentOfWhenOnInstanceMethodsAreNotReplaced() { java( """ import static org.mockito.Mockito.*; - + import java.util.Calendar; import java.util.Locale; - + import org.junit.jupiter.api.Test; - + public class MyTest { - + private Calendar calendarMock = mock(Calendar.class); - + @Test void testStaticMethod() { when(calendarMock.toString()).thenReturn(null); @@ -463,19 +463,19 @@ void argumentOfVerifyOnParameterlessStaticMethodIsReplacedBySimpleLambda() { java( """ import static org.mockito.Mockito.*; - + import java.util.Currency; import java.util.Locale; - + import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; - + public class MyTest { - + private MockedStatic mockedCurrency; - + private Currency currencyMock = mock(Currency.class); - + @Test void testStaticMethod() { verify(Currency.getInstance(Locale.ENGLISH), never()); @@ -485,19 +485,19 @@ void testStaticMethod() { """, """ import static org.mockito.Mockito.*; - + import java.util.Currency; import java.util.Locale; - + import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; - + public class MyTest { - + private MockedStatic mockedCurrency; - + private Currency currencyMock = mock(Currency.class); - + @Test void testStaticMethod() { mockedCurrency.verify(() -> Currency.getInstance(Locale.ENGLISH), never()); @@ -515,19 +515,19 @@ void interfacesAndAbstractClassesWithEmptyMethodBodiesRemainsUntouched() { rewriteRun(java( """ public interface MyInterface { - + void checkThis(); - + } """) , java( """ public abstract class MyAbstractClass { - + public boolean isItTrue() { return true; } - + public abstract boolean isItImplemented(); - + } """ )); @@ -539,14 +539,14 @@ void extensionOfPowerMockTestCaseGetsRemoved() { rewriteRun(java( """ package org.powermock.modules.testng; - + public class PowerMockTestCase {} """ ), java( """ import org.powermock.modules.testng.PowerMockTestCase; - + public class MyPowerMockTestCase extends PowerMockTestCase {} """, """ @@ -562,14 +562,14 @@ void extensionOfPowerMockConfigurationGetsRemoved() { java( """ package org.powermock.configuration; - + public class PowerMockConfiguration {} """ ), java( """ import org.powermock.configuration.PowerMockConfiguration; - + public class MyPowerMockConfiguration extends PowerMockConfiguration {} """, """ @@ -586,11 +586,11 @@ void mockStaticInTryWithResources() { """ import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; - + import java.nio.file.Files; - + import static org.mockito.Mockito.mockStatic; - + class A { @Test void testTryWithResource() { @@ -611,7 +611,7 @@ void shouldNotDuplicateVarsAndMethods() { java( """ package test; - + public class A { public static class B { public static String helloWorld() { @@ -628,17 +628,17 @@ public static String helloWorld() { import org.mockito.Mockito; import org.powermock.core.classloader.annotations.PrepareForTest; import test.A; - + @PrepareForTest({ A.B.class }) public class MyTest { - + private static final String TEST_MESSAGE = "this is a test message"; - + @Before void setUp() { Mockito.mockStatic(A.B.class); } - + @Test public void testStaticMethod() { } diff --git a/src/test/java/org/openrewrite/java/testing/mockito/ReplacePowerMockitoIntegrationTest.java b/src/test/java/org/openrewrite/java/testing/mockito/ReplacePowerMockitoIntegrationTest.java index cb072ef61..f2a63bd79 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/ReplacePowerMockitoIntegrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/ReplacePowerMockitoIntegrationTest.java @@ -33,12 +33,12 @@ public void defaults(RecipeSpec spec) { .logCompilationWarningsAndErrors(true) .classpathFromResources(new InMemoryExecutionContext(), "mockito-core-3.12", - "junit-jupiter-api-5.9", - "junit-4.13", - "powermock-core-1.6", - "powermock-api-mockito-1.6", - "powermock-api-support-1.6", - "testng-7.7")) + "junit-jupiter-api-5", + "junit-4", + "powermock-core-1", + "powermock-api-mockito-1", + "powermock-api-support-1", + "testng-7")) .typeValidationOptions(TypeValidation.builder() .cursorAcyclic(false) // TODO Resolve the missing types in the replacement templates rather than ignore the errors here @@ -63,47 +63,47 @@ public class PowerMockRunner {} """ import static org.mockito.Mockito.*; import static org.junit.jupiter.api.Assertions.assertEquals; - + import java.util.Calendar; import java.util.Currency; import java.util.Locale; - + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; - + public class StaticMethodTest { - + private MockedStatic mockedCurrency; - + private MockedStatic mockedCalendar; - + private Calendar calendarMock = mock(Calendar.class); - + @BeforeEach void setUpStaticMocks() { mockedCurrency = mockStatic(Currency.class); mockedCalendar = mockStatic(Calendar.class); } - + @AfterEach void tearDownStaticMocks() { mockedCalendar.closeOnDemand(); mockedCurrency.closeOnDemand(); } - + @Test void testWithCalendar() { mockedCalendar.when(() -> Calendar.getInstance(Locale.ENGLISH)).thenReturn(calendarMock); assertEquals(Calendar.getInstance(Locale.ENGLISH), calendarMock); } - + @Test void testWithCurrency() { mockedCurrency.verify(Currency::getAvailableCurrencies, never()); } - + } """ ) @@ -126,83 +126,83 @@ public class PowerMockRunner {} import static org.mockito.Mockito.*; import static org.powermock.api.mockito.PowerMockito.mockStatic; import static org.junit.jupiter.api.Assertions.assertEquals; - + import java.util.Calendar; import java.util.Currency; import java.util.Locale; - + import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.testng.annotations.Test; - + @RunWith(PowerMockRunner.class) @PowerMockIgnore({"org.apache.*", "com.sun.*", "javax.*"}) @PrepareForTest(value = {Calendar.class, Currency.class}) public class StaticMethodTest { - + private Calendar calendarMock = mock(Calendar.class); - + @Test void testWithCalendar() { mockStatic(Calendar.class); when(Calendar.getInstance(Locale.ENGLISH)).thenReturn(calendarMock); assertEquals(Calendar.getInstance(Locale.ENGLISH), calendarMock); } - + @Test void testWithCurrency() { mockStatic(Currency.class); verify(Currency.getAvailableCurrencies(), never()); } - + } """, """ import static org.mockito.Mockito.*; import static org.junit.jupiter.api.Assertions.assertEquals; - + import java.util.Calendar; import java.util.Currency; import java.util.Locale; - + import org.mockito.MockedStatic; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + public class StaticMethodTest { - + private MockedStatic mockedCurrency; - + private MockedStatic mockedCalendar; - + private Calendar calendarMock = mock(Calendar.class); - + @BeforeMethod void setUpStaticMocks() { mockedCurrency = mockStatic(Currency.class); mockedCalendar = mockStatic(Calendar.class); } - + @AfterMethod(alwaysRun = true) void tearDownStaticMocks() { mockedCalendar.closeOnDemand(); mockedCurrency.closeOnDemand(); } - + @Test void testWithCalendar() { mockedCalendar.when(() -> Calendar.getInstance(Locale.ENGLISH)).thenReturn(calendarMock); assertEquals(Calendar.getInstance(Locale.ENGLISH), calendarMock); } - + @Test void testWithCurrency() { mockedCurrency.verify(Currency::getAvailableCurrencies, never()); } - + } """ ) @@ -217,27 +217,27 @@ void thatPowerMockitoMockStaticIsReplacedInTestMethod() { java( """ import static org.testng.Assert.assertEquals; - + import java.util.Calendar; import java.util.Currency; import java.util.Locale; - + import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; - + @PrepareForTest(value = {Calendar.class, Currency.class}) public class StaticMethodTest { - + private Calendar calendarMock; - + @BeforeClass void setUp() { calendarMock = Mockito.mock(Calendar.class); } - + @Test void testWithCalendar() { PowerMockito.mockStatic(Calendar.class); @@ -250,43 +250,43 @@ void testWithCalendar() { """, """ import static org.testng.Assert.assertEquals; - + import java.util.Calendar; import java.util.Currency; import java.util.Locale; - + import org.mockito.MockedStatic; import org.mockito.Mockito; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + public class StaticMethodTest { - + private MockedStatic mockedCurrency; - + private MockedStatic mockedCalendar; - + private Calendar calendarMock; - + @BeforeClass void setUp() { calendarMock = Mockito.mock(Calendar.class); } - + @BeforeMethod void setUpStaticMocks() { mockedCurrency = Mockito.mockStatic(Currency.class); mockedCalendar = Mockito.mockStatic(Calendar.class); } - + @AfterMethod(alwaysRun = true) void tearDownStaticMocks() { mockedCalendar.closeOnDemand(); mockedCurrency.closeOnDemand(); } - + @Test void testWithCalendar() { mockedCalendar.when(() -> Calendar.getInstance(Locale.ENGLISH)).thenReturn(calendarMock); @@ -306,27 +306,27 @@ void thatPowerMockitoMockStaticIsReplacedInSetUpMethod() { java( """ import static org.testng.Assert.assertEquals; - + import java.util.Calendar; - + import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + @PrepareForTest(value = {Calendar.class}) public class StaticMethodTest { - + private Calendar calendarMock; - + @BeforeMethod void setUp() { PowerMockito.mockStatic(Calendar.class); calendarMock = Mockito.mock(Calendar.class); Mockito.when(Calendar.getInstance()).thenReturn(calendarMock); } - + @Test void testWithCalendar() { assertEquals(Calendar.getInstance(), calendarMock); @@ -336,33 +336,33 @@ void testWithCalendar() { """, """ import static org.testng.Assert.assertEquals; - + import java.util.Calendar; - + import org.mockito.MockedStatic; import org.mockito.Mockito; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + public class StaticMethodTest { - + private MockedStatic mockedCalendar; - + private Calendar calendarMock; - + @BeforeMethod void setUp() { mockedCalendar = Mockito.mockStatic(Calendar.class); calendarMock = Mockito.mock(Calendar.class); mockedCalendar.when(Calendar::getInstance).thenReturn(calendarMock); } - + @AfterMethod(alwaysRun = true) void tearDownStaticMocks() { mockedCalendar.closeOnDemand(); } - + @Test void testWithCalendar() { assertEquals(Calendar.getInstance(), calendarMock); @@ -381,26 +381,26 @@ void thatPowerMockitoSpyIsReplaced() { java( """ import static org.testng.Assert.assertEquals; - + import java.util.Calendar; import java.util.Locale; - + import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + @PrepareForTest(value = {Calendar.class}) public class StaticMethodTest { - + private Calendar calendarMock; - + @BeforeMethod void setUp() { calendarMock = Mockito.mock(Calendar.class); } - + @Test void testWithCalendar() { PowerMockito.spy(Calendar.class); @@ -408,45 +408,45 @@ void testWithCalendar() { PowerMockito.when(Calendar.getInstance(Locale.ENGLISH)).thenReturn(calendarMock); assertEquals(Calendar.getInstance(Locale.ENGLISH), calendarMock); } - + } """, """ import static org.testng.Assert.assertEquals; - + import java.util.Calendar; import java.util.Locale; - + import org.mockito.MockedStatic; import org.mockito.Mockito; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + public class StaticMethodTest { - + private MockedStatic mockedCalendar; - + private Calendar calendarMock; - + @BeforeMethod void setUp() { mockedCalendar = Mockito.mockStatic(Calendar.class); calendarMock = Mockito.mock(Calendar.class); } - + @AfterMethod(alwaysRun = true) void tearDownStaticMocks() { mockedCalendar.closeOnDemand(); } - + @Test void testWithCalendar() { Mockito.spy(Calendar.class); mockedCalendar.when(() -> Calendar.getInstance(Locale.ENGLISH)).thenReturn(calendarMock); assertEquals(Calendar.getInstance(Locale.ENGLISH), calendarMock); } - + } """ ) @@ -490,22 +490,22 @@ public void testStaticMock() { """, """ import static org.mockito.Mockito.*; - + import foo.StringFilter; import org.mockito.MockedStatic; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + public class MyTest { - + private MockedStatic mockedStringFilter; - + @BeforeMethod void setUpStaticMocks() { mockedStringFilter = mockStatic(StringFilter.class); } - + @AfterMethod(alwaysRun = true) void tearDownStaticMocks() { mockedStringFilter.closeOnDemand(); @@ -531,14 +531,14 @@ void verifyOnMocksRemainsUntouched() { import static org.mockito.internal.verification.VerificationModeFactory.times; import java.util.Calendar; import java.util.Date; - + import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + public class MyTest { - + private Calendar cut; - + @BeforeMethod void setUp() { cut = spy(Calendar.getInstance()); @@ -563,16 +563,16 @@ void dynamicPowerMockitoWhenCallsGetReplaced() { import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.powermock.api.mockito.PowerMockito.*; - + import java.util.Calendar; import java.util.Locale; - + import org.powermock.core.classloader.annotations.PrepareForTest; import org.testng.annotations.Test; - + @PrepareForTest({Calendar.class}) public class MyTest { - + @Test public void testCalendarDynamic() throws Exception { Calendar calendarMock = mock(Calendar.class); @@ -583,29 +583,29 @@ public void testCalendarDynamic() throws Exception { """, """ import static org.mockito.Mockito.*; - + import java.util.Calendar; import java.util.Locale; - + import org.mockito.MockedStatic; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; - + public class MyTest { - + private MockedStatic mockedCalendar; - + @BeforeMethod void setUpStaticMocks() { mockedCalendar = mockStatic(Calendar.class); } - + @AfterMethod(alwaysRun = true) void tearDownStaticMocks() { mockedCalendar.closeOnDemand(); } - + @Test public void testCalendarDynamic() throws Exception { Calendar calendarMock = mock(Calendar.class); @@ -626,11 +626,11 @@ void powerMockitoCallsAreReplacedByMockitoCalls() { import org.junit.jupiter.api.BeforeEach; import org.powermock.api.mockito.PowerMockito; import java.util.Calendar; - + public class MyTest { - + private Calendar calendarMock; - + @BeforeEach void setUp() { calendarMock = PowerMockito.mock(Calendar.class); @@ -644,11 +644,11 @@ void setUp() { import org.junit.jupiter.api.BeforeEach; import org.mockito.Mockito; import java.util.Calendar; - + public class MyTest { - + private Calendar calendarMock; - + @BeforeEach void setUp() { calendarMock = Mockito.mock(Calendar.class); diff --git a/src/test/java/org/openrewrite/java/testing/search/FindUnitTestsTest.java b/src/test/java/org/openrewrite/java/testing/search/FindUnitTestsTest.java index d4008b124..46bc08298 100644 --- a/src/test/java/org/openrewrite/java/testing/search/FindUnitTestsTest.java +++ b/src/test/java/org/openrewrite/java/testing/search/FindUnitTestsTest.java @@ -45,7 +45,7 @@ public void baz() { public void defaults(RecipeSpec spec) { spec.recipe(new FindUnitTests()) .parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), - "junit-jupiter-api-5.9")); + "junit-jupiter-api-5")); } @DocumentExample