Package net.jqwik.api.state
Interface ActionChain<S>
-
- Type Parameters:
S- The type of the object going through state transformations
@API(status=EXPERIMENTAL, since="1.7.0") public interface ActionChain<S>A chain of transforming Actions that can be run for values of typeS. Since the next action is usually created on demand, the currentrunStateof a chain can be queried.By default any action chain instance is not thread safe, i.e. you should not try to invoke run() concurrently.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classActionChain.ActionChainFacadestatic classActionChain.RunningState
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.Optional<S>finalState()The final state value after running an action chain.ActionChain<S>peek(java.util.function.Consumer<S> peeker)Observe the state transformations of a running chain by adding a peeker to an action chain.Srun()Run the list through all transformations provided by the actions to create it.ActionChain.RunningStaterunning()An action chain can be in different running states: NOT_RUN, RUNNING, FAILED, SUCEEDEDstatic <T> ActionChainArbitrary<T>startWith(java.util.function.Supplier<? extends T> initialSupplier)Create arbitrary for a chain with a certain initial state.java.util.List<java.lang.String>transformations()Return list of all applied transformations.ActionChain<S>withInvariant(@Nullable java.lang.String label, java.util.function.Consumer<S> invariant)Add a labelled invariant to a sequence.default ActionChain<S>withInvariant(java.util.function.Consumer<S> invariant)Add an unlabelled invariant to a sequence.
-
-
-
Method Detail
-
startWith
static <T> ActionChainArbitrary<T> startWith(java.util.function.Supplier<? extends T> initialSupplier)
Create arbitrary for a chain with a certain initial state.- Type Parameters:
T- The type of state to be transformed through the chain.- Parameters:
initialSupplier- function to create the initial state object- Returns:
- new arbitrary instance
-
transformations
java.util.List<java.lang.String> transformations()
Return list of all applied transformations.For a chain that has not been run this list is always empty.
- Returns:
- list of describing strings
-
run
S run()
Run the list through all transformations provided by the actions to create it. Stop when either the maximum number of transformations is reached or if a Transformer.END_OF_CHAIN is being applied.- Returns:
- the last resulting state of running through transformations
-
withInvariant
default ActionChain<S> withInvariant(java.util.function.Consumer<S> invariant)
Add an unlabelled invariant to a sequence.- Parameters:
invariant- will be checked after each successful action- Returns:
- the same chain instance
- See Also:
withInvariant(String, Consumer)
-
withInvariant
ActionChain<S> withInvariant(@Nullable @Nullable java.lang.String label, java.util.function.Consumer<S> invariant)
Add a labelled invariant to a sequence.- Parameters:
label- will show up in error messages when the invariant failsinvariant- will be checked after each successful action- Returns:
- the same chain instance
- See Also:
withInvariant(Consumer)
-
finalState
java.util.Optional<S> finalState()
The final state value after running an action chain.- Returns:
- state or Optional.empty() if chain has not been run
-
running
ActionChain.RunningState running()
An action chain can be in different running states: NOT_RUN, RUNNING, FAILED, SUCEEDED- Returns:
- a state object
-
peek
ActionChain<S> peek(java.util.function.Consumer<S> peeker)
Observe the state transformations of a running chain by adding a peeker to an action chain. Thepeekerwill be called after each successful transformation but before checking invariants.There can be more than one peeker.
- Parameters:
peeker- A consumer of a state object- Returns:
- the same chain instance
-
-