Java Code Examples for rx.subjects.TestSubject#onCompleted()

The following examples show how to use rx.subjects.TestSubject#onCompleted() . 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: BaseRxLoaderActivityWithFragmentTest.java    From rxloader with Apache License 2.0 6 votes vote down vote up
@SmallTest
public void testLoaderStartRemoveFragment() throws InterruptedException {
    TestSubject<String> subject = TestSubject.create(testScheduler);
    createLoader(getActivity(), subject).start();
    getActivity().waitForStarted();
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            getActivity().removeFragment();
        }
    });
    Thread.sleep(500); // Need to wait for onDestroy() to be called.
    subject.onNext("test");
    subject.onCompleted();
    testScheduler.triggerActions();
    getInstrumentation().waitForIdleSync();

    assertThat(getActivity().<String>getNext()).isNull();
    assertThat(getActivity().isCompleted()).isFalse().as("onCompleted() is not called if the activity is destroyed");
}
 
Example 2
Source File: BaseRxLoaderActivityWithFragmentTest.java    From rxloader with Apache License 2.0 6 votes vote down vote up
@SmallTest
public void testLoaderStartDetachFragment() throws InterruptedException {
    TestSubject<String> subject = TestSubject.create(testScheduler);
    createLoader(getActivity(), subject).start();
    getActivity().waitForStarted();
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            getActivity().detachFragment();
        }
    });
    Thread.sleep(500); // Need to wait for onDestroy() to be called.
    subject.onNext("test");
    subject.onCompleted();
    testScheduler.triggerActions();
    getInstrumentation().waitForIdleSync();

    assertThat(getActivity().<String>getNext()).isNull();
    assertThat(getActivity().isCompleted()).isFalse().as("onCompleted() is not called if the fragment is detached");
}
 
Example 3
Source File: BaseRxLoaderActivityTest.java    From rxloader with Apache License 2.0 6 votes vote down vote up
@SmallTest
public void testLoaderStartRotationNext() throws InterruptedException {
    TestSubject<String> subject = TestSubject.create(testScheduler);
    createLoader(getActivity(), subject).start();
    getActivity().waitForStarted();
    subject.onNext("test");
    subject.onCompleted();
    testScheduler.triggerActions();
    getActivity().waitForNext();
    getActivity().waitForCompleted();
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            getActivity().recreate();
        }
    });
    createLoader(getActivity(), subject);
    getActivity().waitForNext();
    getActivity().waitForCompleted();

    assertThat(getActivity().<String>getNext()).isEqualTo("test").as("result is delivered again after a configuration change");
    assertThat(getActivity().isCompleted()).isTrue().as("onCompleted() is called again after a configuration change");
}
 
Example 4
Source File: BaseRxLoaderActivityTest.java    From rxloader with Apache License 2.0 6 votes vote down vote up
@SmallTest
public void testLoaderStartNextAfterDestroyed() throws InterruptedException {
    TestSubject<String> subject = TestSubject.create(testScheduler);
    createLoader(getActivity(), subject).start();
    getActivity().waitForStarted();
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            getActivity().finish();
        }
    });
    Thread.sleep(500); // Need to wait for onDestroy() to be called.
    subject.onNext("test");
    subject.onCompleted();
    testScheduler.triggerActions();
    getInstrumentation().waitForIdleSync();

    assertThat(getActivity().<String>getNext()).isNull();
    assertThat(getActivity().isCompleted()).isFalse().as("onCompleted() is not called if the activity is destroyed");

    // Needed to recreate the activity since the test runner expects it to exist. 
    getActivity();
}
 
Example 5
Source File: BaseRxLoaderActivityTest.java    From rxloader with Apache License 2.0 6 votes vote down vote up
@SmallTest
public void testLoaderStartNextRotationClear() throws InterruptedException {
    TestSubject<String> subject = TestSubject.create(testScheduler);
    RxLoader<String> loader = createLoader(getActivity(), subject).start();
    getActivity().waitForStarted();
    subject.onNext("test");
    subject.onCompleted();
    testScheduler.triggerActions();
    getActivity().waitForNext();
    getActivity().waitForCompleted();
    loader.clear();
    T newActivity = recreateActivity();
    createLoader(newActivity, subject);
    getInstrumentation().waitForIdleSync();
    Thread.sleep(500); // Give loader a chance to deliver the result.

    assertThat(newActivity.<String>getNext()).isNull();
    assertThat(newActivity.isCompleted()).isFalse().as("onCompleted() is not called if the result was cleared");
}
 
Example 6
Source File: BaseRxLoaderActivityWithFragmentTest.java    From rxloader with Apache License 2.0 5 votes vote down vote up
@SmallTest
public void testLoaderStartDetachAndAttachFragment() throws InterruptedException {
    TestSubject<String> subject = TestSubject.create(testScheduler);
    createLoader(getActivity(), subject).start();
    getActivity().waitForStarted();
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            getActivity().detachFragment();
        }
    });
    Thread.sleep(500); // Need to wait for onDestroy() to be called.
    subject.onNext("test");
    subject.onCompleted();
    testScheduler.triggerActions();
    getInstrumentation().waitForIdleSync();
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            getActivity().reattchFragment();
        }
    });
    getInstrumentation().waitForIdleSync();
    createLoader(getActivity(), subject);
    getActivity().waitForNext();
    getActivity().waitForCompleted();

    assertThat(getActivity().<String>getNext()).isEqualTo("test").as("result is value delivered from observable");
    assertThat(getActivity().isCompleted()).isTrue().as("onCompleted() called when fragment is reattached");
}
 
Example 7
Source File: BaseRxLoaderActivityWithFragmentTest.java    From rxloader with Apache License 2.0 5 votes vote down vote up
@SmallTest
public void testMultipleLoaderFragments() throws InterruptedException {
    final String fragment1 = "fragment1";
    final String fragment2 = "fragment2";
    TestSubject<String> subject1 = TestSubject.create(testScheduler);
    TestSubject<String> subject2 = TestSubject.create(testScheduler);
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            getActivity().addFragment(fragment1);
            getActivity().addFragment(fragment2);
        }
    });
    createLoader(subject1, fragment1).start();
    createLoader(subject2, fragment2).start();
    getActivity().waitForStarted(fragment1); 
    getActivity().waitForStarted(fragment2);
    subject1.onNext("test1");
    subject2.onNext("test2");
    subject1.onCompleted();
    subject2.onCompleted();
    testScheduler.triggerActions();
    getActivity().waitForNext(fragment1);
    getActivity().waitForCompleted(fragment1);
    getActivity().waitForNext(fragment2);
    getActivity().waitForCompleted(fragment2);

    assertThat(getActivity().<String>getNext(fragment1)).isEqualTo("test1").as("result is value delivered from observable");
    assertThat(getActivity().isCompleted(fragment1)).isTrue().as("onCompleted() called when observable completed");

    assertThat(getActivity().<String>getNext(fragment2)).isEqualTo("test2").as("result is value delivered from observable");
    assertThat(getActivity().isCompleted(fragment2)).isTrue().as("onCompleted() called when observable completed");
}
 
Example 8
Source File: BaseRxLoaderActivityTest.java    From rxloader with Apache License 2.0 5 votes vote down vote up
@SmallTest
public void testLoaderStartNext() throws InterruptedException {
    final TestSubject<String> subject = TestSubject.create(testScheduler);
    createLoader(getActivity(), subject).start();
    getActivity().waitForStarted();
    subject.onNext("test");
    subject.onCompleted();
    testScheduler.triggerActions();
    getActivity().waitForNext();
    getActivity().waitForCompleted();

    assertThat(getActivity().<String>getNext()).isEqualTo("test").as("result is value delivered from observable");
    assertThat(getActivity().isCompleted()).isTrue().as("onCompleted() called when observable completed");
}
 
Example 9
Source File: BaseRxLoaderActivityTest.java    From rxloader with Apache License 2.0 5 votes vote down vote up
@SmallTest
public void testLoaderStartError() throws InterruptedException {
    TestSubject<String> subject = TestSubject.create(testScheduler);
    createLoader(getActivity(), subject).start();
    getActivity().waitForStarted();
    subject.onError(new Exception("test"));
    subject.onCompleted();
    testScheduler.triggerActions();
    getActivity().waitForError();

    assertThat(getActivity().<String>getError()).hasMessage("test").as("onError() is called when sent by observable");
}