Package io.smallrye.mutiny.helpers.test
Class AssertSubscriber<T>
- java.lang.Object
-
- io.smallrye.mutiny.helpers.test.AssertSubscriber<T>
-
- Type Parameters:
T- the type of the items
- All Implemented Interfaces:
org.reactivestreams.Subscriber<T>
public class AssertSubscriber<T> extends java.lang.Object implements org.reactivestreams.Subscriber<T>AMultiSubscriberfor testing purposes that comes with useful assertion helpers.
-
-
Constructor Summary
Constructors Constructor Description AssertSubscriber()Creates a newAssertSubscriberwith 0 requested items and no upfront cancellation.AssertSubscriber(long requested)Creates a newAssertSubscriberwith no upfront cancellation.AssertSubscriber(long requested, boolean cancelled)Creates a newAssertSubscriber.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AssertSubscriber<T>assertCompleted()Assert that the multi has completed.AssertSubscriber<T>assertFailedWith(java.lang.Class<? extends java.lang.Throwable> expectedTypeOfFailure, java.lang.String expectedFailureMessage)Assert that the multi has failed.AssertSubscriber<T>assertHasNotReceivedAnyItem()Assert that no item has been received yet.AssertSubscriber<T>assertItems(T... expected)Assert that a sequence of items has been received (in whole and in exact order).AssertSubscriber<T>assertNotSubscribed()Assert that the multi has not been subscribed.AssertSubscriber<T>assertNotTerminated()Assert that the multi has not been terminated.AssertSubscriber<T>assertSubscribed()Assert that the multi has been subscribed.AssertSubscriber<T>assertTerminated()Assert that the multi has been terminated.AssertSubscriber<T>await()Await for the multi to be terminated.AssertSubscriber<T>await(java.time.Duration duration)Await for the multi to be terminated.AssertSubscriber<T>cancel()Cancel the subscription.static <T> AssertSubscriber<T>create()Creates a newAssertSubscriberwith 0 requested items and no upfront cancellation.static <T> AssertSubscriber<T>create(long requested)Creates a newAssertSubscriberwith no upfront cancellation.java.lang.ThrowablegetFailure()The reported failure, if any.java.util.List<T>getItems()The list of items that have been received.booleanhasCompleted()Check whether the multi has completed.booleanisCancelled()Check whether the subscription has been cancelled or not.voidonComplete()voidonError(java.lang.Throwable t)voidonNext(T t)voidonSubscribe(org.reactivestreams.Subscription s)AssertSubscriber<T>request(long req)Request items.AssertSubscriber<T>run(java.lang.Runnable action)Run an action.
-
-
-
Constructor Detail
-
AssertSubscriber
public AssertSubscriber(long requested, boolean cancelled)Creates a newAssertSubscriber.- Parameters:
requested- the number of initially requested itemscancelled-trueif the subscription is immediately cancelled,falseotherwise
-
AssertSubscriber
public AssertSubscriber()
Creates a newAssertSubscriberwith 0 requested items and no upfront cancellation.
-
AssertSubscriber
public AssertSubscriber(long requested)
Creates a newAssertSubscriberwith no upfront cancellation.- Parameters:
requested- the number of initially requested items
-
-
Method Detail
-
create
public static <T> AssertSubscriber<T> create()
Creates a newAssertSubscriberwith 0 requested items and no upfront cancellation.- Type Parameters:
T- the items type- Returns:
- a new subscriber
-
create
public static <T> AssertSubscriber<T> create(long requested)
Creates a newAssertSubscriberwith no upfront cancellation.- Type Parameters:
T- the items type- Parameters:
requested- the number of initially requested items- Returns:
- a new subscriber
-
assertCompleted
public AssertSubscriber<T> assertCompleted()
Assert that the multi has completed.- Returns:
- this
AssertSubscriber
-
assertFailedWith
public AssertSubscriber<T> assertFailedWith(java.lang.Class<? extends java.lang.Throwable> expectedTypeOfFailure, java.lang.String expectedFailureMessage)
Assert that the multi has failed.- Parameters:
expectedTypeOfFailure- the expected failure typeexpectedFailureMessage- a message to be contained in the failure message, ornullwhen any message is fine- Returns:
- this
AssertSubscriber
-
assertHasNotReceivedAnyItem
public AssertSubscriber<T> assertHasNotReceivedAnyItem()
Assert that no item has been received yet.- Returns:
- this
AssertSubscriber
-
assertSubscribed
public AssertSubscriber<T> assertSubscribed()
Assert that the multi has been subscribed.- Returns:
- this
AssertSubscriber
-
assertNotSubscribed
public AssertSubscriber<T> assertNotSubscribed()
Assert that the multi has not been subscribed.- Returns:
- this
AssertSubscriber
-
assertTerminated
public AssertSubscriber<T> assertTerminated()
Assert that the multi has been terminated.- Returns:
- this
AssertSubscriber
-
assertNotTerminated
public AssertSubscriber<T> assertNotTerminated()
Assert that the multi has not been terminated.- Returns:
- this
AssertSubscriber
-
assertItems
@SafeVarargs public final AssertSubscriber<T> assertItems(T... expected)
Assert that a sequence of items has been received (in whole and in exact order).- Parameters:
expected- a sequence of items- Returns:
- this
AssertSubscriber
-
await
public AssertSubscriber<T> await()
Await for the multi to be terminated. Wait at most 10 seconds before failing.- Returns:
- this
AssertSubscriber
-
await
public AssertSubscriber<T> await(java.time.Duration duration)
Await for the multi to be terminated.- Parameters:
duration- the timeout duration- Returns:
- this
AssertSubscriber
-
cancel
public AssertSubscriber<T> cancel()
Cancel the subscription.- Returns:
- this
AssertSubscriber
-
request
public AssertSubscriber<T> request(long req)
Request items.- Parameters:
req- the number of items to request.- Returns:
- this
AssertSubscriber
-
onSubscribe
public void onSubscribe(org.reactivestreams.Subscription s)
- Specified by:
onSubscribein interfaceorg.reactivestreams.Subscriber<T>
-
onError
public void onError(java.lang.Throwable t)
- Specified by:
onErrorin interfaceorg.reactivestreams.Subscriber<T>
-
onComplete
public void onComplete()
- Specified by:
onCompletein interfaceorg.reactivestreams.Subscriber<T>
-
getItems
public java.util.List<T> getItems()
The list of items that have been received.- Returns:
- the list
-
getFailure
public java.lang.Throwable getFailure()
The reported failure, if any.- Returns:
- the failure or
null
-
run
public AssertSubscriber<T> run(java.lang.Runnable action)
Run an action.- Parameters:
action- the action- Returns:
- this
AssertSubscriber
-
isCancelled
public boolean isCancelled()
Check whether the subscription has been cancelled or not.- Returns:
- a boolean
-
hasCompleted
public boolean hasCompleted()
Check whether the multi has completed.- Returns:
- a boolean
-
-