1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.junitplatform;
20
21 import java.util.List;
22 import java.util.stream.Stream;
23
24 import org.junit.Test;
25 import org.junit.jupiter.api.DynamicTest;
26 import org.junit.jupiter.api.Nested;
27 import org.junit.jupiter.api.TestFactory;
28 import org.junit.platform.engine.Filter;
29 import org.junit.platform.launcher.core.LauncherFactory;
30
31 import static java.util.Collections.emptyList;
32 import static org.junit.jupiter.api.Assertions.assertFalse;
33 import static org.junit.jupiter.api.Assertions.assertTrue;
34
35
36
37
38
39
40 public class TestPlanScannerFilterTest {
41
42 @Test
43 public void emptyClassIsNotAccepted() {
44 assertFalse(newFilter().accept(EmptyClass.class), "does not accept empty class");
45 }
46
47 @Test
48 public void classWithNoTestMethodsIsNotAccepted() {
49 assertFalse(newFilter().accept(ClassWithMethods.class), "does not accept class with no @Test methods");
50 }
51
52 @Test
53 public void classWithTestMethodsIsAccepted() {
54 assertTrue(newFilter().accept(ClassWithTestMethods.class));
55 }
56
57 @Test
58 public void classWithNestedTestClassIsAccepted() {
59 assertTrue(newFilter().accept(ClassWithNestedTestClass.class));
60 }
61
62 @Test
63 public void classWithDeeplyNestedTestClassIsAccepted() {
64 assertTrue(newFilter().accept(ClassWithDeeplyNestedTestClass.class));
65 }
66
67 @Test
68 public void classWithTestFactoryIsAccepted() {
69 assertTrue(newFilter().accept(ClassWithTestFactory.class));
70 }
71
72 @Test
73 public void classWithNestedTestFactoryIsAccepted() {
74 assertTrue(newFilter().accept(ClassWithNestedTestFactory.class));
75 }
76
77 private static TestPlanScannerFilter newFilter() {
78 return new TestPlanScannerFilter(LauncherFactory.create(), new Filter<?>[0]);
79 }
80
81 static class EmptyClass {}
82
83 static class ClassWithMethods {
84
85 void method1() {}
86
87 void method2() {}
88 }
89
90 static class ClassWithTestMethods {
91
92 @Test
93 void test1() {}
94
95 @org.junit.jupiter.api.Test
96 public void test2() {}
97 }
98
99 static class ClassWithNestedTestClass {
100
101 void method() {}
102
103 @Nested
104 class TestClass {
105
106 @org.junit.jupiter.api.Test
107 void test1() {}
108 }
109 }
110
111 static class ClassWithDeeplyNestedTestClass {
112
113 @Nested
114 class Level1 {
115
116 @Nested
117 class Level2 {
118
119 @Nested
120 class TestClass {
121
122 @org.junit.jupiter.api.Test
123 void test1() {}
124 }
125 }
126 }
127 }
128
129 static class ClassWithTestFactory {
130
131 @TestFactory
132 Stream<DynamicTest> tests() {
133 return Stream.empty();
134 }
135 }
136
137 static class ClassWithNestedTestFactory {
138
139 @Nested
140 class TestClass {
141
142 @TestFactory
143 List<DynamicTest> tests() {
144 return emptyList();
145 }
146 }
147 }
148 }