Java Code Examples for io.reactivex.subscribers.TestSubscriber#assertSubscribed()

The following examples show how to use io.reactivex.subscribers.TestSubscriber#assertSubscribed() . 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: UniToPublisherTest.java    From smallrye-mutiny with Apache License 2.0 6 votes vote down vote up
@Test
public void testCancellationBetweenRequestAndValue() {
    // TODO This is a very broken implementation of "delay" - to be replace once delay is implemented
    executor = Executors.newSingleThreadExecutor();
    Publisher<Integer> publisher = Uni.createFrom().item(1).emitOn(executor).map(x -> {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        return x;
    }).convert().toPublisher();

    assertThat(publisher).isNotNull();
    TestSubscriber<Integer> test = Flowable.fromPublisher(publisher).test(0);
    test.assertSubscribed();
    test.request(1);
    test.cancel();
    assertThat(test.isCancelled()).isTrue();
    test.assertNotTerminated();
    test.assertNever(1);
}
 
Example 2
Source File: Modern_Testing.java    From Reactive-Programming-With-Java-9 with MIT License 6 votes vote down vote up
@Test
public void test_just_Flowable() {

	Flowable<String> observable = Flowable.just("mango", "papaya", "guava");
	TestSubscriber<String> testSubscriber = new TestSubscriber<>();

	observable.subscribe(testSubscriber);

	List<String> items = testSubscriber.values();
	testSubscriber.assertComplete();
	testSubscriber.assertSubscribed();
	testSubscriber.assertNoErrors();
	testSubscriber.assertValueCount(3);
	testSubscriber.assertValues("mango", "papaya", "guava");

}
 
Example 3
Source File: UniToPublisherTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithImmediateValueWithRequest() {
    Publisher<Integer> publisher = Uni.createFrom().item(1).convert().toPublisher();
    assertThat(publisher).isNotNull();
    TestSubscriber<Integer> test = Flowable.fromPublisher(publisher).test(0);
    test.assertSubscribed();
    test.request(1);
    test.assertResult(1);
    test.assertComplete();
}
 
Example 4
Source File: UniToPublisherTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithImmediateValueWithRequests() {
    Publisher<Integer> publisher = Uni.createFrom().item(1).convert().toPublisher();
    assertThat(publisher).isNotNull();
    TestSubscriber<Integer> test = Flowable.fromPublisher(publisher).test(0);
    test.assertSubscribed();
    test.request(20);
    test.assertResult(1);
    test.assertComplete();
}
 
Example 5
Source File: UniToPublisherTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidRequest() {
    Publisher<Integer> publisher = Uni.createFrom().item(1).convert().toPublisher();
    assertThat(publisher).isNotNull();
    TestSubscriber<Integer> test = Flowable.fromPublisher(publisher).test(0);
    test.assertSubscribed();
    test.request(0);
    test.assertError(IllegalArgumentException.class);
    test.assertTerminated();
}
 
Example 6
Source File: UniToPublisherTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithImmediateValueWithOneRequestAndImmediateCancellation() {
    Publisher<Integer> publisher = Uni.createFrom().item(1).convert().toPublisher();
    assertThat(publisher).isNotNull();
    TestSubscriber<Integer> test = Flowable.fromPublisher(publisher).test(1, true);
    test.assertSubscribed();
    assertThat(test.isCancelled()).isTrue();
    test.assertNotTerminated();
    test.assertNever(1);
}
 
Example 7
Source File: UniToPublisherTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testCancellationBetweenSubscriptionAndRequest() {
    Publisher<Integer> publisher = Uni.createFrom().item(1).convert().toPublisher();
    assertThat(publisher).isNotNull();
    TestSubscriber<Integer> test = Flowable.fromPublisher(publisher).test(0);
    test.assertSubscribed();
    test.cancel();
    assertThat(test.isCancelled()).isTrue();
    test.assertNotTerminated();
    test.assertNever(1);
}
 
Example 8
Source File: UniToPublisherTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testCancellationAfterValue() {
    Publisher<Integer> publisher = Uni.createFrom().item(1).convert().toPublisher();
    assertThat(publisher).isNotNull();
    TestSubscriber<Integer> test = Flowable.fromPublisher(publisher).test(0);
    test.assertSubscribed();
    test.request(1);
    // Immediate emission, so cancel is called after the emission.
    test.cancel();
    assertThat(test.isCancelled()).isTrue();
    test.assertValue(1);
    test.assertComplete();
}
 
Example 9
Source File: RxJavaDemoTest.java    From reactive-streams-in-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubscriberWithException() {
    Flowable<Integer> flowable = Flowable.create(source -> {
        source.onNext(1);
        source.onError(new RuntimeException());
    }, BackpressureStrategy.LATEST);

    TestSubscriber<Integer> ts = flowable.test();

    ts.assertSubscribed();
    ts.assertError(RuntimeException.class);
}