Skip to content

Commit acfe92f

Browse files
committed
Beef up UnsubscribeTester some more
1 parent cce8745 commit acfe92f

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

rxjava-core/src/main/java/rx/testing/UnsubscribeTester.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import rx.util.functions.Action1;
77
import rx.util.functions.Func0;
88

9+
import static org.junit.Assert.assertFalse;
910
import static org.junit.Assert.assertTrue;
1011

1112
public class UnsubscribeTester
1213
{
14+
private boolean isDone = false;
1315
private Subscription subscription;
1416

1517
public UnsubscribeTester() {}
@@ -59,17 +61,19 @@ private static <T> UnsubscribeTester createOnCompleted(Observable<T> observable)
5961
@Override
6062
public void onCompleted()
6163
{
62-
test.doUnsubscribe();
64+
test.doUnsubscribe("onCompleted");
6365
}
6466

6567
@Override
6668
public void onError(Exception e)
6769
{
70+
test.gotEvent("onError");
6871
}
6972

7073
@Override
7174
public void onNext(T args)
7275
{
76+
test.gotEvent("onNext");
7377
}
7478
}));
7579
return test;
@@ -83,17 +87,19 @@ private static <T> UnsubscribeTester createOnError(Observable<T> observable)
8387
@Override
8488
public void onCompleted()
8589
{
90+
test.gotEvent("onCompleted");
8691
}
8792

8893
@Override
8994
public void onError(Exception e)
9095
{
91-
test.doUnsubscribe();
96+
test.doUnsubscribe("onError");
9297
}
9398

9499
@Override
95100
public void onNext(T args)
96101
{
102+
test.gotEvent("onNext");
97103
}
98104
}));
99105
return test;
@@ -107,17 +113,19 @@ private static <T> UnsubscribeTester createOnNext(Observable<T> observable)
107113
@Override
108114
public void onCompleted()
109115
{
116+
test.gotEvent("onCompleted");
110117
}
111118

112119
@Override
113120
public void onError(Exception e)
114121
{
122+
test.gotEvent("onError");
115123
}
116124

117125
@Override
118126
public void onNext(T args)
119127
{
120-
test.doUnsubscribe();
128+
test.doUnsubscribe("onNext");
121129
}
122130
}));
123131
return test;
@@ -128,15 +136,22 @@ private void setSubscription(Subscription subscription)
128136
this.subscription = subscription;
129137
}
130138

131-
private void doUnsubscribe()
139+
private void gotEvent(String event)
132140
{
133-
Subscription subscription = this.subscription;
134-
this.subscription = null;
135-
subscription.unsubscribe();
141+
assertFalse("received " + event + " after unsubscribe", isDone);
142+
}
143+
144+
private void doUnsubscribe(String event)
145+
{
146+
gotEvent(event);
147+
if (subscription != null) {
148+
isDone = true;
149+
subscription.unsubscribe();
150+
}
136151
}
137152

138153
private void assertPassed()
139154
{
140-
assertTrue("expected notification was received", subscription == null);
155+
assertTrue("expected notification was received", isDone);
141156
}
142157
}

0 commit comments

Comments
 (0)