@Override public Optional<TestDescriptor> resolveUniqueId(UniqueId.Segment segment, TestDescriptor parent) { if (!segment.getType().equals(getSegmentType())) { return Optional.empty(); } if (!requiredParentType().isInstance(parent)) { return Optional.empty(); } String className = getClassName(parent, segment.getValue()); Optional<Class<?>> optionalContainerClass = ReflectionUtils.tryToLoadClass(className).toOptional(); if (!optionalContainerClass.isPresent()) { return Optional.empty(); } Class<?> containerClass = optionalContainerClass.get(); if (!isPotentialCandidate(containerClass)) { return Optional.empty(); } UniqueId uniqueId = createUniqueId(containerClass, parent); return Optional.of(resolveClass(containerClass, uniqueId)); }
@Override public Optional<TestDescriptor> resolveUniqueId(UniqueId.Segment segment, TestDescriptor parent) { if (!segment.getType().equals(SEGMENT_TYPE)) { return Optional.empty(); } if (!requiredParentType().isInstance(parent)) { return Optional.empty(); } String className = getClassName(parent, segment.getValue()); Optional<Class<?>> optionalContainerClass = ReflectionUtils.loadClass(className); if (!optionalContainerClass.isPresent()) { return Optional.empty(); } Class<?> containerClass = optionalContainerClass.get(); if (!isPotentialCandidate(containerClass)) { return Optional.empty(); } UniqueId uniqueId = createUniqueId(containerClass, parent); return Optional.of(resolveClass(containerClass, uniqueId)); }
/** * 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)); }
@Override public Optional<TestDescriptor> resolveUniqueId(Segment segment, TestDescriptor parent) { if (!segment.getType().equals(SEGMENT_TYPE)) { return Optional.empty(); } if (!(parent instanceof ParametrizedBenchmarkMethodDescriptor)) { return Optional.empty(); } ParametrizedBenchmarkMethodDescriptor parentDescriptor = (ParametrizedBenchmarkMethodDescriptor) parent; return findTestDescriptor(segment.getValue(), parentDescriptor.getUniqueId(), parentDescriptor.getParametrizedMethod()); }
public static Condition<ExecutionEvent> uniqueIdSubstring(String uniqueIdSubstring) { Predicate<UniqueId.Segment> predicate = segment -> { String text = segment.getType() + ":" + segment.getValue(); return text.contains(uniqueIdSubstring); }; return new Condition<>( byTestDescriptor( where(TestDescriptor::getUniqueId, uniqueId -> uniqueId.getSegments().stream().anyMatch(predicate))), "descriptor with uniqueId substring \"%s\"", uniqueIdSubstring); }
private Optional<TestDescriptor> findMethod(Segment segment, UniqueId parentId, BenchmarkClass benchmarkClass) { return benchmarkClass.getChildren().stream() // .filter(MethodAware.class::isInstance) // .filter(it -> { Method method = ((MethodAware) it).getMethod(); String id = BenchmarkMethodDescriptor.describeMethodId(method); return segment.getValue().equals(id); }) // .map(it -> createDescriptor(parentId, it)) // .findFirst(); }
private void writeXmlReportInCaseOfRoot(TestIdentifier testIdentifier) { if (isRoot(testIdentifier)) { String rootName = UniqueId.parse(testIdentifier.getUniqueId()).getSegments().get(0).getValue(); writeXmlReportSafely(testIdentifier, rootName); } }
@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()); }
/** * Create a root unique ID from the supplied {@code segmentType} and * {@code value} using the default format. * * @param segmentType the segment type; never {@code null} or blank * @param value the value; never {@code null} or blank * @see #forEngine(String) */ public static UniqueId root(String segmentType, String value) { return new UniqueId(UniqueIdFormat.getDefault(), new Segment(segmentType, value)); }
/** * Get the engine ID stored in this {@code UniqueId}, if available. * * @see #forEngine(String) */ public final Optional<String> getEngineId() { return getRoot().filter(segment -> segment.getType().equals(ENGINE_SEGMENT_TYPE)).map(Segment::getValue); }
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); }
@Override public Optional<TestDescriptor> resolveUniqueId(UniqueId.Segment segment, TestDescriptor parent) { if (!segment.getType().equals(this.segmentType)) { return Optional.empty(); } if (!(parent instanceof ClassTestDescriptor)) { return Optional.empty(); } Optional<Method> optionalMethod = findMethod(segment, (ClassTestDescriptor) parent); if (!optionalMethod.isPresent()) { return Optional.empty(); } Method method = optionalMethod.get(); if (!isRelevantMethod(method)) { return Optional.empty(); } return Optional.of(createTestDescriptor(parent, method)); }
private Optional<Method> findMethod(UniqueId.Segment segment, ClassTestDescriptor parent) { return methodFinder.findMethod(segment.getValue(), parent.getTestClass()); }
private Optional<String> determineTestClassName(UniqueId uniqueId) { Segment runnerSegment = uniqueId.getSegments().get(1); // skip engine node 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(); }