Java Code Examples for io.reactivex.rxjava3.observers.TestObserver#assertNoValues()

The following examples show how to use io.reactivex.rxjava3.observers.TestObserver#assertNoValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PublishRelayTest.java    From RxRelay with Apache License 2.0 6 votes vote down vote up
@Test
public void crossCancel() {
    final TestObserver<Integer> ts1 = new TestObserver<Integer>();
    TestObserver<Integer> ts2 = new TestObserver<Integer>() {
        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            ts1.dispose();
        }
    };

    PublishRelay<Integer> pp = PublishRelay.create();

    pp.subscribe(ts2);
    pp.subscribe(ts1);

    pp.accept(1);

    ts2.assertValue(1);

    ts1.assertNoValues();
}
 
Example 2
Source File: UntilEventTransformerSingleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
@Test
public void twoEvents() {
    TestObserver<String> testObserver = Single.just("1")
        .delay(1, TimeUnit.MILLISECONDS, testScheduler)
        .compose(RxLifecycle.<String, String>bindUntilEvent(lifecycle, "stop"))
        .test();

    lifecycle.onNext("keep going");
    testObserver.assertNoErrors();

    lifecycle.onNext("stop");
    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);

    testObserver.assertNoValues();
    testObserver.assertError(CancellationException.class);
}
 
Example 3
Source File: OutsideLifecycleExceptionTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
@Test
public void eventOutOfLifecycle() {
    PublishSubject<String> stream = PublishSubject.create();
    PublishSubject<String> lifecycle = PublishSubject.create();

    TestObserver<String> testObserver = stream
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    // Event is out of lifecycle, but this just results in completing the stream
    lifecycle.onNext("destroy");
    stream.onNext("1");

    testObserver.assertNoValues();
    testObserver.assertComplete();
}
 
Example 4
Source File: UntilLifecycleTransformerSingleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
@Test
public void oneEvent() {
    TestObserver<String> testObserver = Single.just("1")
        .delay(1, TimeUnit.MILLISECONDS, testScheduler)
        .compose(RxLifecycle.<String, String>bind(lifecycle))
        .test();

    testObserver.assertNoValues();
    testObserver.assertNoErrors();

    lifecycle.onNext("stop");
    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);

    testObserver.assertNoValues();
    testObserver.assertError(CancellationException.class);
}
 
Example 5
Source File: PublishRelayTest.java    From RxRelay with Apache License 2.0 6 votes vote down vote up
@Test
public void crossCancel() {
    final TestObserver<Integer> ts1 = new TestObserver<Integer>();
    TestObserver<Integer> ts2 = new TestObserver<Integer>() {
        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            ts1.dispose();
        }
    };

    PublishRelay<Integer> pp = PublishRelay.create();

    pp.subscribe(ts2);
    pp.subscribe(ts1);

    pp.accept(1);

    ts2.assertValue(1);

    ts1.assertNoValues();
}
 
Example 6
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 6 votes vote down vote up
@Ignore("No backpressure in Observable")
@Test public void backpressureHonoredWhenCached() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  TestObserver<String> observer1 = new TestObserver<>();
  observable.subscribe(observer1);
  observer1.assertNoValues();

  subject.onNext("Foo");
  observer1.assertValues("Foo");

  TestObserver<String> observer2 = new TestObserver<>(/*0*/);
  observable.subscribe(observer2);
  observer2.assertNoValues();

  subject.onNext("Bar"); // Replace the cached value...
  observer1.assertValues("Foo", "Bar");

  //observer2.requestMore(1); // ...and ensure new requests see it.
  observer2.assertValues("Bar");
}
 
Example 7
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 6 votes vote down vote up
@Test public void valueMissedWhenNoSubscribers() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  TestObserver<String> observer1 = new TestObserver<>();
  observable.subscribe(observer1);
  observer1.assertNoValues();
  observer1.dispose();

  subject.onNext("Foo");
  observer1.assertNoValues();

  TestObserver<String> observer2 = new TestObserver<>();
  observable.subscribe(observer2);
  observer2.assertNoValues();
}
 
Example 8
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 6 votes vote down vote up
@Test public void initialValueToNewSubscriberAfterUnsubscribe() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  TestObserver<String> observer1 = new TestObserver<>();
  observable.subscribe(observer1);
  observer1.assertNoValues();

  subject.onNext("Foo");
  observer1.assertValues("Foo");
  observer1.dispose();

  TestObserver<String> observer2 = new TestObserver<>();
  observable.subscribe(observer2);
  observer2.assertValues("Foo");
}
 
Example 9
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 5 votes vote down vote up
@Test public void unsubscribeBeforeSubscribePreventsCacheEmission() {
  PublishSubject<String> upstream = PublishSubject.create();
  Observable<String> replayed = upstream.compose(ReplayingShare.<String>instance());
  replayed.subscribe();
  upstream.onNext("something to cache");

  TestObserver<String> testObserver = new TestObserver<>();
  testObserver.dispose();
  replayed.subscribe(testObserver);
  testObserver.assertNoValues();
}
 
Example 10
Source File: UntilLifecycleTransformerSingleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void noEvent() {
    TestObserver<String> testObserver = Single.just("1")
        .delay(1, TimeUnit.MILLISECONDS, testScheduler)
        .compose(RxLifecycle.<String, String>bind(lifecycle))
        .test();

    testObserver.assertNoValues();

    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
    testObserver.assertValue("1");
    testObserver.assertComplete();
}
 
Example 11
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 5 votes vote down vote up
@Test public void initialValueToNewSubscriber() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  TestObserver<String> observer1 = new TestObserver<>();
  observable.subscribe(observer1);
  observer1.assertNoValues();

  subject.onNext("Foo");
  observer1.assertValues("Foo");

  TestObserver<String> observer2 = new TestObserver<>();
  observable.subscribe(observer2);
  observer2.assertValues("Foo");
}
 
Example 12
Source File: UntilCorrespondingEventTransformerSingleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void twoOpenEvents() {
    TestObserver<String> testObserver = Single.just("1")
        .delay(1, TimeUnit.MILLISECONDS, testScheduler)
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    testObserver.assertNoValues();

    lifecycle.onNext("create");
    lifecycle.onNext("start");
    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
    testObserver.assertValue("1");
    testObserver.assertComplete();
}
 
Example 13
Source File: UntilCorrespondingEventTransformerSingleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void openAndCloseEvent() {
    TestObserver<String> testObserver = Single.just("1")
        .delay(1, TimeUnit.MILLISECONDS, testScheduler)
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    lifecycle.onNext("create");
    testObserver.assertNoErrors();

    lifecycle.onNext("destroy");
    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
    testObserver.assertNoValues();
    testObserver.assertError(CancellationException.class);
}
 
Example 14
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 5 votes vote down vote up
@Test public void noInitialValue() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  TestObserver<String> observer = new TestObserver<>();
  observable.subscribe(observer);
  observer.assertNoValues();
}
 
Example 15
Source File: OutsideLifecycleExceptionTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void eventThrowsBadException() {
    PublishSubject<String> stream = PublishSubject.create();
    PublishSubject<String> lifecycle = PublishSubject.create();

    TestObserver<String> testObserver = stream
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    // We get an error from the function for this lifecycle event
    lifecycle.onNext("ick");
    stream.onNext("1");

    testObserver.assertNoValues();

    // We only want to check for our IllegalArgumentException, but may have
    // to wade through a CompositeException to get at it.
    testObserver.assertError(new Predicate<Throwable>() {
        @Override
        public boolean test(Throwable throwable) throws Exception {
            if (throwable instanceof CompositeException) {
                CompositeException ce = (CompositeException) throwable;
                for (Throwable t : ce.getExceptions()) {
                    if (t instanceof IllegalArgumentException) {
                        return true;
                    }
                }
            }

            return false;
        }
    });
}
 
Example 16
Source File: UntilLifecycleTransformerMaybeTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void oneEvent() {
    TestObserver<String> testObserver = maybe
        .compose(RxLifecycle.<String, String>bind(lifecycle))
        .test();

    lifecycle.onNext("stop");
    stream.onNext("1");

    testObserver.assertNoValues();
    testObserver.assertComplete();
}
 
Example 17
Source File: UntilEventTransformerSingleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void noEvents() {
    TestObserver<String> testObserver = Single.just("1")
        .delay(1, TimeUnit.MILLISECONDS, testScheduler)
        .compose(RxLifecycle.<String, String>bindUntilEvent(lifecycle, "stop"))
        .test();

    testObserver.assertNoValues();

    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
    testObserver.assertValue("1");
    testObserver.assertComplete();
}
 
Example 18
Source File: UntilEventTransformerSingleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void oneWrongEvent() {
    TestObserver<String> testObserver = Single.just("1")
        .delay(1, TimeUnit.MILLISECONDS, testScheduler)
        .compose(RxLifecycle.<String, String>bindUntilEvent(lifecycle, "stop"))
        .test();

    testObserver.assertNoValues();

    lifecycle.onNext("keep going");
    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);

    testObserver.assertValue("1");
    testObserver.assertComplete();
}
 
Example 19
Source File: CountriesServiceSolvedTest.java    From RxBasicsKata with MIT License 5 votes vote down vote up
@Test
public void rx_ListPopulationMoreThanOneMillionWithTimeoutFallbackToEmpty_When_Timeout() throws InterruptedException {
    FutureTask<List<Country>> futureTask = new FutureTask<>(() -> {
        TimeUnit.SECONDS.sleep(15);
        return allCountries;
    });
    new Thread(futureTask).start();
    TestObserver<Country> testObserver = countriesService
            .listPopulationMoreThanOneMillionWithTimeoutFallbackToEmpty(futureTask)
            .test();
    testObserver.await();
    testObserver.assertComplete();
    testObserver.assertNoValues();
    testObserver.assertNoErrors();
}
 
Example 20
Source File: UntilEventTransformerMaybeTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void twoEvents() {
    TestObserver<String> testObserver = maybe
        .compose(RxLifecycle.<String, String>bindUntilEvent(lifecycle, "stop"))
        .test();

    lifecycle.onNext("keep going");
    lifecycle.onNext("stop");

    subject.onNext("1");
    testObserver.assertNoValues();
    testObserver.assertComplete();
}