Skip to content

Recognize meta-annotated test methods in TestsShouldNotBePublic#1040

Merged
timtebeek merged 1 commit into
mainfrom
tim/tests-should-not-be-public-meta-annotations
Jun 20, 2026
Merged

Recognize meta-annotated test methods in TestsShouldNotBePublic#1040
timtebeek merged 1 commit into
mainfrom
tim/tests-should-not-be-public-meta-annotations

Conversation

@timtebeek

@timtebeek timtebeek commented Jun 20, 2026

Copy link
Copy Markdown
Member

TestsShouldNotBePublic previously only matched methods with a direct JUnit 5 annotation (@Test, @BeforeEach, etc.). Methods annotated with a custom annotation that is itself meta-annotated with one of these (e.g. itf's @MavenTest, which is annotated with @TestTemplate/@Test) were not recognized, so the enclosing class kept its redundant public modifier.

Change

  • hasJUnit5MethodAnnotation now recurses through meta-annotations via JavaType.FullyQualified#getAnnotations(), with a seen set to guard against annotation cycles.
  • Added a test covering a method annotated with a custom @Test-meta-annotated annotation.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jun 20, 2026
@timtebeek timtebeek marked this pull request as draft June 20, 2026 14:12
Resolve #308 so that classes whose methods carry a custom annotation
that is itself meta-annotated with @test (e.g. @maventest) also have
their redundant public modifier removed.

Use AnnotationMatcher's built-in meta-annotation matching rather than
hand-rolled recursion.
@timtebeek timtebeek force-pushed the tim/tests-should-not-be-public-meta-annotations branch from c4c836d to b1936c3 Compare June 20, 2026 14:14
@timtebeek timtebeek marked this pull request as ready for review June 20, 2026 14:28
@timtebeek timtebeek merged commit 7e27ad6 into main Jun 20, 2026
1 check passed
@timtebeek timtebeek deleted the tim/tests-should-not-be-public-meta-annotations branch June 20, 2026 14:28
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

TestsShouldNotBePublic should also pick up meta annotations

1 participant