Class TestPlan
- java.lang.Object
-
- org.junit.platform.launcher.TestPlan
-
- Direct Known Subclasses:
InternalTestPlan
@API(status=STABLE, since="1.0") public class TestPlan extends java.lang.ObjectTestPlandescribes the tree of tests and containers as discovered by aLauncher.Tests and containers are represented by
TestIdentifierinstances. The complete set of identifiers comprises a tree-like structure. However, each identifier only stores the unique ID of its parent. This class provides a number of helpful methods to retrieve the parent, children, and descendants of an identifier.While the contained instances of
TestIdentifierare immutable, instances of this class contain mutable state. For example, when a dynamic test is registered at runtime, it is added to the original test plan and reported toTestExecutionListenerimplementations.This class is not intended to be extended by clients.
- Since:
- 1.0
- See Also:
Launcher,TestExecutionListener
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTestPlan.VisitorVisitor forTestIdentifiersin aTestPlan.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<UniqueId,TestIdentifier>allIdentifiersprivate java.util.Map<UniqueId,java.util.Set<TestIdentifier>>childrenprivate ConfigurationParametersconfigurationParametersprivate booleancontainsTestsprivate OutputDirectoryCreatoroutputDirectoryCreatorprivate java.util.Set<TestIdentifier>roots
-
Constructor Summary
Constructors Modifier Constructor Description protectedTestPlan(boolean containsTests, ConfigurationParameters configurationParameters, OutputDirectoryCreator outputDirectoryCreator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaccept(TestPlan.Visitor visitor)Accept the suppliedTestPlan.Visitorfor a depth-first traversal of the test plan.private voidaccept(TestPlan.Visitor visitor, TestIdentifier testIdentifier)voidadd(TestIdentifier testIdentifier)Deprecated.Calling this method is no longer supported and will throw an exception.voidaddInternal(TestIdentifier testIdentifier)booleancontainsTests()Return whether this test plan contains any tests.longcountTestIdentifiers(java.util.function.Predicate<? super TestIdentifier> predicate)Count allTestIdentifiersthat satisfy the given predicate.static TestPlanfrom(boolean containsTests, java.util.Collection<TestDescriptor> engineDescriptors, ConfigurationParameters configurationParameters, OutputDirectoryCreator outputDirectoryCreator)Construct a newTestPlanfrom the supplied collection ofTestDescriptors.java.util.Set<TestIdentifier>getChildren(java.lang.String parentId)Deprecated.java.util.Set<TestIdentifier>getChildren(UniqueId parentId)Get the children of the supplied unique ID.java.util.Set<TestIdentifier>getChildren(TestIdentifier parent)Get the children of the suppliedTestIdentifier.ConfigurationParametersgetConfigurationParameters()Get theConfigurationParametersfor this test plan.java.util.Set<TestIdentifier>getDescendants(TestIdentifier parent)Get all descendants of the suppliedTestIdentifier(i.e., all of its children and their children, recursively).OutputDirectoryCreatorgetOutputDirectoryCreator()Get theOutputDirectoryCreatorfor this test plan.OutputDirectoryProvidergetOutputDirectoryProvider()Deprecated.Please usegetOutputDirectoryCreator()insteadjava.util.Optional<TestIdentifier>getParent(TestIdentifier child)Get the parent of the suppliedTestIdentifier.java.util.Set<TestIdentifier>getRoots()Get the rootTestIdentifiersfor this test plan.TestIdentifiergetTestIdentifier(java.lang.String uniqueId)Deprecated.TestIdentifiergetTestIdentifier(UniqueId uniqueId)Get theTestIdentifierwith the supplied unique ID.
-
-
-
Field Detail
-
roots
private final java.util.Set<TestIdentifier> roots
-
children
private final java.util.Map<UniqueId,java.util.Set<TestIdentifier>> children
-
allIdentifiers
private final java.util.Map<UniqueId,TestIdentifier> allIdentifiers
-
containsTests
private final boolean containsTests
-
configurationParameters
private final ConfigurationParameters configurationParameters
-
outputDirectoryCreator
private final OutputDirectoryCreator outputDirectoryCreator
-
-
Constructor Detail
-
TestPlan
@API(status=INTERNAL, since="1.4") protected TestPlan(boolean containsTests, ConfigurationParameters configurationParameters, OutputDirectoryCreator outputDirectoryCreator)
-
-
Method Detail
-
from
@API(status=INTERNAL, since="1.14") public static TestPlan from(boolean containsTests, java.util.Collection<TestDescriptor> engineDescriptors, ConfigurationParameters configurationParameters, OutputDirectoryCreator outputDirectoryCreator)Construct a newTestPlanfrom the supplied collection ofTestDescriptors.Each supplied
TestDescriptoris expected to be a descriptor for aTestEngine.- Parameters:
containsTests- whether the test plan contains testsengineDescriptors- the engine test descriptors from which the test plan should be created; nevernullconfigurationParameters- theConfigurationParametersfor this test plan; nevernulloutputDirectoryCreator- theOutputDirectoryProviderfor this test plan; nevernull- Returns:
- a new test plan
-
add
@Deprecated @API(status=DEPRECATED, since="1.4") public void add(TestIdentifier testIdentifier)Deprecated.Calling this method is no longer supported and will throw an exception.Add the suppliedTestIdentifierto this test plan.- Parameters:
testIdentifier- the identifier to add; nevernull- Throws:
org.junit.platform.commons.JUnitException- always
-
addInternal
@API(status=INTERNAL, since="1.8") public void addInternal(TestIdentifier testIdentifier)
-
getRoots
public java.util.Set<TestIdentifier> getRoots()
Get the rootTestIdentifiersfor this test plan.- Returns:
- an unmodifiable set of the root identifiers
-
getParent
public java.util.Optional<TestIdentifier> getParent(TestIdentifier child)
Get the parent of the suppliedTestIdentifier.- Parameters:
child- the identifier to look up the parent for; nevernull- Returns:
- an
Optionalcontaining the parent, if present
-
getChildren
public java.util.Set<TestIdentifier> getChildren(TestIdentifier parent)
Get the children of the suppliedTestIdentifier.- Parameters:
parent- the identifier to look up the children for; nevernull- Returns:
- an unmodifiable set of the parent's children, potentially empty
- See Also:
getChildren(UniqueId)
-
getChildren
@API(status=DEPRECATED, since="1.10") @Deprecated public java.util.Set<TestIdentifier> getChildren(java.lang.String parentId)Deprecated.Get the children of the supplied unique ID.- Parameters:
parentId- the unique ID to look up the children for; nevernullor blank- Returns:
- an unmodifiable set of the parent's children, potentially empty
- See Also:
getChildren(TestIdentifier)
-
getChildren
@API(status=MAINTAINED, since="1.10") public java.util.Set<TestIdentifier> getChildren(UniqueId parentId)Get the children of the supplied unique ID.- Parameters:
parentId- the unique ID to look up the children for; nevernull- Returns:
- an unmodifiable set of the parent's children, potentially empty
- See Also:
getChildren(TestIdentifier)
-
getTestIdentifier
@API(status=DEPRECATED, since="1.10") @Deprecated public TestIdentifier getTestIdentifier(java.lang.String uniqueId) throws org.junit.platform.commons.PreconditionViolationExceptionDeprecated.Get theTestIdentifierwith the supplied unique ID.- Parameters:
uniqueId- the unique ID to look up the identifier for; nevernullor blank- Returns:
- the identifier with the supplied unique ID; never
null - Throws:
org.junit.platform.commons.PreconditionViolationException- if noTestIdentifierwith the supplied unique ID is present in this test plan
-
getTestIdentifier
@API(status=MAINTAINED, since="1.10") public TestIdentifier getTestIdentifier(UniqueId uniqueId)Get theTestIdentifierwith the supplied unique ID.- Parameters:
uniqueId- the unique ID to look up the identifier for; nevernull- Returns:
- the identifier with the supplied unique ID; never
null - Throws:
org.junit.platform.commons.PreconditionViolationException- if noTestIdentifierwith the supplied unique ID is present in this test plan
-
countTestIdentifiers
public long countTestIdentifiers(java.util.function.Predicate<? super TestIdentifier> predicate)
Count allTestIdentifiersthat satisfy the given predicate.- Parameters:
predicate- a predicate which returnstruefor identifiers to be counted; nevernull- Returns:
- the number of identifiers that satisfy the supplied predicate
-
getDescendants
public java.util.Set<TestIdentifier> getDescendants(TestIdentifier parent)
Get all descendants of the suppliedTestIdentifier(i.e., all of its children and their children, recursively).- Parameters:
parent- the identifier to look up the descendants for; nevernull- Returns:
- an unmodifiable set of the parent's descendants, potentially empty
-
containsTests
public boolean containsTests()
Return whether this test plan contains any tests.A test plan contains tests, if at least one of the contained engine descriptors contains tests.
- Returns:
trueif this test plan contains tests- See Also:
TestDescriptor.containsTests(TestDescriptor)
-
getConfigurationParameters
@API(status=MAINTAINED, since="1.8") public ConfigurationParameters getConfigurationParameters()Get theConfigurationParametersfor this test plan.- Returns:
- the configuration parameters; never
null - Since:
- 1.8
-
getOutputDirectoryProvider
@API(status=DEPRECATED, since="1.14") @Deprecated public OutputDirectoryProvider getOutputDirectoryProvider()Deprecated.Please usegetOutputDirectoryCreator()insteadGet theOutputDirectoryProviderfor this test plan.- Returns:
- the output directory provider; never
null - Since:
- 1.12
-
getOutputDirectoryCreator
@API(status=MAINTAINED, since="1.14") public OutputDirectoryCreator getOutputDirectoryCreator()Get theOutputDirectoryCreatorfor this test plan.- Returns:
- the output directory creator; never
null - Since:
- 1.14
-
accept
@API(status=MAINTAINED, since="1.13.3") public void accept(TestPlan.Visitor visitor)Accept the suppliedTestPlan.Visitorfor a depth-first traversal of the test plan.- Parameters:
visitor- the visitor to accept; nevernull- Since:
- 1.10
-
accept
private void accept(TestPlan.Visitor visitor, TestIdentifier testIdentifier)
-
-