Skip to content

Commit c9cd3bd

Browse files
authored
Fix UsesType precondition pattern in KotlinTestMethodsShouldReturnUnit (#1022)
UsesType matches against fully qualified type names, but the precondition was given the two-token "org..* *Test*" pattern that AnnotationMatcher uses. That only ever matched because of a TypeNameMatcher bug where a ..* token followed by a suffix matched every name, fixed upstream in #8012. Use a valid single-token glob org.junit..*Test* for the UsesType precondition; the AnnotationMatcher pattern is unchanged.
1 parent a602b44 commit c9cd3bd

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/main/java/org/openrewrite/java/testing/cleanup/KotlinTestMethodsShouldReturnUnit.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
public class KotlinTestMethodsShouldReturnUnit extends Recipe {
3636

3737
private static final String TEST_ANNOTATION_PATTERN = "org..* *Test*";
38+
// `UsesType` matches against fully qualified type names, so it needs a single-token glob rather
39+
// than the two-token (`<owner> <name>`) form `AnnotationMatcher` uses above.
40+
private static final String TEST_ANNOTATION_TYPE_PATTERN = "org.junit..*Test*";
3841
private static final JavaType.Class KOTLIN_UNIT = (JavaType.Class) JavaType.buildType("kotlin.Unit");
3942

4043
@Getter
@@ -47,7 +50,7 @@ public class KotlinTestMethodsShouldReturnUnit extends Recipe {
4750

4851
@Override
4952
public TreeVisitor<?, ExecutionContext> getVisitor() {
50-
return Preconditions.check(new UsesType<>(TEST_ANNOTATION_PATTERN, true), new KotlinIsoVisitor<ExecutionContext>() {
53+
return Preconditions.check(new UsesType<>(TEST_ANNOTATION_TYPE_PATTERN, true), new KotlinIsoVisitor<ExecutionContext>() {
5154
@Override
5255
public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) {
5356
J.MethodDeclaration m = super.visitMethodDeclaration(method, ctx);

0 commit comments

Comments
 (0)