Skip to content

Commit

Permalink
[JUnit Platform Engine] Check unique id prefix rather then engine id (#…
Browse files Browse the repository at this point in the history
…2198)

`UniqueId.getEngine` is not guaranteed to return `cucumber`. Another engine may
launch a discovery request for Cucumber. The engine id in this case would be
`[engine:suite][engine:cucumber]`.
  • Loading branch information
mpkorstanje authored Jan 17, 2021
1 parent 605c949 commit 31c1361
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void resolveClasspathRoot(ClasspathRootSelector selector) {
void resolveUniqueId(UniqueIdSelector uniqueIdSelector) {
UniqueId uniqueId = uniqueIdSelector.getUniqueId();
// Ignore any ids not from our own engine
if (!engineDescriptor.getUniqueId().getEngineId().equals(uniqueId.getEngineId())) {
if (!uniqueId.hasPrefix(engineDescriptor.getUniqueId())) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
import java.util.logging.LogRecord;
import java.util.stream.Collectors;

import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toSet;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClasspathResource;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClasspathRoots;
Expand Down Expand Up @@ -238,6 +238,14 @@ void resolveRequestWithPackageSelector() {
assertEquals(5, testDescriptor.getChildren().size());
}

@Test
void ignoreRequestWithUniqueIdSelectorFromDifferentEngine() {
DiscoverySelector selector = selectUniqueId(UniqueId.forEngine("not-cucumber"));
EngineDiscoveryRequest discoveryRequest = new SelectorRequest(selector);
resolver.resolveSelectors(discoveryRequest, testDescriptor);
assertTrue(testDescriptor.getDescendants().isEmpty());
}

@Test
void resolveRequestWithUniqueIdSelectorFromClasspath() {
DiscoverySelector resource = selectPackage("io.cucumber.junit.platform.engine");
Expand Down

0 comments on commit 31c1361

Please sign in to comment.