@Test public void testMaterialize1() { // null will cause onError to be triggered before "three" can be // returned final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", null, "three"); TestObserver NbpObserver = new TestObserver(); NbpObservable<Try<Optional<String>>> m = NbpObservable.create(o1).materialize(); m.subscribe(NbpObserver); try { o1.t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } assertFalse(NbpObserver.onError); assertTrue(NbpObserver.onCompleted); assertEquals(3, NbpObserver.notifications.size()); assertEquals("one", NbpObserver.notifications.get(0).value().get()); assertTrue(Notification.isNext(NbpObserver.notifications.get(0))); assertEquals("two", Notification.getValue(NbpObserver.notifications.get(1))); assertTrue(Notification.isNext(NbpObserver.notifications.get(1))); assertEquals(NullPointerException.class, NbpObserver.notifications.get(2).error().getClass()); assertTrue(Notification.isError(NbpObserver.notifications.get(2))); }