- Type Parameters:
T- the type of the items
- All Implemented Interfaces:
ContextSupport,UniSubscriber<T>
Uni UniSubscriber for testing purposes that comes with useful assertion helpers.-
Constructor Summary
ConstructorsConstructorDescriptionCreate a newUniAssertSubscriberwith no upfront cancellation and an emptyContext.UniAssertSubscriber(boolean cancelled) Create a newUniAssertSubscriberwith an upfront cancellation configuration and an emptyContext.UniAssertSubscriber(Context context, boolean cancelled) Create a newUniAssertSubscriber. -
Method Summary
Modifier and TypeMethodDescriptionAssert that theUnihas completed.Assert that theUnihas failed.assertFailedWith(Class<? extends Throwable> expectedTypeOfFailure) Assert that theUnihas failed.assertFailedWith(Class<? extends Throwable> expectedTypeOfFailure, String expectedMessage) Assert that theUnihas failed.assertItem(T expected) Assert that theUnihas received an item.Assert that theUnihas not been subscribed.Assert that theUnihas not terminated.Assert that signals have been received in correct order.Assert that theUnihas been subscribed.Assert that theUnihas terminated.Awaits for a failure event.awaitFailure(Duration duration) Awaits for a failure event.awaitFailure(Consumer<Throwable> assertion) Awaits for a failure event and validate it.awaitFailure(Consumer<Throwable> assertion, Duration duration) Awaits for a failure event and validate it.Awaits for an item event.Awaits for a item event at mostduration.Awaits for a subscription event (the subscriber receives aUniSubscriptionfrom the upstream.awaitSubscription(Duration duration) Awaits for a subscription event (the subscriber receives aUniSubscriptionfrom the upstream.voidcancel()Cancel the subscription.context()Provide a context.static <T> UniAssertSubscriber<T> create()Create a newUniAssertSubscriberwith no upfront cancellation and an emptyContext.static <T> UniAssertSubscriber<T> Create a newUniAssertSubscriberwith no upfront cancellation and aContext.Get theUnifailure, if any.getItem()Get theUniitem, if any.Get the name of the thread that calledonFailure(Throwable), if any.Get the name of the thread that calledonItem(Object), if any.Get the name of the thread that calledonSubscribe(UniSubscription), if any.Get theUniSignalaudit trail for this subscriber.voidCalled if the computation of the item by the subscriberUnifailed.voidEvent handler called once the item has been computed by the subscribedUni.voidonSubscribe(UniSubscription subscription) Event handler called once the subscribedUnihas taken into account the subscription.
-
Constructor Details
-
UniAssertSubscriber
Create a newUniAssertSubscriber.- Parameters:
context- the subscription context, cannot benullcancelled-truewhen the subscription shall be cancelled upfront,falseotherwise
-
UniAssertSubscriber
public UniAssertSubscriber(boolean cancelled) Create a newUniAssertSubscriberwith an upfront cancellation configuration and an emptyContext. -
UniAssertSubscriber
public UniAssertSubscriber()Create a newUniAssertSubscriberwith no upfront cancellation and an emptyContext.
-
-
Method Details
-
create
Create a newUniAssertSubscriberwith no upfront cancellation and an emptyContext.- Type Parameters:
T- the type of the item- Returns:
- a new subscriber
-
create
Create a newUniAssertSubscriberwith no upfront cancellation and aContext.- Type Parameters:
T- the type of the item- Parameters:
context- the context, cannot benull- Returns:
- a new subscriber
-
context
Description copied from interface:ContextSupportProvide a context.Since calls to this method shall only be triggered when a Mutiny pipeline uses a
withContextoperator, there is no need in general for caching the context value in a field of the implementing class. Exceptions include operators that have cross-subscriber semantics such as memoizers or broadcasters.This method is expected to be called once per
withContextoperator.- Specified by:
contextin interfaceContextSupport- Returns:
- the context, must not be
null.
-
onSubscribe
Description copied from interface:UniSubscriberEvent handler called once the subscribedUnihas taken into account the subscription. TheUnihave triggered the computation of the item.IMPORTANT:
UniSubscriber.onItem(Object)andUniSubscriber.onFailure(Throwable)would not be called before the invocation of this method.- Executor: Operate on no particular executor, except if
Uni.runSubscriptionOn(Executor)has been called - Exception: Throwing an exception cancels the subscription,
UniSubscriber.onItem(Object)andUniSubscriber.onFailure(Throwable)won't be called
- Specified by:
onSubscribein interfaceUniSubscriber<T>- Parameters:
subscription- the subscription allowing to cancel the computation.
- Executor: Operate on no particular executor, except if
-
onItem
Description copied from interface:UniSubscriberEvent handler called once the item has been computed by the subscribedUni.IMPORTANT: this method will be only called once per subscription. If
UniSubscriber.onFailure(Throwable)is called, this method won't be called.- Executor: Operate on no particular executor, except if
Uni.emitOn(java.util.concurrent.Executor)has been called - Exception: Throwing an exception cancels the subscription.
- Specified by:
onItemin interfaceUniSubscriber<T>- Parameters:
item- the item, may benull.
- Executor: Operate on no particular executor, except if
-
onFailure
Description copied from interface:UniSubscriberCalled if the computation of the item by the subscriberUnifailed.IMPORTANT: this method will be only called once per subscription. If
UniSubscriber.onItem(Object)is called, this method won't be called.- Executor: Operate on no particular executor, except if
Uni.emitOn(java.util.concurrent.Executor)has been called - Exception: Throwing an exception cancels the subscription.
- Specified by:
onFailurein interfaceUniSubscriber<T>- Parameters:
failure- the failure, cannot benull.
- Executor: Operate on no particular executor, except if
-
awaitItem
Awaits for an item event. It waits at mostAssertSubscriber.DEFAULT_TIMEOUT.If the timeout expired, or if a failure event is received instead of the expected completion, the check fails.
- Returns:
- this
UniAssertSubscriber
-
awaitItem
Awaits for a item event at mostduration.If the timeout expired, or if a failure event is received instead of the expected completion, the check fails.
- Parameters:
duration- the duration, must not benull- Returns:
- this
UniAssertSubscriber
-
awaitFailure
Awaits for a failure event. It waits at mostAssertSubscriber.DEFAULT_TIMEOUT.If the timeout expired, or if an item event is received instead of the expected failure, the check fails.
- Returns:
- this
UniAssertSubscriber
-
awaitFailure
Awaits for a failure event and validate it. It waits at mostAssertSubscriber.DEFAULT_TIMEOUT.If the timeout expired, or if an item event is received instead of the expected failure, the check fails. The received failure is validated using the
assertionconsumer. The code of the consumer is expected to throw anAssertionErrorto indicate that the failure didn't pass the validation. The consumer is not called if no failures are received.- Parameters:
assertion- a check validating the received failure (if any). Must not benull- Returns:
- this
UniAssertSubscriber
-
awaitFailure
Awaits for a failure event. It waits at mostduration.If the timeout expired, or if an item event is received instead of the expected failure, the check fails.
- Parameters:
duration- the max duration to wait, must not benull- Returns:
- this
UniAssertSubscriber
-
awaitFailure
Awaits for a failure event and validate it. It waits at mostduration.If the timeout expired, or if an item event is received instead of the expected failure, the check fails. The received failure is validated using the
assertionconsumer. The code of the consumer is expected to throw anAssertionErrorto indicate that the failure didn't pass the validation. The consumer is not called if no failures are received.- Parameters:
assertion- a check validating the received failure (if any). Must not benullduration- the max duration to wait, must not benull- Returns:
- this
UniAssertSubscriber
-
awaitSubscription
Awaits for a subscription event (the subscriber receives aUniSubscriptionfrom the upstream. It waits at mostAssertSubscriber.DEFAULT_TIMEOUT.If the timeout expired, the check fails.
- Returns:
- this
UniAssertSubscriber
-
awaitSubscription
Awaits for a subscription event (the subscriber receives aUniSubscriptionfrom the upstream. It waits at mostduration.If the timeout expired, the check fails.
- Parameters:
duration- the UniAssertSubscriber, must not benull- Returns:
- this
AssertSubscriber
-
assertCompleted
Assert that theUnihas completed.- Returns:
- this
UniAssertSubscriber
-
assertFailed
Assert that theUnihas failed.- Returns:
- this
UniAssertSubscriber
-
getItem
Get theUniitem, if any.- Returns:
- the item or
null
-
getFailure
Get theUnifailure, if any.- Returns:
- the failure or
null
-
assertItem
Assert that theUnihas received an item.- Parameters:
expected- the expected item- Returns:
- this
UniAssertSubscriber
-
assertFailedWith
public UniAssertSubscriber<T> assertFailedWith(Class<? extends Throwable> expectedTypeOfFailure, String expectedMessage) Assert that theUnihas failed.- Parameters:
expectedTypeOfFailure- the expected failure typeexpectedMessage- a message that is expected to be contained in the failure message- Returns:
- this
UniAssertSubscriber
-
assertFailedWith
Assert that theUnihas failed.- Parameters:
expectedTypeOfFailure- the expected failure type- Returns:
- this
UniAssertSubscriber
-
getOnItemThreadName
Get the name of the thread that calledonItem(Object), if any.- Returns:
- the thread name
-
getOnFailureThreadName
Get the name of the thread that calledonFailure(Throwable), if any.- Returns:
- the thread name
-
getOnSubscribeThreadName
Get the name of the thread that calledonSubscribe(UniSubscription), if any.- Returns:
- the thread name
-
cancel
public void cancel()Cancel the subscription. -
assertTerminated
Assert that theUnihas terminated.- Returns:
- this
UniAssertSubscriber
-
assertNotTerminated
Assert that theUnihas not terminated.- Returns:
- this
UniAssertSubscriber
-
assertSubscribed
Assert that theUnihas been subscribed.- Returns:
- this
UniAssertSubscriber
-
assertNotSubscribed
Assert that theUnihas not been subscribed.- Returns:
- this
UniAssertSubscriber
-
getSignals
Get theUniSignalaudit trail for this subscriber.- Returns:
- the signals in receive order
-
assertSignalsReceivedInOrder
Assert that signals have been received in correct order.An example of an legal sequence would be receiving
onSubscribe -> onItem. An example of an illegal sequence would be receivingonItem -> onSubscribe.- Returns:
- this
UniAssertSubscriber
-