|
1 | 1 | /** |
2 | 2 | * @id java/junit5-non-static-inner-class-missing-nested-annotation |
3 | | - * @name J-T-004: Non-static inner class defined in a JUnit5 test is missing a `@Nested` annotation |
4 | | - * @description A non-static inner class defined in a JUnit5 test missing a `@Nested` annotation |
| 3 | + * @name Non-static inner class defined in a JUnit 5 test is missing a `@Nested` annotation |
| 4 | + * @description A non-static inner class defined in a JUnit 5 test missing a `@Nested` annotation |
5 | 5 | * will be excluded from execution and it may indicate a misunderstanding from the |
6 | 6 | * programmer. |
7 | 7 | * @kind problem |
8 | 8 | * @precision very-high |
9 | 9 | * @problem.severity warning |
10 | | - * @tags maintainability |
| 10 | + * @tags quality |
| 11 | + * maintainability |
11 | 12 | * correctness |
12 | 13 | */ |
13 | 14 |
|
14 | 15 | import java |
15 | 16 |
|
16 | | -class JUnit5TestClass extends Class { |
17 | | - JUnit5TestClass() { |
18 | | - this.getAMethod().getAnAnnotation().getType().hasQualifiedName("org.junit.jupiter.api", "Test") |
19 | | - } |
20 | | -} |
21 | | - |
22 | | -from JUnit5TestClass testClass // `TestClass` by definition should have at least one @Test method. |
| 17 | +from JUnit5TestClass testClass |
23 | 18 | where |
24 | | - not testClass.isStatic() and |
25 | | - testClass instanceof InnerClass and // `InnerClass` is by definition a non-static nested class. |
26 | | - not exists(Annotation annotation | |
27 | | - annotation.getType().hasQualifiedName("org.junit.jupiter.api", "Nested") and |
28 | | - annotation.getAnnotatedElement() = testClass |
29 | | - ) |
30 | | -select testClass, "This JUnit5 inner test class lacks a @Nested annotation." |
| 19 | + // `InnerClass` is a non-static, nested class. |
| 20 | + testClass instanceof InnerClass and |
| 21 | + not testClass.hasAnnotation("org.junit.jupiter.api", "Nested") |
| 22 | +select testClass, "This JUnit5 inner test class lacks a '@Nested' annotation." |
0 commit comments