24
24
import rx .Subscriber ;
25
25
26
26
/**
27
- * Subscriber usable for unit testing to perform assertions, inspect received events or wrap a mocked
27
+ * Subscriber usable for unit testing to perform assertions, inspect received events, or wrap a mocked
28
28
* Subscriber.
29
29
*/
30
30
public class TestSubscriber <T > extends Subscriber <T > {
@@ -73,10 +73,10 @@ public void onCompleted() {
73
73
}
74
74
75
75
/**
76
- * Get the {@link Notification}s representing each time this subscriber was notified of sequence completion
76
+ * Get the {@link Notification}s representing each time this Subscriber was notified of sequence completion
77
77
* via {@link #onCompleted}, as a {@link List}.
78
78
*
79
- * @return a list of Notifications representing calls to this subscriber 's {@link #onCompleted} method
79
+ * @return a list of Notifications representing calls to this Subscriber 's {@link #onCompleted} method
80
80
*/
81
81
public List <Notification <T >> getOnCompletedEvents () {
82
82
return testObserver .getOnCompletedEvents ();
@@ -93,9 +93,9 @@ public void onError(Throwable e) {
93
93
}
94
94
95
95
/**
96
- * Get the {@link Throwable}s this subscriber was notified of via {@link #onError} as a {@link List}.
96
+ * Get the {@link Throwable}s this Subscriber was notified of via {@link #onError} as a {@link List}.
97
97
*
98
- * @return a list of Throwables passed to this subscriber 's {@link #onError} method
98
+ * @return a list of the Throwables that were passed to this Subscriber 's {@link #onError} method
99
99
*/
100
100
public List <Throwable > getOnErrorEvents () {
101
101
return testObserver .getOnErrorEvents ();
@@ -108,16 +108,16 @@ public void onNext(T t) {
108
108
}
109
109
110
110
/**
111
- * Get the sequence of items observed by this subscriber , as an ordered {@link List}.
111
+ * Get the sequence of items observed by this Subscriber , as an ordered {@link List}.
112
112
*
113
- * @return a list of items observed by this subscriber , in the order in which they were observed
113
+ * @return a list of items observed by this Subscriber , in the order in which they were observed
114
114
*/
115
115
public List <T > getOnNextEvents () {
116
116
return testObserver .getOnNextEvents ();
117
117
}
118
118
119
119
/**
120
- * Assert that a particular sequence of items was received in order.
120
+ * Assert that a particular sequence of items was received by this Subscriber in order.
121
121
*
122
122
* @param items
123
123
* the sequence of items expected to have been observed
@@ -150,14 +150,24 @@ public void assertUnsubscribed() {
150
150
}
151
151
}
152
152
153
+ /**
154
+ * Assert that this {@code Subscriber} has received no {@code onError} notifications.
155
+ *
156
+ * @throws AssertionError
157
+ * if this {@code Subscriber} has received one or more {@code onError} notifications
158
+ */
153
159
public void assertNoErrors () {
154
160
if (getOnErrorEvents ().size () > 0 ) {
155
161
throw new AssertionError ("Unexpected onError events: " + getOnErrorEvents ().size (), getOnErrorEvents ().get (0 ));
156
162
}
157
163
}
158
164
159
165
/**
160
- * @warn javadoc missing
166
+ * Blocks until this Subscriber receives a notification that the Observable is complete (either an
167
+ * {@code onCompleted} or {@code onError} notification).
168
+ *
169
+ * @throws RuntimeException
170
+ * if the Subscriber is interrupted before the Observable is able to complete
161
171
*/
162
172
public void awaitTerminalEvent () {
163
173
try {
@@ -168,9 +178,15 @@ public void awaitTerminalEvent() {
168
178
}
169
179
170
180
/**
171
- * @warn javadoc missing
181
+ * Blocks until this Subscriber receives a notification that the Observable is complete (either an
182
+ * {@code onCompleted} or {@code onError} notification), or until a timeout expires.
183
+ *
172
184
* @param timeout
185
+ * the duration of the timeout
173
186
* @param unit
187
+ * the units in which {@code timeout} is expressed
188
+ * @throws RuntimeException
189
+ * if the Subscriber is interrupted before the Observable is able to complete
174
190
*/
175
191
public void awaitTerminalEvent (long timeout , TimeUnit unit ) {
176
192
try {
@@ -181,9 +197,15 @@ public void awaitTerminalEvent(long timeout, TimeUnit unit) {
181
197
}
182
198
183
199
/**
184
- * @warn javadoc missing
200
+ * Blocks until this Subscriber receives a notification that the Observable is complete (either an
201
+ * {@code onCompleted} or {@code onError} notification), or until a timeout expires; if the Subscriber
202
+ * is interrupted before either of these events take place, this method unsubscribes the Subscriber from the
203
+ * Observable).
204
+ *
185
205
* @param timeout
206
+ * the duration of the timeout
186
207
* @param unit
208
+ * the units in which {@code timeout} is expressed
187
209
*/
188
210
public void awaitTerminalEventAndUnsubscribeOnTimeout (long timeout , TimeUnit unit ) {
189
211
try {
@@ -194,7 +216,10 @@ public void awaitTerminalEventAndUnsubscribeOnTimeout(long timeout, TimeUnit uni
194
216
}
195
217
196
218
/**
197
- * @warn javadoc missing
219
+ * Returns the last thread that was in use when an item or notification was received by this Subscriber.
220
+ *
221
+ * @return the {@code Thread} on which this Subscriber last received an item or notification from the
222
+ * Observable it is subscribed to
198
223
*/
199
224
public Thread getLastSeenThread () {
200
225
return lastSeenThread ;
0 commit comments