File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed
src/Likely Bugs/Frameworks/JUnit
test/query-tests/Likely Bugs/Frameworks/JUnit Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,20 @@ class JUnit5TestClass extends Class {
120
120
JUnit5TestClass ( ) { this .getAMethod ( ) instanceof JUnitJupiterTestMethod }
121
121
}
122
122
123
+ /**
124
+ * A JUnit inner test class that is non-anonymous, non-local,
125
+ * and non-private.
126
+ */
127
+ class JUnit5InnerTestClass extends JUnit5TestClass {
128
+ JUnit5InnerTestClass ( ) {
129
+ // `InnerClass` is a non-static nested class.
130
+ this instanceof InnerClass and
131
+ not this .isAnonymous ( ) and
132
+ not this .isLocal ( ) and
133
+ not this .isPrivate ( )
134
+ }
135
+ }
136
+
123
137
/**
124
138
* A JUnit `@Ignore` annotation.
125
139
*/
Original file line number Diff line number Diff line change 15
15
16
16
import java
17
17
18
- from JUnit5TestClass testClass
18
+ from JUnit5InnerTestClass testClass
19
19
where
20
- // `InnerClass` is a non-static, nested class.
21
- testClass instanceof InnerClass and
22
20
not testClass .hasAnnotation ( "org.junit.jupiter.api" , "Nested" ) and
23
21
// An abstract class should not have a `@Nested` annotation
24
22
not testClass .isAbstract ( )
Original file line number Diff line number Diff line change @@ -59,4 +59,32 @@ public abstract class Test8 {
59
59
public void test () {
60
60
}
61
61
}
62
+
63
+ interface Test9 {
64
+ }
65
+
66
+ public void f () {
67
+ // COMPLIANT: anonymous classes are not considered as inner test
68
+ // classes by JUnit and therefore don't need `@Nested`
69
+ new Test9 () {
70
+ @ Test
71
+ public void test () {
72
+ }
73
+ };
74
+ // COMPLIANT: local classes are not considered as inner test
75
+ // classes by JUnit and therefore don't need `@Nested`
76
+ class Test10 {
77
+ @ Test
78
+ void test () {
79
+ }
80
+ }
81
+ }
82
+
83
+ // COMPLIANT: private classes are not considered as inner test
84
+ // classes by JUnit and therefore don't need `@Nested`
85
+ private class Test11 {
86
+ @ Test
87
+ public void test () {
88
+ }
89
+ }
62
90
}
You can’t perform that action at this time.
0 commit comments