Skip to content

Commit

Permalink
2.x : Rename variable name "subject" to "processor" for exact express…
Browse files Browse the repository at this point in the history
…ion (#5721)
  • Loading branch information
ggikko authored and akarnokd committed Nov 14, 2017
1 parent 205375d commit b99efbf
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 211 deletions.
114 changes: 57 additions & 57 deletions src/test/java/io/reactivex/processors/AsyncProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ protected FlowableProcessor<Object> create() {

@Test
public void testNeverCompleted() {
AsyncProcessor<String> subject = AsyncProcessor.create();
AsyncProcessor<String> processor = AsyncProcessor.create();

Subscriber<String> observer = TestHelper.mockSubscriber();
subject.subscribe(observer);
processor.subscribe(observer);

subject.onNext("one");
subject.onNext("two");
subject.onNext("three");
processor.onNext("one");
processor.onNext("two");
processor.onNext("three");

verify(observer, Mockito.never()).onNext(anyString());
verify(observer, Mockito.never()).onError(testException);
Expand All @@ -62,15 +62,15 @@ public void testNeverCompleted() {

@Test
public void testCompleted() {
AsyncProcessor<String> subject = AsyncProcessor.create();
AsyncProcessor<String> processor = AsyncProcessor.create();

Subscriber<String> observer = TestHelper.mockSubscriber();
subject.subscribe(observer);
processor.subscribe(observer);

subject.onNext("one");
subject.onNext("two");
subject.onNext("three");
subject.onComplete();
processor.onNext("one");
processor.onNext("two");
processor.onNext("three");
processor.onComplete();

verify(observer, times(1)).onNext("three");
verify(observer, Mockito.never()).onError(any(Throwable.class));
Expand All @@ -80,13 +80,13 @@ public void testCompleted() {
@Test
@Ignore("Null values not allowed")
public void testNull() {
AsyncProcessor<String> subject = AsyncProcessor.create();
AsyncProcessor<String> processor = AsyncProcessor.create();

Subscriber<String> observer = TestHelper.mockSubscriber();
subject.subscribe(observer);
processor.subscribe(observer);

subject.onNext(null);
subject.onComplete();
processor.onNext(null);
processor.onComplete();

verify(observer, times(1)).onNext(null);
verify(observer, Mockito.never()).onError(any(Throwable.class));
Expand All @@ -95,16 +95,16 @@ public void testNull() {

@Test
public void testSubscribeAfterCompleted() {
AsyncProcessor<String> subject = AsyncProcessor.create();
AsyncProcessor<String> processor = AsyncProcessor.create();

Subscriber<String> observer = TestHelper.mockSubscriber();

subject.onNext("one");
subject.onNext("two");
subject.onNext("three");
subject.onComplete();
processor.onNext("one");
processor.onNext("two");
processor.onNext("three");
processor.onComplete();

subject.subscribe(observer);
processor.subscribe(observer);

verify(observer, times(1)).onNext("three");
verify(observer, Mockito.never()).onError(any(Throwable.class));
Expand All @@ -113,18 +113,18 @@ public void testSubscribeAfterCompleted() {

@Test
public void testSubscribeAfterError() {
AsyncProcessor<String> subject = AsyncProcessor.create();
AsyncProcessor<String> processor = AsyncProcessor.create();

Subscriber<String> observer = TestHelper.mockSubscriber();

subject.onNext("one");
subject.onNext("two");
subject.onNext("three");
processor.onNext("one");
processor.onNext("two");
processor.onNext("three");

RuntimeException re = new RuntimeException("failed");
subject.onError(re);
processor.onError(re);

subject.subscribe(observer);
processor.subscribe(observer);

verify(observer, times(1)).onError(re);
verify(observer, Mockito.never()).onNext(any(String.class));
Expand All @@ -133,18 +133,18 @@ public void testSubscribeAfterError() {

@Test
public void testError() {
AsyncProcessor<String> subject = AsyncProcessor.create();
AsyncProcessor<String> processor = AsyncProcessor.create();

Subscriber<String> observer = TestHelper.mockSubscriber();
subject.subscribe(observer);
processor.subscribe(observer);

subject.onNext("one");
subject.onNext("two");
subject.onNext("three");
subject.onError(testException);
subject.onNext("four");
subject.onError(new Throwable());
subject.onComplete();
processor.onNext("one");
processor.onNext("two");
processor.onNext("three");
processor.onError(testException);
processor.onNext("four");
processor.onError(new Throwable());
processor.onComplete();

verify(observer, Mockito.never()).onNext(anyString());
verify(observer, times(1)).onError(testException);
Expand All @@ -153,23 +153,23 @@ public void testError() {

@Test
public void testUnsubscribeBeforeCompleted() {
AsyncProcessor<String> subject = AsyncProcessor.create();
AsyncProcessor<String> processor = AsyncProcessor.create();

Subscriber<String> observer = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<String>(observer);
subject.subscribe(ts);
processor.subscribe(ts);

subject.onNext("one");
subject.onNext("two");
processor.onNext("one");
processor.onNext("two");

ts.dispose();

verify(observer, Mockito.never()).onNext(anyString());
verify(observer, Mockito.never()).onError(any(Throwable.class));
verify(observer, Mockito.never()).onComplete();

subject.onNext("three");
subject.onComplete();
processor.onNext("three");
processor.onComplete();

verify(observer, Mockito.never()).onNext(anyString());
verify(observer, Mockito.never()).onError(any(Throwable.class));
Expand All @@ -178,12 +178,12 @@ public void testUnsubscribeBeforeCompleted() {

@Test
public void testEmptySubjectCompleted() {
AsyncProcessor<String> subject = AsyncProcessor.create();
AsyncProcessor<String> processor = AsyncProcessor.create();

Subscriber<String> observer = TestHelper.mockSubscriber();
subject.subscribe(observer);
processor.subscribe(observer);

subject.onComplete();
processor.onComplete();

InOrder inOrder = inOrder(observer);
inOrder.verify(observer, never()).onNext(null);
Expand All @@ -204,10 +204,10 @@ public void testSubscribeCompletionRaceCondition() {
* With the synchronization code in place I can not get this to fail on my laptop.
*/
for (int i = 0; i < 50; i++) {
final AsyncProcessor<String> subject = AsyncProcessor.create();
final AsyncProcessor<String> processor = AsyncProcessor.create();
final AtomicReference<String> value1 = new AtomicReference<String>();

subject.subscribe(new Consumer<String>() {
processor.subscribe(new Consumer<String>() {

@Override
public void accept(String t1) {
Expand All @@ -226,15 +226,15 @@ public void accept(String t1) {

@Override
public void run() {
subject.onNext("value");
subject.onComplete();
processor.onNext("value");
processor.onComplete();
}
});

SubjectSubscriberThread t2 = new SubjectSubscriberThread(subject);
SubjectSubscriberThread t3 = new SubjectSubscriberThread(subject);
SubjectSubscriberThread t4 = new SubjectSubscriberThread(subject);
SubjectSubscriberThread t5 = new SubjectSubscriberThread(subject);
SubjectSubscriberThread t2 = new SubjectSubscriberThread(processor);
SubjectSubscriberThread t3 = new SubjectSubscriberThread(processor);
SubjectSubscriberThread t4 = new SubjectSubscriberThread(processor);
SubjectSubscriberThread t5 = new SubjectSubscriberThread(processor);

t2.start();
t3.start();
Expand Down Expand Up @@ -262,18 +262,18 @@ public void run() {

private static class SubjectSubscriberThread extends Thread {

private final AsyncProcessor<String> subject;
private final AsyncProcessor<String> processor;
private final AtomicReference<String> value = new AtomicReference<String>();

SubjectSubscriberThread(AsyncProcessor<String> subject) {
this.subject = subject;
SubjectSubscriberThread(AsyncProcessor<String> processor) {
this.processor = processor;
}

@Override
public void run() {
try {
// a timeout exception will happen if we don't get a terminal state
String v = subject.timeout(2000, TimeUnit.MILLISECONDS).blockingSingle();
String v = processor.timeout(2000, TimeUnit.MILLISECONDS).blockingSingle();
value.set(v);
} catch (Exception e) {
e.printStackTrace();
Expand Down
Loading

0 comments on commit b99efbf

Please sign in to comment.