Upgrade to Pro — share decks privately, control downloads, hide ads and more …

rx-ja-night-2016-1

Yuya Kaido
February 24, 2016

 rx-ja-night-2016-1

Yuya Kaido

February 24, 2016
Tweet

More Decks by Yuya Kaido

Other Decks in Programming

Transcript

  1. Integer[] actual = new Integer[] {1, 2, 3};
 Observable<Integer> observable

    = Observable.from(actual);
 
 final List<Integer> expect = new ArrayList<>(actual.length);
 observable.subscribe(new Subscriber<Integer>() {
 @Override
 public void onCompleted() {}
 
 @Override
 public void onError(Throwable e) {}
 
 @Override
 public void onNext(Integer integer) {
 expect.add(integer);
 }
 });
 
 for (int i = 0, size = expect.size(); i < size; i++) {
 assertThat(expect.get(i), is(actual[i]));
 } 
  2. Integer[] actual = new Integer[] {1, 2, 3};
 Observable<Integer> observable

    = Observable.from(actual);
 
 final List<Integer> expect = new ArrayList<>(actual.length);
 observable.subscribe(new Subscriber<Integer>() {
 @Override
 public void onCompleted() {}
 
 @Override
 public void onError(Throwable e) {}
 
 @Override
 public void onNext(Integer integer) {
 expect.add(integer);
 }
 });
 
 for (int i = 0, size = expect.size(); i < size; i++) {
 assertThat(expect.get(i), is(actual[i]));
 } 
  3. Integer[] actual = new Integer[] {1, 2, 3};
 Observable<Integer> observable

    = Observable.from(actual);
 
 final List<Integer> expect = new ArrayList<>(actual.length);
 observable.subscribe(new Subscriber<Integer>() {
 @Override
 public void onCompleted() {}
 
 @Override
 public void onError(Throwable e) {}
 
 @Override
 public void onNext(Integer integer) {
 expect.add(integer);
 }
 });
 
 for (int i = 0, size = expect.size(); i < size; i++) {
 assertThat(expect.get(i), is(actual[i]));
 } 
  4. Integer[] actual = new Integer[] {1, 2, 3};
 Observable<Integer> observable

    = Observable.from(actual);
 
 final List<Integer> expect = new ArrayList<>(actual.length);
 observable.subscribe(new Subscriber<Integer>() {
 @Override
 public void onCompleted() {}
 
 @Override
 public void onError(Throwable e) {}
 
 @Override
 public void onNext(Integer integer) {
 expect.add(integer);
 }
 });
 
 for (int i = 0, size = expect.size(); i < size; i++) {
 assertThat(expect.get(i), is(actual[i]));
 } 
  5. Integer[] actual = new Integer[] {1, 2, 3};
 Observable<Integer> observable

    = Observable.from(actual);
 
 final List<Integer> expect = new ArrayList<>(actual.length);
 observable.subscribe(new Subscriber<Integer>() {
 @Override
 public void onCompleted() {}
 
 @Override
 public void onError(Throwable e) {}
 
 @Override
 public void onNext(Integer integer) {
 expect.add(integer);
 throw new RuntimeException();
 }
 });
 
 for (int i = 0, size = expect.size(); i < size; i++) {
 assertThat(expect.get(i), is(actual[i]));
 } 
  6. Integer[] actual = new Integer[] {1, 2, 3};
 Observable<Integer> observable

    = Observable.from(actual);
 
 final List<Integer> expect = new ArrayList<>(actual.length);
 observable.subscribe(new Subscriber<Integer>() {
 @Override
 public void onCompleted() {}
 
 @Override
 public void onError(Throwable e) {}
 
 @Override
 public void onNext(Integer integer) {
 expect.add(integer);
 throw new RuntimeException();
 }
 });
 
 for (int i = 0, size = expect.size(); i < size; i++) {
 assertThat(expect.get(i), is(actual[i]));
 } 
  7. TestSubscriber Integer[] integers = new Integer[] {1, 2, 3};
 Observable<Integer>

    observable = Observable.from(integers);
 
 TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
 observable.subscribe(testSubscriber);
 
 testSubscriber.assertNoErrors();
 testSubscriber.assertValueCount(integers.length);
 testSubscriber.assertValues(integers);
 testSubscriber.assertCompleted(); 
  8. TestSubscriber Integer[] integers = new Integer[] {1, 2, 3};
 Observable<Integer>

    observable = Observable.from(integers);
 
 TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
 observable.subscribe(testSubscriber);
 
 testSubscriber.assertNoErrors();
 testSubscriber.assertValueCount(integers.length);
 testSubscriber.assertValues(integers);
 testSubscriber.assertCompleted(); 
  9. TestSubscriber Integer[] integers = new Integer[] {1, 2, 3};
 Observable<Integer>

    observable = Observable.from(integers);
 
 TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
 observable.subscribe(testSubscriber);
 
 testSubscriber.assertNoErrors();
 testSubscriber.assertValueCount(integers.length);
 testSubscriber.assertValues(integers);
 testSubscriber.assertCompleted(); 
  10. TestSubscriber Integer[] integers = new Integer[] {1, 2, 3};
 Observable<Integer>

    observable = Observable.from(integers);
 
 TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
 observable.subscribe(testSubscriber);
 
 testSubscriber.assertNoErrors();
 testSubscriber.assertValueCount(integers.length);
 testSubscriber.assertValues(integers);
 testSubscriber.assertCompleted();