use of org.junit.platform.engine.UniqueId.Segment in project junit5 by junit-team.
the class JavaElementsResolver method resolveAllSegments.
/**
* Attempt to resolve all segments for the supplied unique ID.
*/
private Deque<TestDescriptor> resolveAllSegments(UniqueId uniqueId) {
List<Segment> segments = uniqueId.getSegments();
Deque<TestDescriptor> resolvedDescriptors = new LinkedList<>();
resolvedDescriptors.addFirst(this.engineDescriptor);
for (int index = 1; index < segments.size() && resolvedDescriptors.size() == index; index++) {
Segment segment = segments.get(index);
TestDescriptor parent = resolvedDescriptors.getLast();
UniqueId partialUniqueId = parent.getUniqueId().append(segment);
Optional<TestDescriptor> resolvedDescriptor = findTestDescriptorByUniqueId(partialUniqueId);
if (!resolvedDescriptor.isPresent()) {
// @formatter:off
resolvedDescriptor = this.resolvers.stream().map(resolver -> resolver.resolveUniqueId(segment, parent)).filter(Optional::isPresent).map(Optional::get).findFirst();
// @formatter:on
resolvedDescriptor.ifPresent(parent::addChild);
}
resolvedDescriptor.ifPresent(resolvedDescriptors::addLast);
}
return resolvedDescriptors;
}
use of org.junit.platform.engine.UniqueId.Segment in project junit5 by junit-team.
the class UniqueIdSelectorResolver method determineTestClassName.
private Optional<String> determineTestClassName(UniqueId uniqueId) {
// skip engine node
Segment runnerSegment = uniqueId.getSegments().get(1);
if (SEGMENT_TYPE_RUNNER.equals(runnerSegment.getType())) {
return Optional.of(runnerSegment.getValue());
}
logger.warn(() -> format("Unresolvable Unique ID (%s): Unique ID segment after engine segment must be of type \"" + SEGMENT_TYPE_RUNNER + "\"", uniqueId));
return Optional.empty();
}
use of org.junit.platform.engine.UniqueId.Segment in project junit5 by junit-team.
the class UniqueIdFormat method createSegment.
private Segment createSegment(String segmentString) throws JUnitException {
Matcher segmentMatcher = this.segmentPattern.matcher(segmentString);
if (!segmentMatcher.matches()) {
throw new JUnitException(String.format("'%s' is not a well-formed UniqueId segment", segmentString));
}
String type = decode(checkAllowed(segmentMatcher.group(1)));
String value = decode(checkAllowed(segmentMatcher.group(2)));
return new Segment(type, value);
}
use of org.junit.platform.engine.UniqueId.Segment in project junit5 by junit-team.
the class ClassSelectorResolver method resolve.
@Override
public Resolution resolve(UniqueIdSelector selector, Context context) {
Segment lastSegment = selector.getUniqueId().getLastSegment();
if (SEGMENT_TYPE_RUNNER.equals(lastSegment.getType())) {
String testClassName = lastSegment.getValue();
Class<?> testClass = //
ReflectionUtils.tryToLoadClass(testClassName).getOrThrow(cause -> new JUnitException("Unknown class: " + testClassName, cause));
return resolveTestClass(testClass, context);
}
return unresolved();
}
use of org.junit.platform.engine.UniqueId.Segment in project junit5 by junit-team.
the class ClassSelectorResolver method resolve.
@Override
public Resolution resolve(UniqueIdSelector selector, Context context) {
UniqueId uniqueId = selector.getUniqueId();
UniqueId engineId = suiteEngineDescriptor.getUniqueId();
List<Segment> resolvedSegments = engineId.getSegments();
// @formatter:off
return uniqueId.getSegments().stream().skip(resolvedSegments.size()).findFirst().filter(suiteSegment -> SuiteTestDescriptor.SEGMENT_TYPE.equals(suiteSegment.getType())).flatMap(ClassSelectorResolver::tryLoadSuiteClass).filter(isSuiteClass).map(suiteClass -> context.addToParent(parent -> newSuiteDescriptor(suiteClass, parent)).map(suite -> uniqueId.equals(suite.getUniqueId()) ? // The uniqueId selector either targeted a class annotated with @Suite;
suite.addDiscoveryRequestFrom(suiteClass) : // or a specific test in that suite
suite.addDiscoveryRequestFrom(uniqueId))).map(ClassSelectorResolver::toResolution).orElseGet(Resolution::unresolved);
// @formatter:on
}
Aggregations