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 Set<TestDescriptor> tryToResolveWithResolver(AnnotatedElement element, TestDescriptor parent, ElementResolver resolver) { Set<TestDescriptor> resolvedDescriptors = resolver.resolveElement(element, parent); Set<TestDescriptor> result = new LinkedHashSet<>(); resolvedDescriptors.forEach(testDescriptor -> { Optional<TestDescriptor> existingTestDescriptor = findTestDescriptorByUniqueId( testDescriptor.getUniqueId()); if (existingTestDescriptor.isPresent()) { result.add(existingTestDescriptor.get()); } else { parent.addChild(testDescriptor); result.add(testDescriptor); } }); return result; }
@Override public String getUniqueId() { return getTestDescriptor().getUniqueId().toString(); }
/** * 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 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()); }
@Override public final boolean equals(Object other) { if (other == null) { return false; } if (this.getClass() != other.getClass()) { return false; } TestDescriptor that = (TestDescriptor) other; return this.getUniqueId().equals(that.getUniqueId()); }
@Override public Optional<TestDescriptor> resolveUniqueId(Segment segment, TestDescriptor parent) { if (!segment.getType().equals(SEGMENT_TYPE)) { return Optional.empty(); } if (!(parent instanceof BenchmarkClassDescriptor)) { return Optional.empty(); } BenchmarkClassDescriptor descriptor = (BenchmarkClassDescriptor) parent; return findMethod(segment, parent.getUniqueId(), descriptor.getBenchmarkClass()); }
@Override public Set<TestDescriptor> resolveElement(AnnotatedElement element, TestDescriptor parent) { if (!(element instanceof Method)) { return Collections.emptySet(); } if (!(parent instanceof BenchmarkClassDescriptor)) { return Collections.emptySet(); } Method method = (Method) element; BenchmarkClassDescriptor classDescriptor = (BenchmarkClassDescriptor) parent; if (!method.getDeclaringClass().isAssignableFrom(classDescriptor.getJavaClass())) { return Collections.emptySet(); } return findMethod(parent.getUniqueId(), classDescriptor.getBenchmarkClass(), method).map(Collections::singleton) .orElseGet(Collections::emptySet); }
private Set<TestDescriptor> tryToResolveWithResolver(AnnotatedElement element, TestDescriptor parent, ElementResolver resolver) { Set<TestDescriptor> resolvedDescriptors = resolver.resolveElement(element, parent); Set<TestDescriptor> result = new LinkedHashSet<>(); resolvedDescriptors.forEach(testDescriptor -> { Optional<TestDescriptor> existingTestDescriptor = findTestDescriptorByUniqueId(testDescriptor.getUniqueId()); if (existingTestDescriptor.isPresent()) { result.add(existingTestDescriptor.get()); } else { parent.addChild(testDescriptor); result.add(testDescriptor); } }); return result; }
/** * 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; }
@Override public String getUniqueId() { return getBenchmarkDescriptor().getUniqueId().toString(); }
@Override public Set<TestDescriptor> resolveElement(AnnotatedElement element, TestDescriptor parent) { if (!(element instanceof Method)) { return Collections.emptySet(); } if (!(parent instanceof ParametrizedBenchmarkMethodDescriptor)) { return Collections.emptySet(); } ParametrizedBenchmarkMethodDescriptor parentDescriptor = (ParametrizedBenchmarkMethodDescriptor) parent; Method method = (Method) element; if (!parentDescriptor.isUnderlyingMethod(method)) { return Collections.emptySet(); } return findFixtures(parent.getUniqueId(), parentDescriptor.getParametrizedMethod()); }
private UniqueId testId(TestDescriptor descriptor, String value) { return descriptor.getUniqueId().append(JqwikUniqueIDs.PROPERTY_SEGMENT_TYPE, value); }
private void reportCompletion() { if (throwableCollector.isEmpty() && skipResult.isSkipped()) { try { node.nodeSkipped(context, testDescriptor, skipResult); } catch (Throwable throwable) { BlacklistedExceptions.rethrowIfBlacklisted(throwable); logger.debug(throwable, () -> String.format("Failed to invoke nodeSkipped() on Node %s", testDescriptor.getUniqueId())); } taskContext.getListener().executionSkipped(testDescriptor, skipResult.getReason().orElse("<unknown>")); return; } if (!started) { // Call executionStarted first to comply with the contract of EngineExecutionListener. taskContext.getListener().executionStarted(testDescriptor); } try { node.nodeFinished(context, testDescriptor, throwableCollector.toTestExecutionResult()); } catch (Throwable throwable) { BlacklistedExceptions.rethrowIfBlacklisted(throwable); logger.debug(throwable, () -> String.format("Failed to invoke nodeFinished() on Node %s", testDescriptor.getUniqueId())); } taskContext.getListener().executionFinished(testDescriptor, throwableCollector.toTestExecutionResult()); throwableCollector = null; }
+ "current thread. JUnit has cleared the flag, but you may wish to investigate " + "why the flag was not cleared by user code.", this.testDescriptor.getDisplayName(), this.testDescriptor.getUniqueId()));
private TestDescriptor createDescriptor(TestDescriptor parent) { if (element instanceof JqwikTestEngine) return new JqwikEngineDescriptor(engineId()); if (element instanceof Class) { Class<?> containerClass = (Class<?>) this.element; return new ContainerClassDescriptor(uniqueIdForClassContainer(containerClass), containerClass, false); } if (element instanceof Method) { Method targetMethod = (Method) this.element; Optional<Property> optionalProperty = AnnotationSupport.findAnnotation(targetMethod, Property.class); if (optionalProperty.isPresent()) { Property property = optionalProperty.get(); UniqueId uniqueId = JqwikUniqueIDs.appendProperty(parent.getUniqueId(), targetMethod); PropertyConfiguration propertyConfig = PropertyConfiguration.from(property, PropertyDefaultValues.with(TRIES, MAX_DISCARD_RATIO, AFTER_FAILURE), null, null); return new PropertyMethodDescriptor(uniqueId, targetMethod, targetMethod.getDeclaringClass(), propertyConfig); } } throw new JqwikException("Cannot build descriptor for " + element.toString()); } }