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

The following examples show how to use io.reactivex.rxjava3.observers.TestObserver#assertNotComplete() . 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: RxLifecycleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
@Test
public void testBindUntilActivityEvent() {
    BehaviorSubject<ActivityEvent> lifecycle = BehaviorSubject.create();

    TestObserver<Object> testObserver =
        observable.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.STOP)).test();

    lifecycle.onNext(ActivityEvent.CREATE);
    testObserver.assertNotComplete();
    lifecycle.onNext(ActivityEvent.START);
    testObserver.assertNotComplete();
    lifecycle.onNext(ActivityEvent.RESUME);
    testObserver.assertNotComplete();
    lifecycle.onNext(ActivityEvent.PAUSE);
    testObserver.assertNotComplete();
    lifecycle.onNext(ActivityEvent.STOP);
    testObserver.assertComplete();
}
 
Example 2
Source File: RxActivityLifecycleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(ActivityController<? extends LifecycleProvider<ActivityEvent>> controller) {
    LifecycleProvider<ActivityEvent> activity = controller.get();

    TestObserver<Object> testObserver = observable.compose(activity.bindUntilEvent(STOP)).test();

    controller.create();
    testObserver.assertNotComplete();
    controller.start();
    testObserver.assertNotComplete();
    controller.resume();
    testObserver.assertNotComplete();
    controller.pause();
    testObserver.assertNotComplete();
    controller.stop();
    testObserver.assertComplete();
}
 
Example 3
Source File: RxSupportFragmentLifecycleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    TestObserver<Object> testObserver = observable.compose(provider.bindUntilEvent(STOP)).test();

    fragment.onAttach(null);
    testObserver.assertNotComplete();
    fragment.onCreate(null);
    testObserver.assertNotComplete();
    fragment.onViewCreated(null, null);
    testObserver.assertNotComplete();
    fragment.onStart();
    testObserver.assertNotComplete();
    fragment.onResume();
    testObserver.assertNotComplete();
    fragment.onPause();
    testObserver.assertNotComplete();
    fragment.onStop();
    testObserver.assertComplete();
}
 
Example 4
Source File: RxFragmentLifecycleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    TestObserver<Object> testObserver = observable.compose(provider.bindUntilEvent(STOP)).test();

    fragment.onAttach(null);
    testObserver.assertNotComplete();
    fragment.onCreate(null);
    testObserver.assertNotComplete();
    fragment.onViewCreated(null, null);
    testObserver.assertNotComplete();
    fragment.onStart();
    testObserver.assertNotComplete();
    fragment.onResume();
    testObserver.assertNotComplete();
    fragment.onPause();
    testObserver.assertNotComplete();
    fragment.onStop();
    testObserver.assertComplete();
}
 
Example 5
Source File: AndroidLifecycleFragmentTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(LifecycleOwner owner) {
    Fragment fragment = (Fragment) owner;
    ActivityController<?> controller = startFragment(fragment);

    TestObserver<Object> testObserver = observable.compose(AndroidLifecycle.createLifecycleProvider(owner).bindUntilEvent(Lifecycle.Event.ON_STOP)).test();

    testObserver.assertNotComplete();
    controller.start();
    testObserver.assertNotComplete();
    controller.resume();
    testObserver.assertNotComplete();
    controller.pause();
    testObserver.assertNotComplete();
    controller.stop();
    testObserver.assertComplete();
}
 
Example 6
Source File: RxLifecycleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
@Test
public void testBindUntilFragmentEvent() {
    BehaviorSubject<FragmentEvent> lifecycle = BehaviorSubject.create();

    TestObserver<Object> testObserver =
        observable.compose(RxLifecycle.bindUntilEvent(lifecycle, FragmentEvent.STOP)).test();

    lifecycle.onNext(FragmentEvent.ATTACH);
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.CREATE);
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.CREATE_VIEW);
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.START);
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.RESUME);
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.PAUSE);
    testObserver.assertNotComplete();
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.STOP);
    testObserver.assertComplete();
}
 
Example 7
Source File: AndroidLifecycleActivityTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(ActivityController<? extends LifecycleOwner> controller) {
    LifecycleProvider<Lifecycle.Event> activity = AndroidLifecycle.createLifecycleProvider(controller.get());

    TestObserver<Object> testObserver = observable.compose(activity.bindUntilEvent(Lifecycle.Event.ON_STOP)).test();

    controller.create();
    testObserver.assertNotComplete();
    controller.start();
    testObserver.assertNotComplete();
    controller.resume();
    testObserver.assertNotComplete();
    controller.pause();
    testObserver.assertNotComplete();
    controller.stop();
    testObserver.assertComplete();
}
 
Example 8
Source File: UntilEventTransformerObservableTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void noEvents() {
    TestObserver<String> testObserver = stream
        .compose(RxLifecycle.<String, String>bindUntilEvent(lifecycle, "stop"))
        .test();

    stream.onNext("1");
    stream.onNext("2");
    testObserver.assertValues("1", "2");
    testObserver.assertNotComplete();
}
 
Example 9
Source File: RxLifecycleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void testBindActivityLifecycle() {
    BehaviorSubject<ActivityEvent> lifecycle = BehaviorSubject.create();

    lifecycle.onNext(ActivityEvent.CREATE);
    TestObserver<Object> createObserver = observable.compose(RxLifecycleAndroid.bindActivity(lifecycle)).test();

    lifecycle.onNext(ActivityEvent.START);
    createObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(RxLifecycleAndroid.bindActivity(lifecycle)).test();

    lifecycle.onNext(ActivityEvent.RESUME);
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(RxLifecycleAndroid.bindActivity(lifecycle)).test();

    lifecycle.onNext(ActivityEvent.PAUSE);
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();

    TestObserver<Object> pauseObserver = observable.compose(RxLifecycleAndroid.bindActivity(lifecycle)).test();
    lifecycle.onNext(ActivityEvent.STOP);
    createObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(RxLifecycleAndroid.bindActivity(lifecycle)).test();

    lifecycle.onNext(ActivityEvent.DESTROY);
    createObserver.assertComplete();
    stopObserver.assertComplete();
}
 
Example 10
Source File: RxLifecycleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void testBindLifecycle() {
    BehaviorSubject<Lifecycle.Event> lifecycle = BehaviorSubject.create();

    lifecycle.onNext(Lifecycle.Event.ON_CREATE);
    TestObserver<Object> createObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();

    lifecycle.onNext(Lifecycle.Event.ON_START);
    createObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();

    lifecycle.onNext(Lifecycle.Event.ON_RESUME);
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();

    lifecycle.onNext(Lifecycle.Event.ON_PAUSE);
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();

    TestObserver<Object> pauseObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();
    lifecycle.onNext(Lifecycle.Event.ON_STOP);
    createObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();

    lifecycle.onNext(Lifecycle.Event.ON_DESTROY);
    createObserver.assertComplete();
    stopObserver.assertComplete();
}
 
Example 11
Source File: RxActivityLifecycleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
private void testBindToLifecycle(ActivityController<? extends LifecycleProvider<ActivityEvent>> controller) {
    LifecycleProvider<ActivityEvent> activity = controller.get();

    controller.create();
    TestObserver<Object> createObserver = observable.compose(activity.bindToLifecycle()).test();

    controller.start();
    createObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(activity.bindToLifecycle()).test();

    controller.resume();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(activity.bindToLifecycle()).test();

    controller.pause();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(activity.bindToLifecycle()).test();

    controller.stop();
    createObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(activity.bindToLifecycle()).test();

    controller.destroy();
    createObserver.assertComplete();
    stopObserver.assertComplete();
}
 
Example 12
Source File: AndroidLifecycleActivityTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
private void testBindToLifecycle(ActivityController<? extends LifecycleOwner> controller) {
    LifecycleProvider<Lifecycle.Event> provider = AndroidLifecycle.createLifecycleProvider(controller.get());

    controller.create();
    TestObserver<Object> createObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.start();
    createObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.resume();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.pause();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.stop();
    createObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.destroy();
    createObserver.assertComplete();
    stopObserver.assertComplete();
}
 
Example 13
Source File: RxLifecycleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void testBindLifecycleOtherObject() {
    // Ensures it works with other types as well, and not just "Object"
    BehaviorSubject<String> lifecycle = BehaviorSubject.create();
    TestObserver<Object> testObserver = observable.compose(RxLifecycle.bind(lifecycle)).test();
    testObserver.assertNotComplete();
    lifecycle.onNext("");
    testObserver.assertComplete();
}
 
Example 14
Source File: RxLifecycleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void testBindLifecycle() {
    BehaviorSubject<Object> lifecycle = BehaviorSubject.create();
    TestObserver<Object> testObserver = observable.compose(RxLifecycle.bind(lifecycle)).test();
    testObserver.assertNotComplete();
    lifecycle.onNext(new Object());
    testObserver.assertComplete();
}
 
Example 15
Source File: UntilCorrespondingEventTransformerObservableTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void twoOpenEvents() {
    TestObserver<String> testObserver = stream
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    lifecycle.onNext("create");
    stream.onNext("1");
    lifecycle.onNext("start");
    stream.onNext("2");

    testObserver.assertValues("1", "2");
    testObserver.assertNotComplete();
}
 
Example 16
Source File: UntilCorrespondingEventTransformerObservableTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void oneStartEvent() {
    TestObserver<String> testObserver = stream
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    lifecycle.onNext("create");
    stream.onNext("1");
    stream.onNext("2");

    testObserver.assertValues("1", "2");
    testObserver.assertNotComplete();
}
 
Example 17
Source File: UntilCorrespondingEventTransformerObservableTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
@Test
public void noEvents() {
    TestObserver<String> testObserver = stream
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    stream.onNext("1");
    stream.onNext("2");
    testObserver.assertValues("1", "2");
    testObserver.assertNotComplete();
}
 
Example 18
Source File: RxPreferenceFragmentLifecycleTest.java    From RxLifecycle with Apache License 2.0 4 votes vote down vote up
private void testBindToLifecycle(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    fragment.onAttach(null);
    TestObserver<Object> attachObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onCreate(null);
    attachObserver.assertNotComplete();
    TestObserver<Object> createObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onViewCreated(null, null);
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    TestObserver<Object> createViewObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onStart();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onResume();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onPause();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onStop();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDestroyView();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertComplete();
    stopObserver.assertComplete();
    TestObserver<Object> destroyViewObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDestroy();
    attachObserver.assertNotComplete();
    createObserver.assertComplete();
    destroyViewObserver.assertComplete();
    TestObserver<Object> destroyObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDetach();
    attachObserver.assertComplete();
    destroyObserver.assertComplete();
}
 
Example 19
Source File: RxLifecycleTest.java    From RxLifecycle with Apache License 2.0 4 votes vote down vote up
@Test
public void testBindFragmentLifecycle() {
    BehaviorSubject<FragmentEvent> lifecycle = BehaviorSubject.create();

    lifecycle.onNext(FragmentEvent.ATTACH);
    TestObserver<Object> attachObserver = observable.compose(RxLifecycleAndroid.bindFragment(lifecycle)).test();

    lifecycle.onNext(FragmentEvent.CREATE);
    attachObserver.assertNotComplete();
    TestObserver<Object> createObserver = observable.compose(RxLifecycleAndroid.bindFragment(lifecycle)).test();

    lifecycle.onNext(FragmentEvent.CREATE_VIEW);
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    TestObserver<Object> createViewObserver = observable.compose(RxLifecycleAndroid.bindFragment(lifecycle)).test();

    lifecycle.onNext(FragmentEvent.START);
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(RxLifecycleAndroid.bindFragment(lifecycle)).test();

    lifecycle.onNext(FragmentEvent.RESUME);
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(RxLifecycleAndroid.bindFragment(lifecycle)).test();

    lifecycle.onNext(FragmentEvent.PAUSE);
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(RxLifecycleAndroid.bindFragment(lifecycle)).test();

    lifecycle.onNext(FragmentEvent.STOP);
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(RxLifecycleAndroid.bindFragment(lifecycle)).test();

    lifecycle.onNext(FragmentEvent.DESTROY_VIEW);
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertComplete();
    stopObserver.assertComplete();
    TestObserver<Object> destroyViewObserver = observable.compose(RxLifecycleAndroid.bindFragment(lifecycle))
        .test();

    lifecycle.onNext(FragmentEvent.DESTROY);
    attachObserver.assertNotComplete();
    createObserver.assertComplete();
    destroyViewObserver.assertComplete();
    TestObserver<Object> destroyObserver = observable.compose(RxLifecycleAndroid.bindFragment(lifecycle)).test();

    lifecycle.onNext(FragmentEvent.DETACH);
    attachObserver.assertComplete();
    destroyObserver.assertComplete();
}
 
Example 20
Source File: RxSupportFragmentLifecycleTest.java    From RxLifecycle with Apache License 2.0 4 votes vote down vote up
private void testBindToLifecycle(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    fragment.onAttach(null);
    TestObserver<Object> attachObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onCreate(null);
    attachObserver.assertNotComplete();
    TestObserver<Object> createObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onViewCreated(null, null);
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    TestObserver<Object> createViewObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onStart();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onResume();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onPause();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onStop();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDestroyView();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertComplete();
    stopObserver.assertComplete();
    TestObserver<Object> destroyViewObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDestroy();
    attachObserver.assertNotComplete();
    createObserver.assertComplete();
    destroyViewObserver.assertComplete();
    TestObserver<Object> destroyObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDetach();
    attachObserver.assertComplete();
    destroyObserver.assertComplete();
}