@Test
  public void testMaterialize2() {
    final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", "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(4, NbpObserver.notifications.size());
    assertEquals("one", Notification.getValue(NbpObserver.notifications.get(0)));
    assertTrue(Notification.isNext(NbpObserver.notifications.get(0)));
    assertEquals("two", Notification.getValue(NbpObserver.notifications.get(1)));
    assertTrue(Notification.isNext(NbpObserver.notifications.get(1)));
    assertEquals("three", Notification.getValue(NbpObserver.notifications.get(2)));
    assertTrue(Notification.isNext(NbpObserver.notifications.get(2)));
    assertTrue(Notification.isComplete(NbpObserver.notifications.get(3)));
  }
  @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)));
  }
  @Test
  public void testMultipleSubscribes() throws InterruptedException, ExecutionException {
    final TestAsyncErrorObservable o = new TestAsyncErrorObservable("one", "two", null, "three");

    NbpObservable<Try<Optional<String>>> m = NbpObservable.create(o).materialize();

    assertEquals(3, m.toList().toBlocking().toFuture().get().size());
    assertEquals(3, m.toList().toBlocking().toFuture().get().size());
  }
 @Test
 public void testWithCompletionCausingError() {
   NbpTestSubscriber<Try<Optional<Integer>>> ts = new NbpTestSubscriber<>();
   final RuntimeException ex = new RuntimeException("boo");
   NbpObservable.<Integer>empty()
       .materialize()
       .doOnNext(
           new Consumer<Object>() {
             @Override
             public void accept(Object t) {
               throw ex;
             }
           })
       .subscribe(ts);
   ts.assertError(ex);
   ts.assertNoValues();
   ts.assertTerminated();
 }
 void subscribeNext() {
   other.subscribe(new NbpFullArbiterSubscriber<>(arbiter));
 }