Class TestObserver<T>

  • All Implemented Interfaces:
    Observer<T>


    public class TestObserver<T>
    extends Object
    implements Observer<T>
    Observer usable for unit testing to perform assertions, inspect received events or wrap a mocked Observer.
    • Constructor Detail

      • TestObserver

        public TestObserver(Observer<T> delegate)
      • TestObserver

        public TestObserver()
    • Method Detail

      • getOnNextEvents

        public List<T> getOnNextEvents()
        Get the sequence of items observed by this observer, as an ordered List.
        Returns:
        a list of items observed by this observer, in the order in which they were observed
      • getEvents

        public List<Object> getEvents()
        Get a list containing all of the items and notifications received by this observer, where the items will be given as-is, any error notifications will be represented by their Throwables, and any sequence-complete notifications will be represented by their Notification objects.
        Returns:
        a List containing one item for each item or notification received by this observer, in the order in which they were observed or received
      • assertReceivedOnNext

        public void assertReceivedOnNext(List<T> items)
        Assert that a particular sequence of items was received in order.
        Parameters:
        items - the sequence of items expected to have been observed
        Throws:
        AssertionError - if the sequence of items observed does not exactly match items