forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnnotationTest.java
More file actions
117 lines (101 loc) · 2.68 KB
/
AnnotationTest.java
File metadata and controls
117 lines (101 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import java.util.Collection;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
public class AnnotationTest {
@Nested
public class Test1 { // COMPLIANT: Inner test class has `@Nested`
@Test
public void test() {
}
}
// NON_COMPLIANT: Inner test class is missing `@Nested`
public class Test2_Test { // $ Alert
@Test
public void test() {
}
}
// NON_COMPLIANT: Inner test class is missing `@Nested`
public class Test2_RepeatedTest { // $ Alert
@RepeatedTest(2)
public void test() {
}
}
// NON_COMPLIANT: Inner test class is missing `@Nested`
public class Test2_ParameterizedTest { // $ Alert
@ParameterizedTest
@ValueSource(strings = { "" })
public void test(String s) {
}
}
// NON_COMPLIANT: Inner test class is missing `@Nested`
public class Test2_TestFactory { // $ Alert
@TestFactory
Collection<Object> test() {
return null;
}
}
// NON_COMPLIANT: Inner test class is missing `@Nested`
public class Test2_TestTemplate { // $ Alert
@TestTemplate
public void test() {
}
}
public class Test3 { // COMPLIANT: Since it is empty, it is not a test class
}
public class Test4 { // COMPLIANT: Since no methods have `@Test`, it is not a test class
public void f() {
}
public void g() {
}
public void h() {
}
}
public static class Test5 { // COMPLIANT: Static nested test classes don't need `@Nested`
@Test
public void test() {
}
}
// COMPLIANT: Invalid to use `@Nested` on a static class, but
// this matter is out of scope (see QHelp Implementation Notes)
@Nested
public static class Test6 {
@Test
public void test() {
}
}
public abstract class Test7 { // COMPLIANT: Abstract nested test classes don't need `@Nested`
@Test
public void test() {
}
}
interface Test8 {
}
public void f() {
// COMPLIANT: anonymous classes are not considered as inner test
// classes by JUnit and therefore don't need `@Nested`
new Test8() {
@Test
public void test() {
}
};
// COMPLIANT: local classes are not considered as inner test
// classes by JUnit and therefore don't need `@Nested`
class Test9 {
@Test
void test() {
}
}
}
// COMPLIANT: private classes are not considered as inner test
// classes by JUnit and therefore don't need `@Nested`
private class Test10 {
@Test
public void test() {
}
}
}