/** * Returns the {@link TestDescriptor} that represents the specified * {@link Description}. * * <p>There are edge cases where multiple {@link Description Descriptions} * with the same {@code uniqueId} exist, e.g. when using overloaded methods * to define {@linkplain org.junit.experimental.theories.Theory theories}. * In this case, we try to find the correct {@link TestDescriptor} by * checking for object identity on the {@link Description} it represents. * * @param description the {@code Description} to look up */ Optional<VintageTestDescriptor> lookupTestDescriptor(Description description) { List<VintageTestDescriptor> descriptors = descriptionToDescriptors.get(description); if (descriptors == null) { return Optional.empty(); } if (descriptors.size() == 1) { return Optional.of(getOnlyElement(descriptors)); } // @formatter:off return descriptors.stream() .filter(testDescriptor -> description == testDescriptor.getDescription()) .findFirst(); // @formatter:on }
@SuppressWarnings("unchecked") private Stream<DynamicNode> toDynamicNodeStream(Object testFactoryMethodResult) { if (testFactoryMethodResult instanceof DynamicNode) { return Stream.of((DynamicNode) testFactoryMethodResult); } try { return (Stream<DynamicNode>) CollectionUtils.toStream(testFactoryMethodResult); } catch (PreconditionViolationException ex) { throw invalidReturnTypeException(ex); } }
public static List<Field> findAnnotatedFields(Class<?> clazz, Class<?> fieldType, Class<? extends Annotation> annotationType) { return getDeclaredFields(clazz).stream().filter((field) -> { return fieldType.isAssignableFrom(field.getType()) && isAnnotated(field, annotationType); }).collect(CollectionUtils.toUnmodifiableList()); }
public static List<Field> findAnnotatedFields(Class<?> clazz, Class<?> fieldType, Class<? extends Annotation> annotationType) { return getDeclaredFields(clazz).stream().filter((field) -> { return fieldType.isAssignableFrom(field.getType()) && isAnnotated(field, annotationType); }).collect(CollectionUtils.toUnmodifiableList()); }
private static MethodSource toMethodSource(Class<?> testClass, String methodName) { if (methodName.contains("[") && methodName.endsWith("]")) { // special case for parameterized tests return toMethodSource(testClass, methodName.substring(0, methodName.indexOf("["))); } else { List<Method> methods = findMethods(testClass, where(Method::getName, isEqual(methodName))); return (methods.size() == 1) ? MethodSource.from(testClass, getOnlyElement(methods)) : null; } }
.map(ClasspathRootSelector::new) .collect(toUnmodifiableList());
private void printReportEntry(String indent, ReportEntry reportEntry) { out.println(); out.print(indent); out.print(reportEntry.getTimestamp()); Set<Map.Entry<String, String>> entries = reportEntry.getKeyValuePairs().entrySet(); if (entries.size() == 1) { printReportEntry(" ", getOnlyElement(entries)); return; } for (Map.Entry<String, String> entry : entries) { out.println(); printReportEntry(indent + theme.blank(), entry); } }
/** * Create a list of {@code ModuleSelectors} for the supplied module names. * * <p>The unnamed module is not supported. * * @param moduleNames the module names to select; never {@code null}, never * containing {@code null} or blank * @since 1.1 * @see ModuleSelector */ @API(status = EXPERIMENTAL, since = "1.1") public static List<ModuleSelector> selectModules(Set<String> moduleNames) { Preconditions.notNull(moduleNames, "moduleNames must not be null"); Preconditions.containsNoNullElements(moduleNames, "individual module name must not be null"); // @formatter:off return moduleNames.stream() .map(DiscoverySelectors::selectModule) // unmodifiable since this is a public, non-internal method .collect(toUnmodifiableList()); // @formatter:on }
/** * Return a filter that will include elements if and only if all of the * filters in the supplied collection of {@link Filter filters} include it. * * <p>If the collection is empty, the returned filter will include all * elements it is asked to filter. * * @param filters the collection of filters to compose; never {@code null} * @see #composeFilters(Filter...) */ static <T> Filter<T> composeFilters(Collection<? extends Filter<T>> filters) { Preconditions.notNull(filters, "Filters must not be null"); if (filters.isEmpty()) { return alwaysIncluded(); } if (filters.size() == 1) { return getOnlyElement(filters); } return new CompositeFilter<>(filters); }