@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)));
  }
Example #2
0
  @Test
  public void twoNotificationsShouldNotBeEqualIfTheyWrapUnequalMessages() {

    Notification other =
        new Notification(notification.getMessage() + "Y", notification.getDetail());

    assertNotEquals(notification, other);
  }
Example #3
0
  @Test
  public void twoNotificationsShouldBeEqualIfTheyWrapEqualMessagesAndEqualDetails() {

    Notification other = new Notification(notification.getMessage(), notification.getDetail());

    assertEquals(notification, other);
    assertThat(notification.hashCode(), is(equalTo(other.hashCode())));
  }
Example #4
0
  @Test
  public void aNotificationShouldBeEqualToTheOtherEvenTheirDetailsAreBithNull() {

    notification = new Notification(notification.getMessage(), null);
    Notification other = new Notification(notification.getMessage(), null);

    assertEquals(notification, other);
  }
  @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)));
  }