private void validateWasAtLeastInvokedOnce(int invocationIndex) { Preconditions.condition(invocationIndex > 0, () -> "No supporting " + TestTemplateInvocationContextProvider.class.getSimpleName() + " provided an invocation context"); }
private DynamicContainer(String displayName, URI testSourceUri, Stream<? extends DynamicNode> children) { super(displayName, testSourceUri); Preconditions.notNull(children, "children must not be null"); this.children = children; }
static void assertAll(String heading, Executable... executables) { Preconditions.notEmpty(executables, "executables array must not be null or empty"); Preconditions.containsNoNullElements(executables, "individual executables must not be null"); assertAll(heading, Arrays.stream(executables)); }
DefaultParameterContext(Parameter parameter, int index, Optional<Object> target) { Preconditions.condition(index >= 0, "index must be greater than or equal to zero"); this.parameter = Preconditions.notNull(parameter, "parameter must not be null"); this.index = index; this.target = Preconditions.notNull(target, "target must not be null"); }
public Script(Class<? extends Annotation> annotationType, String annotationAsString, String engine, String source, String reason) { Preconditions.notNull(annotationType, "annotationType must not be null"); Preconditions.notNull(annotationAsString, "annotationAsString must not be null"); Preconditions.notBlank(engine, "engine must not be blank"); Preconditions.notBlank(source, "source must not be blank"); Preconditions.notNull(reason, "reason must not be null"); this.annotationType = annotationType; this.annotationAsString = annotationAsString; this.engine = engine; this.source = source; this.reason = reason; this.hashCode = computeHashCode(); }
DynamicNode(String displayName, URI testSourceUri) { this.displayName = Preconditions.notBlank(displayName, "displayName must not be null or blank"); this.testSourceUri = testSourceUri; }
static void assertAll(String heading, Collection<Executable> executables) { Preconditions.notNull(executables, "executables collection must not be null"); Preconditions.containsNoNullElements(executables, "individual executables must not be null"); assertAll(heading, executables.stream()); }
private DefaultTestInstances(List<Object> instances) { this.instances = Preconditions.notEmpty(instances, "instances must not be empty"); }
private InputStream openInputStream(ExtensionContext context, String resource) { Preconditions.notBlank(resource, "Classpath resource [" + resource + "] must not be null or blank"); Class<?> testClass = context.getRequiredTestClass(); return Preconditions.notNull(inputStreamProvider.apply(testClass, resource), () -> "Classpath resource [" + resource + "] does not exist"); }
/** * Create a {@code PackageSelector} for the supplied package name. * * <p>The default package is represented by an empty string ({@code ""}). * * @param packageName the package name to select; never {@code null} and * never containing whitespace only * @see PackageSelector */ public static PackageSelector selectPackage(String packageName) { Preconditions.notNull(packageName, "Package name must not be null"); Preconditions.condition(packageName.isEmpty() || !packageName.trim().isEmpty(), "Package name must not contain only whitespace"); return new PackageSelector(packageName.trim()); }
private RepeatedTestDisplayNameFormatter displayNameFormatter(RepeatedTest repeatedTest, Method method, String displayName) { String pattern = Preconditions.notBlank(repeatedTest.name().trim(), () -> String.format( "Configuration error: @RepeatedTest on method [%s] must be declared with a non-empty name.", method)); return new RepeatedTestDisplayNameFormatter(pattern, displayName); }
/** * 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 }
OrFilter(Collection<? extends Filter> filters) { this.filters = Preconditions.notEmpty(filters, "filters must not be empty"); }
@Override public Object get(int index) { Preconditions.condition(index >= 0 && index < this.arguments.length, () -> format("index must be >= 0 and < %d", this.arguments.length)); return this.arguments[index]; }
private DynamicTest(String displayName, URI testSourceUri, Executable executable) { super(displayName, testSourceUri); this.executable = Preconditions.notNull(executable, "executable must not be null"); }
/** * Create a new {@code ExclusiveResource}. * * @param key the identifier of the resource; never {@code null} or blank * @param lockMode the lock mode to use to synchronize access to the * resource; never {@code null} */ public ExclusiveResource(String key, LockMode lockMode) { this.key = Preconditions.notBlank(key, "key must not be blank"); this.lockMode = Preconditions.notNull(lockMode, "lockMode must not be null"); }
private ParameterizedTestNameFormatter createNameFormatter(Method templateMethod, String displayName) { ParameterizedTest parameterizedTest = findAnnotation(templateMethod, ParameterizedTest.class).get(); String pattern = Preconditions.notBlank(parameterizedTest.name().trim(), () -> String.format( "Configuration error: @ParameterizedTest on method [%s] must be declared with a non-empty name.", templateMethod)); return new ParameterizedTestNameFormatter(pattern, displayName); }
/** * Return a filter that will include elements if and only if all of the * filters in the supplied array of {@link Filter filters} include it. * * <p>If the array is empty, the returned filter will include all elements * it is asked to filter. * * @param filters the array of filters to compose; never {@code null} * @see #composeFilters(Collection) */ @SafeVarargs @SuppressWarnings("varargs") static <T> Filter<T> composeFilters(Filter<T>... filters) { Preconditions.notNull(filters, "filters array must not be null"); Preconditions.containsNoNullElements(filters, "individual filters must not be null"); if (filters.length == 0) { return alwaysIncluded(); } if (filters.length == 1) { return filters[0]; } return new CompositeFilter<>(asList(filters)); }
/** * Create a namespace which restricts access to data to all extensions * which use the same sequence of {@code parts} for creating a namespace. * * <p>The order of the {@code parts} is significant. * * <p>Internally the {@code parts} are compared using {@link Object#equals(Object)}. */ public static Namespace create(Object... parts) { Preconditions.notEmpty(parts, "parts array must not be null or empty"); Preconditions.containsNoNullElements(parts, "individual parts must not be null"); return new Namespace(parts); }
private List<TestTemplateInvocationContextProvider> validateProviders(ExtensionContext extensionContext, ExtensionRegistry extensionRegistry) { // @formatter:off List<TestTemplateInvocationContextProvider> providers = extensionRegistry.stream(TestTemplateInvocationContextProvider.class) .filter(provider -> provider.supportsTestTemplate(extensionContext)) .collect(toList()); // @formatter:on return Preconditions.notEmpty(providers, () -> String.format("You must register at least one %s that supports @TestTemplate method [%s]", TestTemplateInvocationContextProvider.class.getSimpleName(), getTestMethod())); }