|
2 | 2 |
|
3 | 3 | import static aQute.tester.bundle.engine.BundleEngine.CHECK_UNRESOLVED; |
4 | 4 | import static org.assertj.core.api.Assertions.allOf; |
| 5 | +import static org.assertj.core.api.Assertions.assertThat; |
5 | 6 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
6 | 7 | import static org.junit.platform.commons.util.FunctionUtils.where; |
7 | 8 | import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; |
|
22 | 23 |
|
23 | 24 | import java.io.PrintWriter; |
24 | 25 | import java.lang.reflect.Method; |
| 26 | +import java.util.ArrayList; |
25 | 27 | import java.util.List; |
26 | 28 | import java.util.function.Supplier; |
| 29 | +import java.util.stream.Collectors; |
27 | 30 |
|
| 31 | +import org.assertj.core.api.AutoCloseableSoftAssertions; |
28 | 32 | import org.assertj.core.api.Condition; |
29 | 33 | import org.junit.jupiter.api.AfterEach; |
30 | 34 | import org.junit.jupiter.api.BeforeEach; |
|
40 | 44 | import org.junit.platform.engine.TestEngine; |
41 | 45 | import org.junit.platform.engine.TestExecutionResult; |
42 | 46 | import org.junit.platform.engine.UniqueId; |
| 47 | +import org.junit.platform.engine.discovery.ClassSelector; |
43 | 48 | import org.junit.platform.engine.support.descriptor.EngineDescriptor; |
44 | 49 | import org.junit.platform.testkit.engine.EngineTestKit; |
45 | 50 | import org.junit.platform.testkit.engine.EngineTestKit.Builder; |
@@ -119,6 +124,14 @@ public void setUp(TestInfo info) { |
119 | 124 | } |
120 | 125 | } |
121 | 126 |
|
| 127 | + protected void startLaunchpadNoEngines() { |
| 128 | + builder = new LaunchpadBuilder(); |
| 129 | + builder.bndrun("bundleenginetest-noengines.bndrun") |
| 130 | + .excludeExport("aQute.tester.bundle.engine") |
| 131 | + .excludeExport("aQute.tester.bundle.engine.discovery"); |
| 132 | + startLaunchpad(); |
| 133 | + } |
| 134 | + |
122 | 135 | protected void startLaunchpad() { |
123 | 136 | if (DEBUG) { |
124 | 137 | builder.debug(); |
@@ -174,11 +187,7 @@ public void outsideOfFramework_hasInitializationError() throws Exception { |
174 | 187 | @Test |
175 | 188 | @Tag(CUSTOM_LAUNCH) |
176 | 189 | public void withNoEngines_reportsMissingEngines_andSkipsMainTests() throws Exception { |
177 | | - builder = new LaunchpadBuilder(); |
178 | | - builder = builder.bndrun("bundleenginetest-noengines.bndrun") |
179 | | - .excludeExport("aQute.tester.bundle.engine") |
180 | | - .excludeExport("aQute.tester.bundle.engine.discovery"); |
181 | | - startLaunchpad(); |
| 190 | + startLaunchpadNoEngines(); |
182 | 191 |
|
183 | 192 | Bundle testBundle = testBundler.startTestBundle(JUnit4Test.class); |
184 | 193 |
|
@@ -270,11 +279,7 @@ public void execute(ExecutionRequest request) { |
270 | 279 | @Test |
271 | 280 | @Tag(CUSTOM_LAUNCH) |
272 | 281 | public void withEngineWithServiceSpecCommentsAndWhitespace_loadsEngine() throws Exception { |
273 | | - builder = new LaunchpadBuilder(); |
274 | | - builder.bndrun("bundleenginetest-noengines.bndrun") |
275 | | - .excludeExport("aQute.tester.bundle.engine") |
276 | | - .excludeExport("aQute.tester.bundle.engine.discovery"); |
277 | | - startLaunchpad(); |
| 282 | + startLaunchpadNoEngines(); |
278 | 283 |
|
279 | 284 | Bundle engineBundle = testBundler.bundleWithEE() |
280 | 285 | .includeResource("META-INF/services/" + TestEngine.class.getName()) |
@@ -1126,10 +1131,9 @@ public void testClass_withBothJUnit3And4_raisesAnError() { |
1126 | 1131 | .debug(debugStr) |
1127 | 1132 | .assertThatEvents() |
1128 | 1133 | .haveExactly(1, |
1129 | | - event(uniqueIdSubstring(test.getSymbolicName()), testClass(JUnit3And4Test.class), |
1130 | | - finishedWithFailure(instanceOf(JUnitException.class), |
1131 | | - message( |
1132 | | - x -> x.matches("^(?si).*TestCase.*JUnit 4 annotations.*annotations will be ignored.*$"))))); |
| 1134 | + event(uniqueIdSubstring(test.getSymbolicName()), testClass(JUnit3And4Test.class), finishedWithFailure( |
| 1135 | + instanceOf(JUnitException.class), |
| 1136 | + message(x -> x.matches("^(?si).*TestCase.*JUnit 4 annotations.*annotations will be ignored.*$"))))); |
1133 | 1137 |
|
1134 | 1138 | } |
1135 | 1139 |
|
@@ -1178,4 +1182,71 @@ public void testClass_withBothJUnit3AndOtherJUnit_doesntRaiseAnError() { |
1178 | 1182 | .assertThatEvents() |
1179 | 1183 | .haveExactly(0, finishedWithFailure(instanceOf(JUnitException.class))); |
1180 | 1184 | } |
| 1185 | + |
| 1186 | + public static class SubEngine implements TestEngine { |
| 1187 | + |
| 1188 | + static EngineDiscoveryRequest request; |
| 1189 | + |
| 1190 | + @Override |
| 1191 | + public String getId() { |
| 1192 | + return "sub-engine"; |
| 1193 | + } |
| 1194 | + |
| 1195 | + @Override |
| 1196 | + public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) { |
| 1197 | + request = discoveryRequest; |
| 1198 | + return null; |
| 1199 | + } |
| 1200 | + |
| 1201 | + @Override |
| 1202 | + public void execute(ExecutionRequest request) {} |
| 1203 | + } |
| 1204 | + |
| 1205 | + @Test |
| 1206 | + @Tag(CUSTOM_LAUNCH) |
| 1207 | + public void subRequest_resolvesAndRemovesBundleSelectors() throws Exception { |
| 1208 | + startLaunchpadNoEngines(); |
| 1209 | + |
| 1210 | + Bundle engineBundle = testBundler.bundleWithEE() |
| 1211 | + .includeResource("META-INF/services/" + TestEngine.class.getName()) |
| 1212 | + .literal(SubEngine.class.getName()) |
| 1213 | + .addResource(SubEngine.class) |
| 1214 | + .start(); |
| 1215 | + Bundle testBundle = startTestBundle(JUnit4Test.class); |
| 1216 | + |
| 1217 | + EngineDiscoveryRequest request; |
| 1218 | + |
| 1219 | + synchronized (SubEngine.class) { |
| 1220 | + SubEngine.request = null; |
| 1221 | + |
| 1222 | + engineInFramework() |
| 1223 | + .selectors(selectBundle(testBundle)) |
| 1224 | + .execute() |
| 1225 | + .all() |
| 1226 | + .debug(debugStr); |
| 1227 | + request = SubEngine.request; |
| 1228 | + } |
| 1229 | + assertThat(request).isNotNull(); |
| 1230 | + |
| 1231 | + Class<?> junit4TestInBundle = testBundle.loadClass(JUnit4Test.class.getName()); |
| 1232 | + |
| 1233 | + List<Class<?>> selectedClasses = new ArrayList<>(); |
| 1234 | + |
| 1235 | + try (AutoCloseableSoftAssertions softly = new AutoCloseableSoftAssertions()) { |
| 1236 | + softly.assertThat(request.getSelectorsByType(BundleSelector.class)).as("should remove BundleSelectors") |
| 1237 | + .isEmpty(); |
| 1238 | + List<DiscoverySelector> selectors = request.getSelectorsByType(DiscoverySelector.class); |
| 1239 | + softly.assertThat(selectors) |
| 1240 | + .as("size") |
| 1241 | + .hasSize(1); |
| 1242 | + List<Class<?>> actualClasses = selectors.stream() |
| 1243 | + .filter(ClassSelector.class::isInstance) |
| 1244 | + .map(ClassSelector.class::cast) |
| 1245 | + .map(classSelector -> classSelector.getJavaClass()) |
| 1246 | + .collect(Collectors.toList()); |
| 1247 | + softly.assertThat(actualClasses) |
| 1248 | + .as("classes") |
| 1249 | + .containsExactlyInAnyOrder(junit4TestInBundle); |
| 1250 | + } |
| 1251 | + } |
1181 | 1252 | } |
0 commit comments