Skip to content

Commit

Permalink
Merge branch 'main' into bump-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
giurim authored Sep 29, 2022
2 parents b2249fb + 40c73ee commit 749d697
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 7 additions & 10 deletions src/main/java/co/helmethair/scalatest/ScalatestEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
Expand All @@ -55,17 +54,16 @@ public void execute(ExecutionRequest executionRequest) {
executor.executeTest(executionRequest.getRootTestDescriptor(), reporter);
}

private List<String> discoverUniqueIdSelectors(EngineDiscoveryRequest discoveryRequest) {
private Stream<String> 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<String> 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());
Expand All @@ -74,9 +72,8 @@ private Optional<String> getSuite(UniqueIdSelector u) {
return Optional.empty();
}

private List<String> discoverClassSelectors(EngineDiscoveryRequest discoveryRequest) {
private Stream<String> discoverClassSelectors(EngineDiscoveryRequest discoveryRequest) {
return discoveryRequest.getSelectorsByType(ClassSelector.class).stream()
.map(ClassSelector::getClassName)
.collect(Collectors.toList());
.map(ClassSelector::getClassName);
}
}
4 changes: 3 additions & 1 deletion src/test/java/co/helmethair/scalatest/UniqueIdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 749d697

Please sign in to comment.