public final class ArgumentsCombiner extends Object
ArgumentsProvider
implementations or provider methods
to produce argument combinations.
This class has quite some overlapping functionality with
JUnit Pioneer's @CartesianTest. What this class adds that
@CartesianTest
doesn't is filtering out combinations.
This class has no special support for enums like @CartesianTest
and @EnumSource
do. That's because
with(Collection)
and crossJoin(Collection)
can be used in combination with EnumSet
. For instance, to exclude some enum
constants, use EnumSet.complementOf(EnumSet)
in combination with one of the other EnumSet
factory methods.
Note that instances of this class can be considered as builders for Stream
s of Arguments
instances. Like Stream
s they
should not be used more than once.
Modifier and Type | Method and Description |
---|---|
static Arguments |
combineArguments(Object o1,
Object o2)
Combines two (sets of) arguments into one
Arguments object. |
ArgumentsCombiner |
crossJoin(ArgumentsProvider argumentsProvider,
ExtensionContext context)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoin(Collection<?> arguments)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoin(Object... arguments)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoin(Supplier<? extends Stream<?>> argumentsProvider)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoinBooleans(boolean[] arguments)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoinBytes(byte[] arguments)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoinChars(char[] arguments)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoinDoubles(double[] arguments)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoinFloats(float[] arguments)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoinInts(int[] arguments)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoinLongs(long[] arguments)
Adds a set of arguments.
|
ArgumentsCombiner |
crossJoinShorts(short[] arguments)
Adds a set of arguments.
|
ArgumentsCombiner |
excludeCombination(Object... values)
Excludes a combination of values from the current combinations of arguments.
|
ArgumentsCombiner |
excludeCombinations(Predicate<? super Object[]> filter)
Excludes all combinations of arguments that match a filter.
|
Stream<? extends Arguments> |
stream()
Returns a stream with all combinations of arguments.
|
static ArgumentsCombiner |
with(ArgumentsProvider argumentsProvider,
ExtensionContext context)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
with(Collection<?> arguments)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
with(Object... arguments)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
with(Stream<?> arguments)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
withBooleans(boolean[] arguments)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
withBytes(byte[] arguments)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
withChars(char[] arguments)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
withDoubles(double[] arguments)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
withFloats(float[] arguments)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
withInts(int[] arguments)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
withLongs(long[] arguments)
Creates an arguments combiner with an initial set of arguments.
|
static ArgumentsCombiner |
withShorts(short[] arguments)
Creates an arguments combiner with an initial set of arguments.
|
public static ArgumentsCombiner withBooleans(boolean[] arguments)
Note that this method does not support variable arguments; use with(Object...)
for that.
arguments
- The initial set of arguments.public static ArgumentsCombiner withChars(char[] arguments)
Note that this method does not support variable arguments; use with(Object...)
for that.
arguments
- The initial set of arguments.public static ArgumentsCombiner withBytes(byte[] arguments)
Note that this method does not support variable arguments; use with(Object...)
for that.
arguments
- The initial set of arguments.public static ArgumentsCombiner withShorts(short[] arguments)
Note that this method does not support variable arguments; use with(Object...)
for that.
arguments
- The initial set of arguments.public static ArgumentsCombiner withInts(int[] arguments)
Note that this method does not support variable arguments; use with(Object...)
for that.
arguments
- The initial set of arguments.public static ArgumentsCombiner withLongs(long[] arguments)
Note that this method does not support variable arguments; use with(Object...)
for that.
arguments
- The initial set of arguments.public static ArgumentsCombiner withFloats(float[] arguments)
Note that this method does not support variable arguments; use with(Object...)
for that.
arguments
- The initial set of arguments.public static ArgumentsCombiner withDoubles(double[] arguments)
Note that this method does not support variable arguments; use with(Object...)
for that.
arguments
- The initial set of arguments.public static ArgumentsCombiner with(Object... arguments)
arguments
- The initial set of arguments.public static ArgumentsCombiner with(Collection<?> arguments)
arguments
- A collection with the initial set of arguments.NullPointerException
- If the given collection is null
.public static ArgumentsCombiner with(Stream<?> arguments)
arguments
- A stream with the initial set of arguments. Note that this stream should not be used outside the returned instance anymore.NullPointerException
- If the given stream is null
.public static ArgumentsCombiner with(ArgumentsProvider argumentsProvider, ExtensionContext context)
Note that if the arguments provider throws an exception from its ArgumentsProvider.provideArguments(ExtensionContext)
method,
that exception will be re-thrown as is but as an unchecked exception.
argumentsProvider
- The provider initial set of arguments.context
- The current extension context.NullPointerException
- If the given arguments provider or context is null
.public ArgumentsCombiner crossJoinBooleans(boolean[] arguments)
Note that this method does not support variable arguments; use crossJoin(Object...)
for that.
arguments
- The arguments to add.public ArgumentsCombiner crossJoinChars(char[] arguments)
Note that this method does not support variable arguments; use crossJoin(Object...)
for that.
arguments
- The arguments to add.public ArgumentsCombiner crossJoinBytes(byte[] arguments)
Note that this method does not support variable arguments; use crossJoin(Object...)
for that.
arguments
- The arguments to add.public ArgumentsCombiner crossJoinShorts(short[] arguments)
Note that this method does not support variable arguments; use crossJoin(Object...)
for that.
arguments
- The arguments to add.public ArgumentsCombiner crossJoinInts(int[] arguments)
Note that this method does not support variable arguments; use crossJoin(Object...)
for that.
arguments
- The arguments to add.public ArgumentsCombiner crossJoinLongs(long[] arguments)
Note that this method does not support variable arguments; use crossJoin(Object...)
for that.
arguments
- The arguments to add.public ArgumentsCombiner crossJoinFloats(float[] arguments)
Note that this method does not support variable arguments; use crossJoin(Object...)
for that.
arguments
- The arguments to add.public ArgumentsCombiner crossJoinDoubles(double[] arguments)
Note that this method does not support variable arguments; use crossJoin(Object...)
for that.
arguments
- The arguments to add.public ArgumentsCombiner crossJoin(Object... arguments)
arguments
- The arguments to add.public ArgumentsCombiner crossJoin(Collection<?> arguments)
arguments
- A collection with the arguments to add.NullPointerException
- If the given collection is null
.public ArgumentsCombiner crossJoin(Supplier<? extends Stream<?>> argumentsProvider)
argumentsProvider
- A supplier for a stream with the arguments to add.
Each invocation of the supplier should return a fresh new stream that is not used for any other purposes.NullPointerException
- If the given supplier is null
.public ArgumentsCombiner crossJoin(ArgumentsProvider argumentsProvider, ExtensionContext context)
Note that if the arguments provider throws an exception from its ArgumentsProvider.provideArguments(ExtensionContext)
method,
that exception will be re-thrown as is but as an unchecked exception.
argumentsProvider
- The provider for the arguments to add.context
- The current extension context.NullPointerException
- If the given arguments provider or context is null
.public ArgumentsCombiner excludeCombination(Object... values)
Note that the number of values given should be equal to the number of arguments in each current combination. Otherwise, an exception will be
thrown when the stream returned by stream()
is consumed.
values
- The combination of values to exclude.public ArgumentsCombiner excludeCombinations(Predicate<? super Object[]> filter)
filter
- The filter to use.
Every Arguments
instance for which filter.test
returns true
will be excluded.NullPointerException
- If the given filter is null
.public Stream<? extends Arguments> stream()
ArgumentsCombiner
should no longer be used.public static Arguments combineArguments(Object o1, Object o2)
Arguments
object. If either argument is an instance of Arguments
, its elements will
be used as separate arguments in the result. Otherwise, the argument is used as a single argument.o1
- The first argument or set of arguments.o2
- The second argument or set of arguments.Copyright © 2020–2023. All rights reserved.