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

public static interface StepVerifier.Step<T> extends StepVerifier.LastStep
Define a builder for expecting main sequence individual signals.
  • Method Details

    • as

      StepVerifier.Step<T> as(String description)
      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

      StepVerifier.Step<T> consumeNextWith(Consumer<? super T> consumer)
      Expect an element and consume with the given consumer.Any AssertionErrors thrown by the consumer will be rethrown during verification.
      Parameters:
      consumer - the consumer for the value
      Returns:
      this builder
    • assertNext

      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. using Hamcrest, AssertJ or JUnit assertion methods). Alias for consumeNextWith(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

      StepVerifier.Step<T> consumeRecordedWith(Consumer<? super Collection<T>> consumer)
      Expect a recording session started via recordWith(java.util.function.Supplier<? extends java.util.Collection<T>>), end it and verify it by applying the given consumer. Any AssertionErrors 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

      StepVerifier.Step<T> expectNext(T t)
      Expect the next element received to be equal to the given value.
      Parameters:
      t - the value to expect
      Returns:
      this builder
      See Also:
    • expectNext

      StepVerifier.Step<T> expectNext(T t1, T t2)
      Expect the next elements received to be equal to the given values.
      Parameters:
      t1 - the first value to expect
      t2 - the second value to expect
      Returns:
      this builder
      See Also:
    • expectNext

      StepVerifier.Step<T> expectNext(T t1, T t2, T t3)
      Expect the next elements received to be equal to the given values.
      Parameters:
      t1 - the first value to expect
      t2 - the second value to expect
      t3 - the third value to expect
      Returns:
      this builder
      See Also:
    • expectNext

      StepVerifier.Step<T> expectNext(T t1, T t2, T t3, T t4)
      Expect the next elements received to be equal to the given values.
      Parameters:
      t1 - the first value to expect
      t2 - the second value to expect
      t3 - the third value to expect
      t4 - the fourth value to expect
      Returns:
      this builder
      See Also:
    • expectNext

      StepVerifier.Step<T> expectNext(T t1, T t2, T t3, T t4, T t5)
      Expect the next elements received to be equal to the given values.
      Parameters:
      t1 - the first value to expect
      t2 - the second value to expect
      t3 - the third value to expect
      t4 - the fourth value to expect
      t5 - the fifth value to expect
      Returns:
      this builder
      See Also:
    • expectNext

      StepVerifier.Step<T> expectNext(T t1, T t2, T t3, T t4, T t5, T t6)
      Expect the next elements received to be equal to the given values.
      Parameters:
      t1 - the first value to expect
      t2 - the second value to expect
      t3 - the third value to expect
      t4 - the fourth value to expect
      t5 - the fifth value to expect
      t6 - the sixth value to expect
      Returns:
      this builder
      See Also:
    • expectNext

      StepVerifier.Step<T> expectNext(T... ts)
      Expect the next elements received to be equal to the given values.
      Parameters:
      ts - the values to expect
      Returns:
      this builder
      See Also:
    • expectNextCount

      StepVerifier.Step<T> expectNextCount(long count)
      Expect to received count elements, starting from the previous expectation or onSubscribe.
      Parameters:
      count - the number of emitted items to expect.
      Returns:
      this builder
      See Also:
    • expectNextSequence

      StepVerifier.Step<T> expectNextSequence(Iterable<? extends T> iterable)
      Expect the next elements to match the given Iterable until its iterator depletes.
      Parameters:
      iterable - the iterable containing the next expected values
      Returns:
      this builder
      See Also:
    • expectNextMatches

      StepVerifier.Step<T> expectNextMatches(Predicate<? super T> predicate)
      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

      StepVerifier.Step<T> consumeSubscriptionWith(Consumer<? super Subscription> consumer)
      Expect a Subscription and consume with the given consumer. Any AssertionErrors thrown by the consumer will be rethrown during verification.
      Parameters:
      consumer - the consumer for the Subscription
      Returns:
      this builder
      See Also:
    • expectAccessibleContext

      StepVerifier.ContextExpectations<T> expectAccessibleContext()
      Expect that after the Subscription step, a Context has been propagated. You can continue with assertions on said Context, and you will need to use StepVerifier.ContextExpectations.then() to switch back to verifying the sequence itself.
      Returns:
      a StepVerifier.ContextExpectations for further assertion of the propagated Context
    • expectNoAccessibleContext

      StepVerifier.Step<T> expectNoAccessibleContext()
      Expect that NO Context was propagated after the Subscription phase, 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

      StepVerifier.Step<T> expectNoEvent(Duration duration)
      Expect that no event has been observed by the verifier for the length of the provided Duration. 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 with expectNoEvent(Duration) to work around that.

      Also avoid using this method at the end of the set of expectations: prefer StepVerifier.LastStep.expectTimeout(Duration) rather than expectNoEvent(...).thenCancel().

      Parameters:
      duration - the duration for which to observe no event has been received
      Returns:
      this builder
      See Also:
    • expectRecordedMatches

      StepVerifier.Step<T> expectRecordedMatches(Predicate<? super Collection<T>> predicate)
      Expect a recording session started via recordWith(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

      StepVerifier.Step<T> recordWith(Supplier<? extends Collection<T>> supplier)
      Start a recording session storing Subscriber.onNext(Object) values in the supplied Collection. Further steps expectRecordedMatches(Predicate) and consumeRecordedWith(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 the Collection to 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

      default StepVerifier.Step<T> thenAwait()
      Mark a Pause in the expectation evaluation. If a VirtualTimeScheduler has been configured, VirtualTimeScheduler.advanceTime() will be used and the pause will not block testing or Publisher thread.
      Returns:
      this builder
    • thenAwait

      StepVerifier.Step<T> thenAwait(Duration timeshift)
      Pause the expectation evaluation for a given Duration. If a VirtualTimeScheduler has been configured, VirtualTimeScheduler.advanceTimeBy(Duration) will be used and the pause will not block testing or Publisher thread.
      Parameters:
      timeshift - a pause Duration
      Returns:
      this builder
    • thenConsumeWhile

      StepVerifier.Step<T> thenConsumeWhile(Predicate<T> predicate)
      Consume further onNext signals as long as they match a predicate.
      Parameters:
      predicate - the condition to continue consuming onNext
      Returns:
      this builder
    • thenConsumeWhile

      StepVerifier.Step<T> thenConsumeWhile(Predicate<T> predicate, Consumer<T> consumer)
      Consume further onNext signals using a provided Consumer as long as they match a Predicate. You can use the consumer to apply assertions on each value.
      Parameters:
      predicate - the condition to continue consuming onNext
      consumer - the consumer to use to consume the data, when the predicate matches
      Returns:
      this builder
    • thenRequest

      StepVerifier.Step<T> thenRequest(long n)
      Request the given amount of elements from the upstream Publisher. This is in addition to the initial number of elements requested by an initial passed demand like with StepVerifier.create(Publisher, long).
      Parameters:
      n - the number of elements to request
      Returns:
      this builder
      See Also: