Junit 5 replaced several Junit 4 annotations with very similar annotations.
Create a ReplaceAnnotations visitor which finds these method-scoped JUnit4 annotations and replaces them with their Junit5 successors:
Implementation
It is likely that this can be accomplished only with yaml/declarative visitors calling ChangeType since most or all of these are drop in replacements.
For a similar example of declaratively using ChangeType to switch annotation types, see this similar example from the mockito recipes.
Note that @Ignore can optionally accept an argument. If such an argument exists, it should be preserved as an argument to the replacing @Disabled. If @Ignore and @Disabled accept the same arguments then fully yaml/declarative ChangeType is sufficient. If the arguments have to be transformed then you'll probably have to write a visitor in Java to handle that.
If it does turn out that you need to implement a new visitor in Java, you will probably only have to override JavaRefactorVisitor.visitMethod(). For a similar annotation-editing java visitor, see the similar (but more complex) ChangeTestAnnotation visitor which replaces the Junit4 version of @test with the Junit5 version of @test.
Testing
Regardless of whether or not your visitor is written in YAML or Java, create a test case that exercises your visitor, asserting that it refactors a java source file that used the Junit4 annotations into one which uses the Junit 5 annotations.
Here is an example of a similar test class that exercises visitors declared in a yaml file.
Documenting
There should be a new page for this visitor added to our docs
Junit 5 replaced several Junit 4 annotations with very similar annotations.
Create a
ReplaceAnnotationsvisitor which finds these method-scoped JUnit4 annotations and replaces them with their Junit5 successors:Implementation
It is likely that this can be accomplished only with yaml/declarative visitors calling ChangeType since most or all of these are drop in replacements.
For a similar example of declaratively using ChangeType to switch annotation types, see this similar example from the mockito recipes.
Note that
@Ignorecan optionally accept an argument. If such an argument exists, it should be preserved as an argument to the replacing@Disabled. If@Ignoreand@Disabledaccept the same arguments then fully yaml/declarative ChangeType is sufficient. If the arguments have to be transformed then you'll probably have to write a visitor in Java to handle that.If it does turn out that you need to implement a new visitor in Java, you will probably only have to override
JavaRefactorVisitor.visitMethod(). For a similar annotation-editing java visitor, see the similar (but more complex) ChangeTestAnnotation visitor which replaces the Junit4 version of @test with the Junit5 version of @test.Testing
Regardless of whether or not your visitor is written in YAML or Java, create a test case that exercises your visitor, asserting that it refactors a java source file that used the Junit4 annotations into one which uses the Junit 5 annotations.
Here is an example of a similar test class that exercises visitors declared in a yaml file.
Documenting
There should be a new page for this visitor added to our docs