private UniqueId createUniqueId(Method method, TestDescriptor parent) { String methodId = String.format("%s(%s)", method.getName(), ClassUtils.nullSafeToString(method.getParameterTypes())); return parent.getUniqueId().append(this.segmentType, methodId); }
private RunnerTestDescriptor createCompleteRunnerTestDescriptor(Class<?> testClass, Runner runner, UniqueId engineId) { UniqueId id = engineId.append(SEGMENT_TYPE_RUNNER, testClass.getName()); RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(id, testClass, runner); addChildrenRecursively(runnerTestDescriptor); return runnerTestDescriptor; }
/** * 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; }
protected UniqueId createUniqueId(Class<?> testClass, TestDescriptor parent) { return parent.getUniqueId().append(getSegmentType(), getSegmentValue(testClass)); }
private void addChildrenRecursively(VintageTestDescriptor parent) { List<Description> children = parent.getDescription().getChildren(); // Use LinkedHashMap to preserve order, ArrayList for fast access by index Map<String, List<Description>> childrenByUniqueId = children.stream().collect( groupingBy(uniqueIdReader.andThen(uniqueIdStringifier), LinkedHashMap::new, toCollection(ArrayList::new))); for (Entry<String, List<Description>> entry : childrenByUniqueId.entrySet()) { String uniqueId = entry.getKey(); List<Description> childrenWithSameUniqueId = entry.getValue(); IntFunction<String> uniqueIdGenerator = determineUniqueIdGenerator(uniqueId, childrenWithSameUniqueId); for (int index = 0; index < childrenWithSameUniqueId.size(); index++) { String reallyUniqueId = uniqueIdGenerator.apply(index); Description description = childrenWithSameUniqueId.get(index); UniqueId id = parent.getUniqueId().append(VintageTestDescriptor.SEGMENT_TYPE_TEST, reallyUniqueId); VintageTestDescriptor child = new VintageTestDescriptor(id, description); parent.addChild(child); addChildrenRecursively(child); } } }
private VintageTestDescriptor registerDynamicTestDescriptor(Description description) { // workaround for dynamic children as used by Spock's Runner TestDescriptor parent = findParent(description); UniqueId uniqueId = parent.getUniqueId().append(SEGMENT_TYPE_DYNAMIC, uniqueIdExtractor.apply(description)); VintageTestDescriptor dynamicDescriptor = new VintageTestDescriptor(uniqueId, description); parent.addChild(dynamicDescriptor); testRun.registerDynamicTest(dynamicDescriptor); dynamicTestRegistered(dynamicDescriptor); return dynamicDescriptor; }
private UniqueId createUniqueId(Class<?> benchmarkClass, TestDescriptor parent) { return parent.getUniqueId().append(SEGMENT_TYPE, benchmarkClass.getName()); }
/** * Construct a new {@code UniqueId} by appending a new {@link Segment}, based * on the supplied {@code segmentType} and {@code value}, to the end of this * {@code UniqueId}. * * <p>This {@code UniqueId} will not be modified. * * <p>Neither the {@code segmentType} nor the {@code value} may contain any * of the special characters used for constructing the string representation * of this {@code UniqueId}. * * @param segmentType the type of the segment; never {@code null} or blank * @param value the value of the segment; never {@code null} or blank */ public final UniqueId append(String segmentType, String value) { return append(new Segment(segmentType, value)); }
MockExecutionTask(UniqueId uniqueId, String name) { super(uniqueId.append("task", name), name); }
/** * 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()) { resolvedDescriptor = this.resolvers.stream().map(resolver -> resolver.resolveUniqueId(segment, parent)) .filter(Optional::isPresent).map(Optional::get).findFirst(); resolvedDescriptor.ifPresent(parent::addChild); } resolvedDescriptor.ifPresent(resolvedDescriptors::addLast); } return resolvedDescriptors; }
private Set<TestDescriptor> findFixtures(UniqueId parentId, ParametrizedBenchmarkMethod descriptor) { return descriptor.getChildren().stream().map(it -> { UniqueId uniqueId = parentId.append(SEGMENT_TYPE, it.getDisplayName()); return new BenchmarkFixtureDescriptor(uniqueId, descriptor.getDescriptor(), it); }).collect(Collectors.toSet()); }
private Optional<TestDescriptor> findTestDescriptor(String segmentValue, UniqueId parentId, ParametrizedBenchmarkMethod parametrizedMethod) { return parametrizedMethod.getChildren().stream().filter(it -> { return it.getDisplayName().equals(segmentValue); }).map(it -> { UniqueId uniqueId = parentId.append(SEGMENT_TYPE, it.getDisplayName()); return (TestDescriptor) new BenchmarkFixtureDescriptor(uniqueId, parametrizedMethod.getDescriptor(), it); }).findFirst(); } }
public static UniqueId createUniqueId(UniqueId uniqueId, BenchmarkMethod benchmarkMethod) { return uniqueId.append("method", describeMethodId(benchmarkMethod.getMethod())); }
private UniqueId testId(TestDescriptor descriptor, String value) { return descriptor.getUniqueId().append(JqwikUniqueIDs.PROPERTY_SEGMENT_TYPE, value); }
@Example void propertyWithParams() { ContainerClassDescriptor classDescriptor = buildContainerDescriptor(TestContainer.class); Method method = TestHelper.getMethod(TestContainer.class, "propertyWithParams"); Set<TestDescriptor> descriptors = resolver.resolveElement(method, classDescriptor); assertThat(descriptors).hasSize(1); PropertyMethodDescriptor propertyMethodDescriptor = (PropertyMethodDescriptor) descriptors.iterator().next(); assertThat(propertyMethodDescriptor.getLabel()).isEqualTo("propertyWithParams"); assertThat(propertyMethodDescriptor.getUniqueId()) .isEqualTo(classDescriptor.getUniqueId().append("property", "propertyWithParams(int, java.lang.String)")); }
@Override public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) { this.discoveryRequestForDiscovery = discoveryRequest; this.uniqueIdForDiscovery = uniqueId; UniqueId engineUniqueId = UniqueId.forEngine(ID); TestDescriptorStub engineDescriptor = new TestDescriptorStub(engineUniqueId, ID); TestDescriptorStub testDescriptor = new TestDescriptorStub(engineUniqueId.append("test", "test"), "test"); engineDescriptor.addChild(testDescriptor); return engineDescriptor; }