diff --git a/src/main/java/co/helmethair/scalatest/ScalatestEngine.java b/src/main/java/co/helmethair/scalatest/ScalatestEngine.java index 18ac8a4..0df5ff3 100644 --- a/src/main/java/co/helmethair/scalatest/ScalatestEngine.java +++ b/src/main/java/co/helmethair/scalatest/ScalatestEngine.java @@ -13,7 +13,6 @@ import org.junit.platform.engine.discovery.ClassSelector; import org.junit.platform.engine.discovery.UniqueIdSelector; -import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -37,8 +36,8 @@ public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId return runtime.discover(engineDescriptor, Stream.concat( - discoverClassSelectors(discoveryRequest).stream(), - discoverUniqueIdSelectors(discoveryRequest).stream() + discoverClassSelectors(discoveryRequest), + discoverUniqueIdSelectors(discoveryRequest) ).collect(Collectors.toSet()), Thread.currentThread().getContextClassLoader()); } @@ -55,17 +54,16 @@ public void execute(ExecutionRequest executionRequest) { executor.executeTest(executionRequest.getRootTestDescriptor(), reporter); } - private List discoverUniqueIdSelectors(EngineDiscoveryRequest discoveryRequest) { + private Stream discoverUniqueIdSelectors(EngineDiscoveryRequest discoveryRequest) { return discoveryRequest.getSelectorsByType(UniqueIdSelector.class).stream() .map(this::getSuite) .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toList()); + .map(Optional::get); } private Optional getSuite(UniqueIdSelector u) { UniqueId uniqueId = u.getUniqueId(); - if (uniqueId.hasPrefix(UniqueId.forEngine(ID))) { + if (uniqueId.hasPrefix(UniqueId.forEngine(ID)) && uniqueId.getSegments().size() > 1) { UniqueId.Segment segment = uniqueId.getSegments().get(1); if (SUITE_TYPE.equals(segment.getType())) { return Optional.of(segment.getValue()); @@ -74,9 +72,8 @@ private Optional getSuite(UniqueIdSelector u) { return Optional.empty(); } - private List discoverClassSelectors(EngineDiscoveryRequest discoveryRequest) { + private Stream discoverClassSelectors(EngineDiscoveryRequest discoveryRequest) { return discoveryRequest.getSelectorsByType(ClassSelector.class).stream() - .map(ClassSelector::getClassName) - .collect(Collectors.toList()); + .map(ClassSelector::getClassName); } } diff --git a/src/test/java/co/helmethair/scalatest/UniqueIdTest.java b/src/test/java/co/helmethair/scalatest/UniqueIdTest.java index 52d3906..8a86711 100644 --- a/src/test/java/co/helmethair/scalatest/UniqueIdTest.java +++ b/src/test/java/co/helmethair/scalatest/UniqueIdTest.java @@ -9,7 +9,9 @@ public class UniqueIdTest implements TestHelpers { @ParameterizedTest - @CsvSource({"[engine:scalatest]/[suite:tests.NestedTest], 2, 0", + @CsvSource({ + "[engine:scalatest], 0, 0", + "[engine:scalatest]/[suite:tests.NestedTest], 2, 0", // For now, it does not support really executing the selected test, it will execute the whole suite "[engine:scalatest]/[suite:tests.NestedTest]/[test:nested test1], 2, 0", "[engine:scalatest]/[foo:tests.NestedTest], 0, 0",