Testing with the aggregate operators and the BlockingObservable class
Using the operators and methods learned in the previous two sections, we are able to rework the test we've written to look like this:
@Test public void testUsingBlockingObservable() { List<String> result = tested .toList() .toBlocking() .single(); Assert.assertEquals(expected, result); }
There is no boilerplate code here. We retrieve all the items emitted as a list and compare them to the expected list.
Using the BlockingObsevables
class and the aggregate operators is pretty useful in most cases. While testing asynchronous Observable
instances, which emit long, slow sequences, they are not so useful though. It is not good practice to block the test cases for a long time: slow ...
Get Learning Reactive Programming with Java 8 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.