Skip to content

Skip JUnit 4 lifecycle annotation when Jupiter equivalent already present#1043

Merged
timtebeek merged 1 commit into
mainfrom
fix/before-after-duplicate-annotation
Jun 20, 2026
Merged

Skip JUnit 4 lifecycle annotation when Jupiter equivalent already present#1043
timtebeek merged 1 commit into
mainfrom
fix/before-after-duplicate-annotation

Conversation

@timtebeek

@timtebeek timtebeek commented Jun 20, 2026

Copy link
Copy Markdown
Member

What's changed

UpdateBeforeAfterAnnotations migrated JUnit 4 lifecycle annotations by changing their type to the Jupiter equivalent. When a method already carried both the JUnit 4 annotation and its Jupiter equivalent — e.g. a shared base class supporting both frameworks:

class TestBase {
    @Before
    @BeforeEach
    void setup() {
    }
}

changing @Before to @BeforeEach produced a duplicate, non-repeatable annotation, yielding the compile error:

Duplicate annotation. The declaration of 'org.junit.jupiter.api.BeforeEach' does not have a valid java.lang.annotation.Repeatable annotation

Now, before the type-change passes run, any JUnit 4 lifecycle annotation whose Jupiter equivalent is already present on the same method is removed instead.

…sent

When a method carries both a JUnit 4 lifecycle annotation (e.g. @before)
and its Jupiter equivalent (@beforeeach), changing the type of the JUnit 4
annotation produced a duplicate, non-repeatable annotation. Remove the
JUnit 4 annotation instead in that case.

Fixes #501
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jun 20, 2026
@timtebeek timtebeek merged commit 0eb4765 into main Jun 20, 2026
1 check passed
@timtebeek timtebeek deleted the fix/before-after-duplicate-annotation branch June 20, 2026 16:17
@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.

UpdateBeforeAfterAnnotations does not check for existing target annotations

1 participant