Book Image

Learning Reactive Programming with Java 8

By : Nickolay Tzvetinov
Book Image

Learning Reactive Programming with Java 8

By: Nickolay Tzvetinov

Overview of this book

Table of Contents (15 chapters)
Learning Reactive Programming with Java 8
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 tests are bad tests.