Package reactor.test
Interface StepVerifier.Step<T>
- Type Parameters:
T- the type of values that the subscriber contains
- All Superinterfaces:
StepVerifier.LastStep
- All Known Subinterfaces:
StepVerifier.FirstStep<T>
- Enclosing interface:
- StepVerifier
Define a builder for expecting main sequence individual signals.
-
Method Summary
Modifier and TypeMethodDescriptionSet a description for the previous verification step.default StepVerifier.Step<T>assertNext(Consumer<? super T> assertionConsumer) Expect an element and consume it with the given consumer, usually performing assertions on it (eg.consumeNextWith(Consumer<? super T> consumer) Expect an element and consume with the given consumer.AnyAssertionErrors thrown by the consumer will be rethrown during verification.consumeRecordedWith(Consumer<? super Collection<T>> consumer) Expect a recording session started viarecordWith(java.util.function.Supplier<? extends java.util.Collection<T>>), end it and verify it by applying the given consumer.consumeSubscriptionWith(Consumer<? super Subscription> consumer) Expect aSubscriptionand consume with the given consumer.Expect that after theSubscriptionstep, aContexthas been propagated.expectNext(T t) Expect the next element received to be equal to the given value.expectNext(T... ts) Expect the next elements received to be equal to the given values.expectNext(T t1, T t2) Expect the next elements received to be equal to the given values.expectNext(T t1, T t2, T t3) Expect the next elements received to be equal to the given values.expectNext(T t1, T t2, T t3, T t4) Expect the next elements received to be equal to the given values.Expect the next elements received to be equal to the given values.Expect the next elements received to be equal to the given values.expectNextCount(long count) Expect to receivedcountelements, starting from the previous expectation or onSubscribe.expectNextMatches(Predicate<? super T> predicate) Expect an element and evaluate with the given predicate.expectNextSequence(Iterable<? extends T> iterable) Expect the next elements to match the givenIterableuntil its iterator depletes.Expect that NOContextwas propagated after theSubscriptionphase, which usually indicates that the sequence under test doesn't contain Reactor operators (i.e.expectNoEvent(Duration duration) Expect that no event has been observed by the verifier for the length of the providedDuration.expectRecordedMatches(Predicate<? super Collection<T>> predicate) Expect a recording session started viarecordWith(java.util.function.Supplier<? extends java.util.Collection<T>>), end it and verify it by ensuring the provided predicate matches.recordWith(Supplier<? extends Collection<T>> supplier) Start a recording session storingSubscriber.onNext(Object)values in the suppliedCollection.Run an arbitrary task scheduled after previous expectations or tasks.default StepVerifier.Step<T>Mark a Pause in the expectation evaluation.Pause the expectation evaluation for a givenDuration.thenConsumeWhile(Predicate<T> predicate) Consume further onNext signals as long as they match a predicate.thenConsumeWhile(Predicate<T> predicate, Consumer<T> consumer) thenRequest(long n) Request the given amount of elements from the upstreamPublisher.Methods inherited from interface reactor.test.StepVerifier.LastStep
consumeErrorWith, expectComplete, expectError, expectError, expectErrorMatches, expectErrorMessage, expectErrorSatisfies, expectTimeout, thenCancel, verifyComplete, verifyError, verifyError, verifyErrorMatches, verifyErrorMessage, verifyErrorSatisfies, verifyTimeout
-
Method Details
-
as
Set a description for the previous verification step. Choosing a unique and descriptive name can make assertion errors easier to resolve.Note that calling this several times in a row will only take the first description into account.
- Parameters:
description- the description for the previous verification step- Returns:
- this builder
-
consumeNextWith
Expect an element and consume with the given consumer.AnyAssertionErrors thrown by the consumer will be rethrown during verification.- Parameters:
consumer- the consumer for the value- Returns:
- this builder
-
assertNext
Expect an element and consume it with the given consumer, usually performing assertions on it (eg. using Hamcrest, AssertJ or JUnit assertion methods). Alias forconsumeNextWith(Consumer)for better discoverability of that use case.Any
AssertionErrors thrown by the consumer will be rethrown during verification.- Parameters:
assertionConsumer- the consumer for the value, performing assertions- Returns:
- this builder
-
consumeRecordedWith
Expect a recording session started viarecordWith(java.util.function.Supplier<? extends java.util.Collection<T>>), end it and verify it by applying the given consumer. AnyAssertionErrors thrown by the consumer will be rethrown during verification.- Parameters:
consumer- the consumer used to apply assertions on the recorded session- Returns:
- this builder
-
expectNext
Expect the next element received to be equal to the given value.- Parameters:
t- the value to expect- Returns:
- this builder
- See Also:
-
expectNext
Expect the next elements received to be equal to the given values.- Parameters:
t1- the first value to expectt2- the second value to expect- Returns:
- this builder
- See Also:
-
expectNext
Expect the next elements received to be equal to the given values.- Parameters:
t1- the first value to expectt2- the second value to expectt3- the third value to expect- Returns:
- this builder
- See Also:
-
expectNext
Expect the next elements received to be equal to the given values.- Parameters:
t1- the first value to expectt2- the second value to expectt3- the third value to expectt4- the fourth value to expect- Returns:
- this builder
- See Also:
-
expectNext
Expect the next elements received to be equal to the given values.- Parameters:
t1- the first value to expectt2- the second value to expectt3- the third value to expectt4- the fourth value to expectt5- the fifth value to expect- Returns:
- this builder
- See Also:
-
expectNext
Expect the next elements received to be equal to the given values.- Parameters:
t1- the first value to expectt2- the second value to expectt3- the third value to expectt4- the fourth value to expectt5- the fifth value to expectt6- the sixth value to expect- Returns:
- this builder
- See Also:
-
expectNext
Expect the next elements received to be equal to the given values.- Parameters:
ts- the values to expect- Returns:
- this builder
- See Also:
-
expectNextCount
Expect to receivedcountelements, starting from the previous expectation or onSubscribe.- Parameters:
count- the number of emitted items to expect.- Returns:
- this builder
- See Also:
-
expectNextSequence
Expect the next elements to match the givenIterableuntil its iterator depletes.- Parameters:
iterable- the iterable containing the next expected values- Returns:
- this builder
- See Also:
-
expectNextMatches
Expect an element and evaluate with the given predicate.- Parameters:
predicate- the predicate to test on the next received value- Returns:
- this builder
- See Also:
-
consumeSubscriptionWith
Expect aSubscriptionand consume with the given consumer. AnyAssertionErrors thrown by the consumer will be rethrown during verification.- Parameters:
consumer- the consumer for theSubscription- Returns:
- this builder
- See Also:
-
expectAccessibleContext
StepVerifier.ContextExpectations<T> expectAccessibleContext()Expect that after theSubscriptionstep, aContexthas been propagated. You can continue with assertions on saidContext, and you will need to useStepVerifier.ContextExpectations.then()to switch back to verifying the sequence itself.- Returns:
- a
StepVerifier.ContextExpectationsfor further assertion of the propagatedContext
-
expectNoAccessibleContext
StepVerifier.Step<T> expectNoAccessibleContext()Expect that NOContextwas propagated after theSubscriptionphase, which usually indicates that the sequence under test doesn't contain Reactor operators (i.e. external Publisher, just a scalar source...).- Returns:
- this builder for further assertion of the sequence
-
expectNoEvent
Expect that no event has been observed by the verifier for the length of the providedDuration. If virtual time is used, this duration is verified using the virtual clock.Note that you should only use this method as the first expectation if you actually don't expect a subscription to happen. Use
StepVerifier.FirstStep.expectSubscription()combined withexpectNoEvent(Duration)to work around that.Also avoid using this method at the end of the set of expectations: prefer
StepVerifier.LastStep.expectTimeout(Duration)rather thanexpectNoEvent(...).thenCancel().- Parameters:
duration- the duration for which to observe no event has been received- Returns:
- this builder
- See Also:
-
expectRecordedMatches
Expect a recording session started viarecordWith(java.util.function.Supplier<? extends java.util.Collection<T>>), end it and verify it by ensuring the provided predicate matches.- Parameters:
predicate- the predicate to test on the recorded session- Returns:
- this builder
- See Also:
-
recordWith
Start a recording session storingSubscriber.onNext(Object)values in the suppliedCollection. Further stepsexpectRecordedMatches(Predicate)andconsumeRecordedWith(Consumer)can consume and assert the session.If an existing recording session hasn't not been declaratively consumed, this step will override the current session.
- Parameters:
supplier- the supplier for theCollectionto use for recording.- Returns:
- this builder
-
then
Run an arbitrary task scheduled after previous expectations or tasks.- Parameters:
task- the task to run- Returns:
- this builder
-
thenAwait
Mark a Pause in the expectation evaluation. If aVirtualTimeSchedulerhas been configured,VirtualTimeScheduler.advanceTime()will be used and the pause will not block testing orPublisherthread.- Returns:
- this builder
-
thenAwait
Pause the expectation evaluation for a givenDuration. If aVirtualTimeSchedulerhas been configured,VirtualTimeScheduler.advanceTimeBy(Duration)will be used and the pause will not block testing orPublisherthread.- Parameters:
timeshift- a pauseDuration- Returns:
- this builder
-
thenConsumeWhile
Consume further onNext signals as long as they match a predicate.- Parameters:
predicate- the condition to continue consuming onNext- Returns:
- this builder
-
thenConsumeWhile
Consume further onNext signals using a providedConsumeras long as they match aPredicate. You can use the consumer to apply assertions on each value.- Parameters:
predicate- the condition to continue consuming onNextconsumer- the consumer to use to consume the data, when the predicate matches- Returns:
- this builder
-
thenRequest
Request the given amount of elements from the upstreamPublisher. This is in addition to the initial number of elements requested by an initial passed demand like withStepVerifier.create(Publisher, long).- Parameters:
n- the number of elements to request- Returns:
- this builder
- See Also:
-