示例#1
0
  @Test
  public void testAsSetAction() throws Exception {
    final Value<String> value = Value.create("1");
    assertEquals(value.get(), "1");
    TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    Subscription subscribe = value.asObservable().subscribe(testSubscriber);

    value.asSetAction().call("2");

    testSubscriber.assertValueCount(2);
    testSubscriber.assertValues("1", "2");
  }
示例#2
0
  @Test
  public void testCreateReplay() throws Exception {

    final Value<String> value = Value.createReplay("1");
    assertEquals(value.get(), "1");
    TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    Subscription subscribe = value.asObservable().subscribe(testSubscriber);

    testSubscriber.assertValueCount(1);
    testSubscriber.assertValue("1");

    value.set("2");

    testSubscriber.assertValueCount(2);
    testSubscriber.assertValues("1", "2");

    subscribe.unsubscribe();

    testSubscriber = new TestSubscriber<>();
    value.asObservable().subscribe(testSubscriber);

    testSubscriber.assertValueCount(2);
    testSubscriber.assertValues("1", "2");
  }
示例#3
0
 private void assertValues(List<Integer> values, TestSubscriber<Integer> subscriber) {
   subscriber.assertValues(values.toArray(new Integer[values.size()]));
 }