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

rx-ja-night-2016-1

836437265cbba12ee1b24bbb359a6c15?s=47 Yuya Kaido
February 24, 2016

 rx-ja-night-2016-1

836437265cbba12ee1b24bbb359a6c15?s=128

Yuya Kaido

February 24, 2016
Tweet

Transcript

  1. TestSubscriber Rx Ja Night 2016 #1 yuyakaido

  2. Observableͷςετ ॻ͍ͯ·͔͢ʁ 

  3. ࣗݾ঺հ • ւ౻༏໻ʢ͔͍Ͳ͏Ώ͏΍ʣ • גࣜձࣾΤ΢ϨΧ • ςετॻ͚ॻ͚͓͡͞Μ • Android 

    yuyakaido yuyakaido
  4. גࣜձࣾΤ΢ϨΧ • ࣗࣾαʔϏεͷاըɾ։ൃɾӡӦ • ΦϯϥΠϯσʔςΟϯάαʔϏεɿ • Χοϓϧઐ༻ΞϓϦɿ • ࣾһ਺ɿ90໊ •

    IAC  ΤϯδχΞ 60 ඇΤϯδχΞ 30
  5. Observableͷςετ 

  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);
 }
 });
 
 for (int i = 0, size = expect.size(); i < size; i++) {
 assertThat(expect.get(i), is(actual[i]));
 } 
  7. 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]));
 } 
  8. 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]));
 } 
  9. 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]));
 } 
  10. ໰୊఺ • onError() • onCompleted() • ඇಉظ 

  11. 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]));
 } 
  12. 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]));
 } 
  13. TestSubscriber 

  14. 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(); 
  15. 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(); 
  16. 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(); 
  17. 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(); 
  18. TestSubscriber • assert  http://reactivex.io/RxJava/javadoc/rx/observers/TestSubscriber.html

  19. TestSubscriber • assert  http://reactivex.io/RxJava/javadoc/rx/observers/TestSubscriber.html

  20. TestSubscriber • ඇಉظ  http://reactivex.io/RxJava/javadoc/rx/observers/TestSubscriber.html

  21. TestSubscriber • Πϕϯτऔಘ  http://reactivex.io/RxJava/javadoc/rx/observers/TestSubscriber.html

  22. Observableͷςετ ॻ͖·͠ΐ͏ʂʂ 

  23. Thank you :) Credit: NASA Earth Observatory/NOAA NGDC