We can test what we get by simply subscribing to the source Observable
instance and collecting all of the incoming notifications. In order to demonstrate that, we'll develop a factory
method for creating a new Observable
instance and will test its behavior.
The method will receive a Comparator
instance and multiple items, and will return Observable
instance, emitting these items as a sorted sequence. The items will be sorted according to the Comparator
instance passed.
We can develop the method using TDD. Let's first define the test as follows:
public class SortedObservableTest { private Observable<String> tested; private List<String> expected; @Before public void before() { tested = CreateObservable.<String>sorted( (a, b) -> a.compareTo(b), "Star", "Bar", "Car", "War", "Far", "Jar"); expected = Arrays.asList( "Bar", "Car", "Far", "Jar", "Star", "War" ); } TestData data = new TestData(); tested...