org.junit.jupiter.api.DynamicContainer Maven / Gradle / Ivy
Show all versions of junit-jupiter-api Show documentation
/*
* Copyright 2015-2018 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v20.html
*/
package org.junit.jupiter.api;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.apiguardian.api.API;
import org.junit.platform.commons.util.Preconditions;
/**
* A {@code DynamicContainer} is a container generated at runtime.
*
* It is composed of a {@linkplain #getDisplayName display name} and an
* iterable of {@link DynamicNode}s.
*
*
Instances of {@code DynamicContainer} must be generated by factory methods
* annotated with {@link TestFactory @TestFactory}.
*
* @since 5.0
*/
@API(status = EXPERIMENTAL, since = "5.0")
public class DynamicContainer extends DynamicNode {
/**
* Factory for creating a new {@code DynamicContainer} for the supplied display
* name and a collection of dynamic nodes.
*
*
The collection of dynamic nodes must not contain {@code null} elements.
*
* @param displayName the display name for the dynamic container; never
* {@code null} or blank
* @param dynamicNodes collection of dynamic nodes to execute;
* never {@code null}
*/
public static DynamicContainer dynamicContainer(String displayName, Iterable extends DynamicNode> dynamicNodes) {
return new DynamicContainer(displayName, StreamSupport.stream(dynamicNodes.spliterator(), false));
}
/**
* Factory for creating a new {@code DynamicContainer} for the supplied display
* name and a stream of dynamic nodes.
*
*
The stream of dynamic nodes must not contain {@code null} elements.
*
* @param displayName the display name for the dynamic container; never
* {@code null} or blank
* @param dynamicNodes stream of dynamic nodes to execute;
* never {@code null}
*/
public static DynamicContainer dynamicContainer(String displayName, Stream extends DynamicNode> dynamicNodes) {
return new DynamicContainer(displayName, dynamicNodes);
}
private final Stream extends DynamicNode> children;
private DynamicContainer(String displayName, Stream extends DynamicNode> children) {
super(displayName);
Preconditions.notNull(children, "children must not be null");
this.children = children;
}
/**
* Get the {@link Stream} of {@link DynamicNode DynamicNodes} associated
* with this container.
*/
public Stream extends DynamicNode> getChildren() {
return children;
}
}