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); }
void applyClassNamePredicate(Predicate<String> classNamePredicate, TestDescriptor engineDescriptor) { TestDescriptor.Visitor filteringVisitor = descriptor -> { if (descriptor instanceof ClassTestDescriptor && !includeClass((ClassTestDescriptor) descriptor, classNamePredicate)) { descriptor.removeFromHierarchy(); } }; engineDescriptor.accept(filteringVisitor); }
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; }
private Deque<Description> determinePath(RunnerTestDescriptor runnerTestDescriptor, Optional<? extends TestDescriptor> identifiedTestDescriptor) { Deque<Description> path = new ArrayDeque<>(); Optional<? extends TestDescriptor> current = identifiedTestDescriptor; while (current.isPresent() && !current.get().equals(runnerTestDescriptor)) { path.addFirst(((VintageTestDescriptor) current.get()).getDescription()); current = current.get().getParent(); } return path; }
private Set<Description> determineDescendants(Optional<? extends TestDescriptor> identifiedTestDescriptor) { // @formatter:off return identifiedTestDescriptor.map( testDescriptor -> testDescriptor .getDescendants() .stream() .map(VintageTestDescriptor.class::cast) .map(VintageTestDescriptor::getDescription) .collect(toSet())) .orElseGet(Collections::emptySet); // @formatter:on }
private void notifyFinishedRecursively(TestDescriptor descriptor, Consumer<TestDescriptor> visitor) { Optional<TestDescriptor> parent = descriptor.getParent(); while (parent.isPresent()) { TestDescriptor actualParent = parent.get(); AtomicInteger integer = expectedContainerCount.computeIfAbsent(actualParent, it -> { AtomicInteger childCount = new AtomicInteger(0); it.accept(item -> { if (item instanceof BenchmarkMethodDescriptor || item instanceof BenchmarkFixtureDescriptor) { childCount.incrementAndGet(); } }); return childCount; }); if (integer.decrementAndGet() == 0) { visitor.accept(actualParent); } parent = actualParent.getParent(); } }
private void pruneTree(TestDescriptor rootDescriptor) { rootDescriptor.accept(TestDescriptor::prune); }
+ "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()));
/** * Accept a {@link Visitor} to the subtree starting with this descriptor. * * @param visitor the {@code Visitor} to accept; never {@code null} */ default void accept(Visitor visitor) { Preconditions.notNull(visitor, "Visitor must not be null"); visitor.visit(this); // Create a copy of the set in order to avoid a ConcurrentModificationException new LinkedHashSet<>(this.getChildren()).forEach(child -> child.accept(visitor)); }
/** * Get the immutable set of all <em>descendants</em> of this descriptor. * * <p>A <em>descendant</em> is a child of this descriptor or a child of one of * its children, recursively. * * @see #getChildren() */ default Set<? extends TestDescriptor> getDescendants() { Set<TestDescriptor> descendants = new LinkedHashSet<>(); descendants.addAll(getChildren()); for (TestDescriptor child : getChildren()) { descendants.addAll(child.getDescendants()); } return Collections.unmodifiableSet(descendants); }
private void executeAllChildren(RunnerExecutor runnerExecutor, TestDescriptor engineTestDescriptor) { // @formatter:off engineTestDescriptor.getChildren() .stream() .map(RunnerTestDescriptor.class::cast) .forEach(runnerExecutor::execute); // @formatter:on }
/** * Remove this descriptor from the hierarchy unless it is a root or contains * tests. * * <p>A concrete {@link TestEngine} may override this method in order to * implement a different algorithm or to skip pruning altogether. * * @see #isRoot() * @see #containsTests(TestDescriptor) * @see #removeFromHierarchy() */ default void prune() { if (!isRoot() && !containsTests(this)) { removeFromHierarchy(); } }
/** * Determine if the supplied descriptor (or any of its descendants) * {@linkplain TestDescriptor#isTest() is a test} or * {@linkplain TestDescriptor#mayRegisterTests() may potentially register * tests dynamically}. * * @param testDescriptor the {@code TestDescriptor} to check for tests; never * {@code null} * @return {@code true} if the descriptor is a test, contains tests, or may * later register tests dynamically */ static boolean containsTests(TestDescriptor testDescriptor) { Preconditions.notNull(testDescriptor, "TestDescriptor must not be null"); return testDescriptor.isTest() || testDescriptor.mayRegisterTests() || testDescriptor.getChildren().stream().anyMatch(TestDescriptor::containsTests); }
@Override public String getDisplayName() { return getTestDescriptor().getDisplayName(); }
@SuppressWarnings("unchecked") private Optional<TestDescriptor> findTestDescriptorByUniqueId(UniqueId uniqueId) { return (Optional<TestDescriptor>) this.engineDescriptor.findByUniqueId(uniqueId); }
public TestDescriptor build(TestDescriptor parent) { TestDescriptor descriptor = createDescriptor(parent); for (TestDescriptorBuilder child : children) { descriptor.addChild(child.build(descriptor)); } return descriptor; }
@Override public final Set<TestTag> getTags() { // return modifiable copy Set<TestTag> allTags = new LinkedHashSet<>(this.tags); getParent().ifPresent(parentDescriptor -> allTags.addAll(parentDescriptor.getTags())); return allTags; }
@Example void staticMethodIsSkipped() { LauncherDiscoveryRequest discoveryRequest = request().selectors(selectMethod(SimpleExampleTests.class, "staticExample")) .build(); TestDescriptor engineDescriptor = discoverTests(discoveryRequest); assertThat(engineDescriptor.getDescendants().size()).isEqualTo(2); assertThat(count(engineDescriptor, isSkipDecorator)).isEqualTo(1); }
private void pruneTree(TestDescriptor rootDescriptor) { rootDescriptor.accept(TestDescriptor::prune); }