Migrate the test suite from JUnit 4 to JUnit 5 - #840
Merged
Conversation
Convert the 18 remaining JUnit 4 test classes under src/test/java to JUnit Jupiter using OpenRewrite's JUnit4to5Migration recipe, with hand fixes for what the recipe could not handle automatically: - TransformerTesterRule, a custom @Rule/TestRule, is rewritten as a JUnit 5 InvocationInterceptor extension and PropertiesTransformerTest now uses @ExtendWith instead of @rule. - MinijarFilterTest's TemporaryFolder.builder() field is replaced with a plain package-private @tempdir File field (the recipe produced a non-compiling File.builder() call). - DefaultShaderTest's public static @ClassRule TemporaryFolder becomes a package-private static @tempdir File field, renamed to camelCase to satisfy checkstyle's VisibilityModifier and StaticVariableName rules, which do not exempt @tempdir the way they exempt @rule. ShadeMojoTest is deliberately left on JUnit 4: it extends AbstractMojoTestCase, which extends PlexusTestCase, which extends junit.framework.TestCase. The pom now declares junit-jupiter-api and junit-vintage-engine (versions managed by the parent's junit-bom) test dependencies so both engines are discovered by the JUnit Platform provider, alongside the existing junit:junit dependency that ShadeMojoTest still needs. src/it and src/test/resources are untouched; they hold JUnit 4 based IT/sample fixtures and JAR/class-file shading inputs, not code to migrate. Generated-by: Claude Opus 5 (1M context)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves 18 test classes to Jupiter. The bulk is the OpenRewrite
JUnit4to5Migrationrecipe, but three things needed hand work — the third is the one worth reviewing.TransformerTesterRulewas a customTestRule. The recipe converted the@Testannotations inPropertiesTransformerTestto Jupiter but left the@Rulefield alone. That still compiles, which is the dangerous part: under Jupiter the rule would simply never run, and the four spec-driven tests would have passed while asserting nothing. It is rewritten as anInvocationInterceptorand applied with@ExtendWithinstead of a@Rulefield.One behavioural note on that rewrite: the JUnit 4 rule deliberately never called
base.evaluate()when a@TransformerTestspec was present — the test body never ran. Jupiter requiresinvocation.proceed()to be called exactly once, so the interceptor now does. That is safe here only because all four@TransformerTestmethods have empty bodies ({}), andPropertiesTransformerTestis the only class using the annotation. Worth knowing if anyone later adds a body to one of them.MinijarFilterTest— the recipe emitted non-compiling code, turningTemporaryFolder.builder().assureDeletion().build()intoFile.builder().... Replaced with a plain@TempDir Filefield.DefaultShaderTest—@ClassRule TemporaryFolder TEMPORARY_FOLDERbecame@TempDir public static File TEMPORARY_FOLDER, which trips two checkstyle rules at once:VisibilityModifierexempts@Rule/@ClassRulebut not@TempDir, andStaticVariableNamewants lowerCamelCase for non-final statics. Renamed to a package-privatestatic File temporaryFolder.Left on JUnit 4 deliberately:
ShadeMojoTest. It extendsAbstractMojoTestCase→PlexusTestCase→junit.framework.TestCase, with methods discovered by thetest*naming convention. That inheritance lives in maven-plugin-testing-harness, not here.junit:junittherefore stays (the harness marks itoptional, so it must be declared explicitly), andjunit-vintage-engineis added so the class stays discoverable once surefire switches to the platform provider.org.hamcrest:hamcrestalso stays — several tests useCoreMatchers/MatcherAssertdirectly.junit-jupiter-engineis deliberately not declared, since surefire provisions it.src/itandsrc/test/resourcesare untouched — confirmed by diffing the OpenRewrite output so that onlypom.xmlandsrc/test/javadiffer.Verification
mvn testbefore:Tests run: 72, Failures: 0, Errors: 0, Skipped: 0(surefire selectingJUnit4Provider).mvn testafter:Tests run: 72, Failures: 0, Errors: 0, Skipped: 0(surefire selectingJUnitPlatformProvider, withShadeMojoTest's 5 tests running via the vintage engine).checkstyle:check0 violations;spotless:checkclean.Because "the tests still pass" proves nothing about an extension that might silently do nothing, the interceptor was also checked negatively: corrupting one expected value in
PropertiesTransformerTestproduces a realAssertionFailedError, so it is genuinely enforcing.Draft until CI confirms.
Generated-by: Claude Opus 5 (1M context)