Class Scenario.When<T>
java.lang.Object
org.springframework.modulith.test.Scenario.When<T>
- Enclosing class:
- Scenario
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
The result of an expected event publication.class
The result of an expected state change. -
Constructor Summary
ConstructorDescriptionWhen
(BiFunction<TransactionOperations, ApplicationEventPublisher, T> stimulus, Consumer<T> cleanup, Function<org.awaitility.core.ConditionFactory, org.awaitility.core.ConditionFactory> customizer) -
Method Summary
Modifier and TypeMethodDescriptionandCleanup
(Runnable runnable) andCleanup
(Consumer<T> consumer) andWaitAtMost
(Duration duration) Configures theScenario
to wait for at most the given duration for an event of the subsequent specification to arrive.<E> Scenario.When<T>.EventResult<E>
andWaitForEventOfType
(Class<E> type) Expects an event of the given type to arrive.<S> Scenario.When<T>.StateChangeResult<S>
andWaitForStateChange
(Supplier<S> supplier) Expects a particular state change on the module to produce a result.<S> Scenario.When<T>.StateChangeResult<S>
andWaitForStateChange
(Supplier<S> supplier, Predicate<? super S> acceptanceCriteria) Expects a particular state change on the module to produce a result and uses the givenPredicate
to determine whether the value is conclusive.customize
(Function<org.awaitility.core.ConditionFactory, org.awaitility.core.ConditionFactory> customizer) Customize the execution of the scenario.<E> Scenario.When<T>.EventResult<E>
forEventOfType
(Class<E> type) Alternative toandWaitForEventOfType(Class)
for better readability if execution customizations have been applied before.<S> Scenario.When<T>.StateChangeResult<S>
forStateChange
(Supplier<S> supplier) Alternative toandWaitForStateChange(Supplier)
for better readability if execution customizations have been applied before.<S> Scenario.When<T>.StateChangeResult<S>
forStateChange
(Supplier<S> supplier, Predicate<? super S> acceptanceCriteria) Alternative toandWaitForStateChange(Supplier, Predicate)
for better readability if execution customizations have been applied before.
-
Constructor Details
-
When
When(BiFunction<TransactionOperations, ApplicationEventPublisher, T> stimulus, Consumer<T> cleanup, Function<org.awaitility.core.ConditionFactory, org.awaitility.core.ConditionFactory> customizer) - Parameters:
stimulus
- must not be null.cleanup
- must not be null.customizer
- must not be null.
-
-
Method Details
-
andCleanup
Registers the givenRunnable
as cleanup callback to always run after completion of theScenario
, no matter the outcome of its execution (error or success).- Parameters:
runnable
- must not be null.- Returns:
- will never be null.
-
andCleanup
Registers the givenConsumer
as cleanup callback to always run after completion of theScenario
, no matter the outcome of its execution (error or success).- Parameters:
consumer
- must not be null.- Returns:
- will never be null.
-
andWaitAtMost
Configures theScenario
to wait for at most the given duration for an event of the subsequent specification to arrive.- Parameters:
duration
- must not be null.- Returns:
- will never be null.
-
customize
public Scenario.When<T> customize(Function<org.awaitility.core.ConditionFactory, org.awaitility.core.ConditionFactory> customizer) Customize the execution of the scenario. The given customizer will be added to the default one registered via aScenarioCustomizer
. In other words, multiple invocations will replace registrations made in previous calls but always be chained after the default customizations registered.- Parameters:
customizer
- must not be null.- Returns:
- will never be null.
-
forEventOfType
Alternative toandWaitForEventOfType(Class)
for better readability if execution customizations have been applied before.- Type Parameters:
E
- the type of the event.- Parameters:
type
- must not be null.- Returns:
- will never be null.
- See Also:
-
forStateChange
Alternative toandWaitForStateChange(Supplier)
for better readability if execution customizations have been applied before.- Type Parameters:
S
- the type of the state change result- Parameters:
supplier
- must not be null.- Returns:
- will never be null.
- See Also:
-
forStateChange
public <S> Scenario.When<T>.StateChangeResult<S> forStateChange(Supplier<S> supplier, Predicate<? super S> acceptanceCriteria) Alternative toandWaitForStateChange(Supplier, Predicate)
for better readability if execution customizations have been applied before.- Type Parameters:
S
- the type of the state change result- Parameters:
supplier
- must not be null.acceptanceCriteria
- must not be null.- Returns:
- will never be null.
- See Also:
-
andWaitForEventOfType
Expects an event of the given type to arrive. Use API on the returnedScenario.When.EventResult
to specify more detailed expectations and conclude those with a call a flavor ofScenario.When.EventResult.toArrive()
.- Type Parameters:
E
- the type of the event.- Parameters:
type
- must not be null.- Returns:
- will never be null.
- See Also:
-
andWaitForStateChange
Expects a particular state change on the module to produce a result. By default, a non-null value would indicate success, except forOptional
s, in which case we'd check for the presence of a value andbooleans
, for which we accept true as conclusive signal. For more control about the result matching, useandWaitForStateChange(Supplier, Predicate)
.- Type Parameters:
S
- the type of the result.- Parameters:
supplier
- must not be null.- Returns:
- will never be null.
- See Also:
-
andWaitForStateChange
public <S> Scenario.When<T>.StateChangeResult<S> andWaitForStateChange(Supplier<S> supplier, Predicate<? super S> acceptanceCriteria) Expects a particular state change on the module to produce a result and uses the givenPredicate
to determine whether the value is conclusive.- Type Parameters:
S
- the type of the result for the state change- Parameters:
supplier
- must not be null.acceptanceCriteria
- must not be null.- Returns:
- will never be null.
- See Also:
-