-
Notifications
You must be signed in to change notification settings - Fork 121
Simplify annotation handling in SpringJUnit5Check #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
152e98d
0f93b8c
1437466
75ac65f
6b5df77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,30 +37,23 @@ | |
* @author Phillip Webb | ||
*/ | ||
public class SpringJUnit5Check extends AbstractSpringCheck { | ||
|
||
private static final String JUNIT4_TEST_ANNOTATION = "org.junit.Test"; | ||
|
||
private static final List<String> TEST_ANNOTATIONS; | ||
static { | ||
Set<String> annotations = new LinkedHashSet<>(); | ||
addAnnotation(annotations, JUNIT4_TEST_ANNOTATION); | ||
addAnnotation(annotations, "org.junit.jupiter.api.RepeatedTest"); | ||
addAnnotation(annotations, "org.junit.jupiter.api.Test"); | ||
addAnnotation(annotations, "org.junit.jupiter.api.TestFactory"); | ||
addAnnotation(annotations, "org.junit.jupiter.api.TestTemplate"); | ||
addAnnotation(annotations, "org.junit.jupiter.params.ParameterizedTest"); | ||
TEST_ANNOTATIONS = Collections.unmodifiableList(new ArrayList<>(annotations)); | ||
} | ||
|
||
private static final List<String> LIFECYCLE_ANNOTATIONS; | ||
static { | ||
Set<String> annotations = new LinkedHashSet<>(); | ||
addAnnotation(annotations, "org.junit.jupiter.api.BeforeAll"); | ||
addAnnotation(annotations, "org.junit.jupiter.api.BeforeEach"); | ||
addAnnotation(annotations, "org.junit.jupiter.api.AfterAll"); | ||
addAnnotation(annotations, "org.junit.jupiter.api.AfterEach"); | ||
LIFECYCLE_ANNOTATIONS = Collections.unmodifiableList(new ArrayList<>(annotations)); | ||
} | ||
private static final List<String> TEST_ANNOTATIONS = Collections.unmodifiableList(Arrays.asList( | ||
"RepeatedTest", | ||
"Test", | ||
"TestFactory", | ||
"TestTemplate", | ||
"ParameterizedTest" | ||
)); | ||
|
||
private static final List<String> LIFECYCLE_ANNOTATIONS = Collections.unmodifiableList(Arrays.asList( | ||
"BeforeAll", | ||
"BeforeEach", | ||
"AfterAll", | ||
"AfterEach" | ||
) | ||
); | ||
|
||
private static final Set<String> BANNED_IMPORTS; | ||
static { | ||
|
@@ -75,14 +68,6 @@ public class SpringJUnit5Check extends AbstractSpringCheck { | |
BANNED_IMPORTS = Collections.unmodifiableSet(bannedImports); | ||
} | ||
|
||
private static void addAnnotation(Set<String> annotations, String annotation) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that removing this method and the usage of it will introduce a regression. The javadoc for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method accepts both simple and fully-qualified names, e.g. "Override" will match both java.lang.Override and Override. Which means that if we are using only the non FQN then we receive a check for both, there is also a test for that: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think we can't be certain that this is the case. One user could write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant is that I believe it catches both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I see what you mean now. I agree that just the simple names should be sufficient. We try to keep issues and pull requests focused on a single change. To that end, would you mind splitting the corrections to JUnit5BadModifier and the simplifications above into separate pull requests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I have updated this one to be the refactor, I'll create a new one for the test |
||
annotations.add(annotation); | ||
int lastDot = annotation.lastIndexOf("."); | ||
if (lastDot != -1) { | ||
annotations.add(annotation.substring(lastDot + 1)); | ||
} | ||
} | ||
|
||
private List<String> unlessImports = new ArrayList<>(); | ||
|
||
private final List<DetailAST> testMethods = new ArrayList<>(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.