Package io.smallrye.mutiny.helpers.test
Class UniAssertSubscriber<T>
- java.lang.Object
-
- io.smallrye.mutiny.helpers.test.UniAssertSubscriber<T>
-
- Type Parameters:
T- the type of the items
- All Implemented Interfaces:
UniSubscriber<T>
public class UniAssertSubscriber<T> extends java.lang.Object implements UniSubscriber<T>
AUniUniSubscriberfor testing purposes that comes with useful assertion helpers.
-
-
Constructor Summary
Constructors Constructor Description UniAssertSubscriber()Create a newUniAssertSubscriberwith no upfront cancellation.UniAssertSubscriber(boolean cancelled)Create a newUniAssertSubscriber.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UniAssertSubscriber<T>assertCompleted()Assert that theUnihas completed.UniAssertSubscriber<T>assertFailed()Assert that theUnihas failed.UniAssertSubscriber<T>assertFailedWith(java.lang.Class<? extends java.lang.Throwable> expectedTypeOfFailure, java.lang.String expectedMessage)Assert that theUnihas failed.UniAssertSubscriber<T>assertItem(T expected)Assert that theUnihas received an item.UniAssertSubscriber<T>assertNotSubscribed()Assert that theUnihas not been subscribed.UniAssertSubscriber<T>assertNotTerminated()Assert that theUnihas not terminated.UniAssertSubscriber<T>assertSignalsReceivedInOrder()Assert that signals have been received in correct order.UniAssertSubscriber<T>assertSubscribed()Assert that theUnihas been subscribed.UniAssertSubscriber<T>assertTerminated()Assert that theUnihas terminated.UniAssertSubscriber<T>await()Await for termination.voidcancel()Cancel the subscription.static <T> UniAssertSubscriber<T>create()Create a newUniAssertSubscriberwith no upfront cancellation.java.lang.ThrowablegetFailure()Get theUnifailure, if any.TgetItem()Get theUniitem, if any.java.lang.StringgetOnFailureThreadName()Get the name of the thread that calledonFailure(Throwable), if any.java.lang.StringgetOnItemThreadName()Get the name of the thread that calledonItem(Object), if any.java.lang.StringgetOnSubscribeThreadName()Get the name of the thread that calledonSubscribe(UniSubscription), if any.java.util.List<UniSignal>getSignals()Get theUniSignalaudit trail for this subscriber.voidonFailure(java.lang.Throwable failure)Called if the computation of the item by the subscriberUnifailed.voidonItem(T item)Event 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 Detail
-
UniAssertSubscriber
public UniAssertSubscriber(boolean cancelled)
Create a newUniAssertSubscriber.- Parameters:
cancelled-truewhen the subscription shall be cancelled upfront,falseotherwise
-
UniAssertSubscriber
public UniAssertSubscriber()
Create a newUniAssertSubscriberwith no upfront cancellation.
-
-
Method Detail
-
create
public static <T> UniAssertSubscriber<T> create()
Create a newUniAssertSubscriberwith no upfront cancellation.- Type Parameters:
T- the type of the item- Returns:
- a new subscriber
-
onSubscribe
public void onSubscribe(UniSubscription subscription)
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
public void onItem(T item)
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. IfUniSubscriber.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
public void onFailure(java.lang.Throwable failure)
Description copied from interface:UniSubscriberCalled if the computation of the item by the subscriberUnifailed. IMPORTANT: this method will be only called once per subscription. IfUniSubscriber.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
-
await
public UniAssertSubscriber<T> await()
Await for termination.- Returns:
- this
UniAssertSubscriber
-
assertCompleted
public UniAssertSubscriber<T> assertCompleted()
Assert that theUnihas completed.- Returns:
- this
UniAssertSubscriber
-
assertFailed
public UniAssertSubscriber<T> assertFailed()
Assert that theUnihas failed.- Returns:
- this
UniAssertSubscriber
-
getFailure
public java.lang.Throwable getFailure()
Get theUnifailure, if any.- Returns:
- the failure or
null
-
assertItem
public UniAssertSubscriber<T> assertItem(T expected)
Assert that theUnihas received an item.- Parameters:
expected- the expected item- Returns:
- this
UniAssertSubscriber
-
assertFailedWith
public UniAssertSubscriber<T> assertFailedWith(java.lang.Class<? extends java.lang.Throwable> expectedTypeOfFailure, java.lang.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
-
getOnItemThreadName
public java.lang.String getOnItemThreadName()
Get the name of the thread that calledonItem(Object), if any.- Returns:
- the thread name
-
getOnFailureThreadName
public java.lang.String getOnFailureThreadName()
Get the name of the thread that calledonFailure(Throwable), if any.- Returns:
- the thread name
-
getOnSubscribeThreadName
public java.lang.String getOnSubscribeThreadName()
Get the name of the thread that calledonSubscribe(UniSubscription), if any.- Returns:
- the thread name
-
cancel
public void cancel()
Cancel the subscription.
-
assertTerminated
public UniAssertSubscriber<T> assertTerminated()
Assert that theUnihas terminated.- Returns:
- this
UniAssertSubscriber
-
assertNotTerminated
public UniAssertSubscriber<T> assertNotTerminated()
Assert that theUnihas not terminated.- Returns:
- this
UniAssertSubscriber
-
assertSubscribed
public UniAssertSubscriber<T> assertSubscribed()
Assert that theUnihas been subscribed.- Returns:
- this
UniAssertSubscriber
-
assertNotSubscribed
public UniAssertSubscriber<T> assertNotSubscribed()
Assert that theUnihas not been subscribed.- Returns:
- this
UniAssertSubscriber
-
getSignals
public java.util.List<UniSignal> getSignals()
Get theUniSignalaudit trail for this subscriber.- Returns:
- the signals in receive order
-
assertSignalsReceivedInOrder
public UniAssertSubscriber<T> 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
-
-