Skip to content

Commit 01ce71e

Browse files
authored
no @nested for inner composed annotation (#674)
1 parent 1956bf0 commit 01ce71e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
8686
J.ClassDeclaration cd = super.visitClassDeclaration(classDecl, ctx);
8787
boolean alreadyNested = classDecl.getLeadingAnnotations().stream()
8888
.anyMatch(a -> TypeUtils.isOfClassType(a.getType(), NESTED));
89-
if (!alreadyNested && hasTestMethods(cd)) {
89+
boolean isAnnotationType = cd.getKind() == J.ClassDeclaration.Kind.Type.Annotation;
90+
if (!isAnnotationType && !alreadyNested && hasTestMethods(cd)) {
9091
cd = JavaTemplate.builder("@Nested")
9192
.javaParser(JavaParser.fromJavaVersion()
9293
.classpathFromResources(ctx, "junit-jupiter-api-5.9"))

src/test/java/org/openrewrite/java/testing/junit5/AddMissingNestedTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,29 @@ public void test() {
203203
)
204204
);
205205
}
206+
207+
@Test
208+
void doesNotNestAnnotationType() {
209+
//language=java
210+
rewriteRun(
211+
java(
212+
"""
213+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
214+
215+
import java.lang.annotation.Retention;
216+
import org.junit.jupiter.api.Test;
217+
218+
public class SingleTest {
219+
@CustomTest
220+
public void test() {
221+
}
222+
223+
@Retention(RUNTIME)
224+
@Test
225+
@interface CustomTest {
226+
}
227+
}
228+
""")
229+
);
230+
}
206231
}

0 commit comments

Comments
 (0)