Add support for migrating groups attribute

This commit is contained in:
Gijs de Jong
2022-10-26 11:28:24 +02:00
parent 5de2496035
commit 3132810c47
2 changed files with 21 additions and 2 deletions

View File

@@ -105,6 +105,24 @@ public final class AnnotationAttributeReplacement extends BugChecker implements
SourceCode.treeToString(
assignmentTree.getExpression(), state))))
.build()))
.put(
singleArgumentMatcher("org.testng.annotations.Test#groups"),
(annotation, argument, state) ->
Optional.of(argument)
.filter(AssignmentTree.class::isInstance)
.map(AssignmentTree.class::cast)
.map(
assignmentTree ->
SuggestedFix.builder()
.merge(removeAnnotationArgument(annotation, argument, state))
.merge(
SuggestedFix.postfixWith(
annotation,
String.format(
"\n@org.junit.jupiter.api.Tag(%s)",
SourceCode.treeToString(
assignmentTree.getExpression(), state))))
.build()))
.build();
@Override

View File

@@ -42,13 +42,13 @@ final class AnnotationAttributeReplacementTest {
"import org.testng.annotations.Test;",
"",
"class A {",
" @Test(priority = 1, description = \"test\")",
" @Test(priority = 1, groups = \"unit\", description = \"test\")",
" public void foo() {}",
"}")
.addOutputLines(
"A.java",
"import org.junit.jupiter.api.MethodOrderer;",
"import org.junit.jupiter.api.TestMethodOrder;",
"import org.junit.jupiter.api.TestMethodOrder;",
"import org.testng.annotations.Test;",
"",
"@TestMethodOrder(MethodOrderer.OrderAnnotation.class)",
@@ -56,6 +56,7 @@ final class AnnotationAttributeReplacementTest {
" @Test",
" @org.junit.jupiter.api.Order(1)",
" @org.junit.jupiter.api.DisplayName(\"test\")",
" @org.junit.jupiter.api.Tag(\"unit\")",
" public void foo() {}",
"}")
.doTest(TEXT_MATCH);