Skip to content

Commit 4c0d9c9

Browse files
artem-zinnatullinakarnokd
authored andcommitted
2.x: Common test classes for Processors. (#4882)
1 parent 442c6ce commit 4c0d9c9

File tree

7 files changed

+183
-283
lines changed

7 files changed

+183
-283
lines changed

src/test/java/io/reactivex/processors/AsyncProcessorTest.java

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,37 @@
1313

1414
package io.reactivex.processors;
1515

16-
import static org.junit.Assert.*;
17-
import static org.mockito.ArgumentMatchers.*;
18-
import static org.mockito.Mockito.*;
19-
20-
import java.util.concurrent.TimeUnit;
21-
import java.util.concurrent.atomic.AtomicReference;
22-
23-
import org.junit.*;
24-
import org.mockito.*;
25-
import org.reactivestreams.Subscriber;
26-
2716
import io.reactivex.TestHelper;
2817
import io.reactivex.exceptions.TestException;
2918
import io.reactivex.functions.Consumer;
3019
import io.reactivex.internal.fuseable.QueueSubscription;
3120
import io.reactivex.internal.subscriptions.BooleanSubscription;
3221
import io.reactivex.schedulers.Schedulers;
33-
import io.reactivex.subscribers.*;
22+
import io.reactivex.subscribers.SubscriberFusion;
23+
import io.reactivex.subscribers.TestSubscriber;
24+
import org.junit.Ignore;
25+
import org.junit.Test;
26+
import org.mockito.InOrder;
27+
import org.mockito.Mockito;
28+
import org.reactivestreams.Subscriber;
3429

35-
public class AsyncProcessorTest {
30+
import java.util.concurrent.TimeUnit;
31+
import java.util.concurrent.atomic.AtomicReference;
32+
33+
import static org.junit.Assert.*;
34+
import static org.mockito.ArgumentMatchers.any;
35+
import static org.mockito.ArgumentMatchers.anyString;
36+
import static org.mockito.Mockito.*;
37+
38+
public class AsyncProcessorTest extends DelayedFlowableProcessorTest<Object> {
3639

3740
private final Throwable testException = new Throwable();
3841

42+
@Override
43+
protected FlowableProcessor<Object> create() {
44+
return AsyncProcessor.create();
45+
}
46+
3947
@Test
4048
public void testNeverCompleted() {
4149
AsyncProcessor<String> subject = AsyncProcessor.create();
@@ -422,58 +430,6 @@ public void fusionOfflie() {
422430
.assertResult(1);
423431
}
424432

425-
@Test
426-
public void onNextNull() {
427-
final AsyncProcessor<Object> p = AsyncProcessor.create();
428-
429-
p.onNext(null);
430-
431-
p.test()
432-
.assertNoValues()
433-
.assertError(NullPointerException.class)
434-
.assertErrorMessage("onNext called with null. Null values are generally not allowed in 2.x operators and sources.");
435-
}
436-
437-
@Test
438-
public void onErrorNull() {
439-
final AsyncProcessor<Object> p = AsyncProcessor.create();
440-
441-
p.onError(null);
442-
443-
p.test()
444-
.assertNoValues()
445-
.assertError(NullPointerException.class)
446-
.assertErrorMessage("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
447-
}
448-
449-
@Test
450-
public void onNextNullDelayed() {
451-
final AsyncProcessor<Object> p = AsyncProcessor.create();
452-
453-
TestSubscriber<Object> ts = p.test();
454-
455-
p.onNext(null);
456-
457-
ts
458-
.assertNoValues()
459-
.assertError(NullPointerException.class)
460-
.assertErrorMessage("onNext called with null. Null values are generally not allowed in 2.x operators and sources.");
461-
}
462-
463-
@Test
464-
public void onErrorNullDelayed() {
465-
final AsyncProcessor<Object> p = AsyncProcessor.create();
466-
467-
TestSubscriber<Object> ts = p.test();
468-
469-
p.onError(null);
470-
471-
ts
472-
.assertNoValues()
473-
.assertError(NullPointerException.class)
474-
.assertErrorMessage("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
475-
}
476-
477433
@Test
478434
public void onSubscribeAfterDone() {
479435
AsyncProcessor<Object> p = AsyncProcessor.create();

src/test/java/io/reactivex/processors/BehaviorProcessorTest.java

Lines changed: 27 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,41 @@
1313

1414
package io.reactivex.processors;
1515

16-
import static org.junit.Assert.*;
17-
import static org.mockito.ArgumentMatchers.any;
18-
import static org.mockito.Mockito.*;
19-
20-
import java.util.List;
21-
import java.util.concurrent.*;
22-
import java.util.concurrent.atomic.AtomicReference;
23-
24-
import org.junit.*;
25-
import org.mockito.*;
26-
import org.reactivestreams.Subscriber;
27-
28-
import io.reactivex.*;
29-
import io.reactivex.exceptions.*;
16+
import io.reactivex.Flowable;
17+
import io.reactivex.Scheduler;
18+
import io.reactivex.TestHelper;
19+
import io.reactivex.exceptions.MissingBackpressureException;
20+
import io.reactivex.exceptions.TestException;
3021
import io.reactivex.functions.Function;
3122
import io.reactivex.internal.subscriptions.BooleanSubscription;
3223
import io.reactivex.plugins.RxJavaPlugins;
3324
import io.reactivex.schedulers.Schedulers;
34-
import io.reactivex.subscribers.*;
25+
import io.reactivex.subscribers.DefaultSubscriber;
26+
import io.reactivex.subscribers.TestSubscriber;
27+
import org.junit.Assert;
28+
import org.junit.Test;
29+
import org.mockito.InOrder;
30+
import org.mockito.Mockito;
31+
import org.reactivestreams.Subscriber;
3532

36-
public class BehaviorProcessorTest {
33+
import java.util.List;
34+
import java.util.concurrent.CountDownLatch;
35+
import java.util.concurrent.TimeUnit;
36+
import java.util.concurrent.atomic.AtomicReference;
37+
38+
import static org.junit.Assert.*;
39+
import static org.mockito.ArgumentMatchers.any;
40+
import static org.mockito.Mockito.*;
41+
42+
public class BehaviorProcessorTest extends DelayedFlowableProcessorTest<Object> {
3743

3844
private final Throwable testException = new Throwable();
3945

46+
@Override
47+
protected FlowableProcessor<Object> create() {
48+
return BehaviorProcessor.create();
49+
}
50+
4051
@Test
4152
public void testThatSubscriberReceivesDefaultValueAndSubsequentEvents() {
4253
BehaviorProcessor<String> subject = BehaviorProcessor.createDefault("default");
@@ -563,66 +574,6 @@ public void testCurrentStateMethodsError() {
563574
assertTrue(as.getThrowable() instanceof TestException);
564575
}
565576

566-
@Test
567-
public void onNextNull() {
568-
final BehaviorProcessor<Object> p = BehaviorProcessor.create();
569-
570-
p.onNext(null);
571-
572-
p.test()
573-
.assertNoValues()
574-
.assertError(NullPointerException.class)
575-
.assertErrorMessage("onNext called with null. Null values are generally not allowed in 2.x operators and sources.");
576-
}
577-
578-
@Test
579-
public void onErrorNull() {
580-
final BehaviorProcessor<Object> p = BehaviorProcessor.create();
581-
582-
p.onError(null);
583-
584-
p.test()
585-
.assertNoValues()
586-
.assertError(NullPointerException.class)
587-
.assertErrorMessage("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
588-
}
589-
590-
@Test
591-
public void onNextNullDelayed() {
592-
final BehaviorProcessor<Object> p = BehaviorProcessor.create();
593-
594-
TestSubscriber<Object> ts = p.test();
595-
596-
assertTrue(p.hasSubscribers());
597-
598-
p.onNext(null);
599-
600-
assertFalse(p.hasSubscribers());
601-
602-
ts
603-
.assertNoValues()
604-
.assertError(NullPointerException.class)
605-
.assertErrorMessage("onNext called with null. Null values are generally not allowed in 2.x operators and sources.");
606-
}
607-
608-
@Test
609-
public void onErrorNullDelayed() {
610-
final BehaviorProcessor<Object> p = BehaviorProcessor.create();
611-
612-
TestSubscriber<Object> ts = p.test();
613-
614-
assertTrue(p.hasSubscribers());
615-
616-
p.onError(null);
617-
618-
assertFalse(p.hasSubscribers());
619-
620-
ts
621-
.assertNoValues()
622-
.assertError(NullPointerException.class)
623-
.assertErrorMessage("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
624-
}
625-
626577
@Test
627578
public void cancelOnArrival() {
628579
BehaviorProcessor<Object> p = BehaviorProcessor.create();
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.reactivex.processors;
2+
3+
import io.reactivex.subscribers.TestSubscriber;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.assertFalse;
7+
8+
public abstract class DelayedFlowableProcessorTest<T> extends FlowableProcessorTest<T> {
9+
10+
@Test
11+
public void onNextNullDelayed() {
12+
final FlowableProcessor<T> p = create();
13+
14+
TestSubscriber<T> ts = p.test();
15+
16+
p.onNext(null);
17+
18+
19+
20+
ts
21+
.assertNoValues()
22+
.assertError(NullPointerException.class)
23+
.assertErrorMessage("onNext called with null. Null values are generally not allowed in 2.x operators and sources.");
24+
}
25+
26+
@Test
27+
public void onErrorNullDelayed() {
28+
final FlowableProcessor<T> p = create();
29+
30+
TestSubscriber<T> ts = p.test();
31+
32+
p.onError(null);
33+
assertFalse(p.hasSubscribers());
34+
35+
ts
36+
.assertNoValues()
37+
.assertError(NullPointerException.class)
38+
.assertErrorMessage("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
39+
}
40+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.reactivex.processors;
2+
3+
import org.junit.Test;
4+
5+
public abstract class FlowableProcessorTest<T> {
6+
7+
protected abstract FlowableProcessor<T> create();
8+
9+
@Test
10+
public void onNextNull() {
11+
final FlowableProcessor<T> p = create();
12+
13+
p.onNext(null);
14+
15+
p.test()
16+
.assertNoValues()
17+
.assertError(NullPointerException.class)
18+
.assertErrorMessage("onNext called with null. Null values are generally not allowed in 2.x operators and sources.");
19+
}
20+
21+
@Test
22+
public void onErrorNull() {
23+
final FlowableProcessor<T> p = create();
24+
25+
p.onError(null);
26+
27+
p.test()
28+
.assertNoValues()
29+
.assertError(NullPointerException.class)
30+
.assertErrorMessage("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
31+
}
32+
}

src/test/java/io/reactivex/processors/PublishProcessorTest.java

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,34 @@
1313

1414
package io.reactivex.processors;
1515

16-
import static org.junit.Assert.*;
17-
import static org.mockito.Mockito.*;
16+
import io.reactivex.Flowable;
17+
import io.reactivex.TestHelper;
18+
import io.reactivex.exceptions.MissingBackpressureException;
19+
import io.reactivex.exceptions.TestException;
20+
import io.reactivex.functions.Consumer;
21+
import io.reactivex.functions.Function;
22+
import io.reactivex.schedulers.Schedulers;
23+
import io.reactivex.subscribers.DefaultSubscriber;
24+
import io.reactivex.subscribers.TestSubscriber;
25+
import org.junit.Test;
26+
import org.mockito.InOrder;
27+
import org.mockito.Mockito;
28+
import org.reactivestreams.Subscriber;
29+
import org.reactivestreams.Subscription;
1830

1931
import java.util.ArrayList;
20-
import java.util.concurrent.*;
32+
import java.util.concurrent.TimeUnit;
2133
import java.util.concurrent.atomic.AtomicInteger;
2234

23-
import org.junit.Test;
24-
import org.mockito.*;
25-
import org.reactivestreams.*;
35+
import static org.junit.Assert.*;
36+
import static org.mockito.Mockito.*;
2637

27-
import io.reactivex.*;
28-
import io.reactivex.exceptions.*;
29-
import io.reactivex.functions.*;
30-
import io.reactivex.schedulers.Schedulers;
31-
import io.reactivex.subscribers.*;
38+
public class PublishProcessorTest extends FlowableProcessorTest<Object> {
3239

33-
public class PublishProcessorTest {
40+
@Override
41+
protected FlowableProcessor<Object> create() {
42+
return PublishProcessor.create();
43+
}
3444

3545
@Test
3646
public void testCompleted() {
@@ -615,27 +625,5 @@ public void run() {
615625
}
616626
}
617627

618-
@Test
619-
public void onNextNull() {
620-
final PublishProcessor<Object> p = PublishProcessor.create();
621-
622-
p.onNext(null);
623-
624-
p.test()
625-
.assertNoValues()
626-
.assertError(NullPointerException.class)
627-
.assertErrorMessage("onNext called with null. Null values are generally not allowed in 2.x operators and sources.");
628-
}
629628

630-
@Test
631-
public void onErrorNull() {
632-
final PublishProcessor<Object> p = PublishProcessor.create();
633-
634-
p.onError(null);
635-
636-
p.test()
637-
.assertNoValues()
638-
.assertError(NullPointerException.class)
639-
.assertErrorMessage("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
640-
}
641629
}

0 commit comments

Comments
 (0)