| 1 |
/* |
| 2 |
* Copyright (c) 2016-present, RxJava Contributors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 |
* the License for the specific language governing permissions and limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package io.reactivex.rxjava3.internal.operators.flowable; |
| 15 |
|
| 16 |
import static org.junit.Assert.*; |
| 17 |
import static org.mockito.ArgumentMatchers.any; |
| 18 |
import static org.mockito.Mockito.*; |
| 19 |
|
| 20 |
import java.io.IOException; |
| 21 |
import java.util.List; |
| 22 |
import java.util.concurrent.TimeUnit; |
| 23 |
|
| 24 |
import org.junit.Test; |
| 25 |
import org.reactivestreams.*; |
| 26 |
|
| 27 |
import io.reactivex.rxjava3.core.*; |
| 28 |
import io.reactivex.rxjava3.exceptions.TestException; |
| 29 |
import io.reactivex.rxjava3.functions.*; |
| 30 |
import io.reactivex.rxjava3.internal.functions.Functions; |
| 31 |
import io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription; |
| 32 |
import io.reactivex.rxjava3.plugins.RxJavaPlugins; |
| 33 |
import io.reactivex.rxjava3.subscribers.TestSubscriber; |
| 34 |
import io.reactivex.rxjava3.testsupport.*; |
| 35 |
|
| 36 |
public class FlowableAnyTest extends RxJavaTest { |
| 37 |
|
| 38 |
@Test |
| 39 |
public void anyWithTwoItems() { |
| 40 |
Flowable<Integer> w = Flowable.just(1, 2); |
| 41 |
Single<Boolean> single = w.any(new Predicate<Integer>() { |
| 42 |
@Override |
| 43 |
public boolean test(Integer v) { |
| 44 |
return true; |
| 45 |
} |
| 46 |
}); |
| 47 |
|
| 48 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 49 |
|
| 50 |
single.subscribe(observer); |
| 51 |
|
| 52 |
verify(observer, never()).onSuccess(false); |
| 53 |
verify(observer, times(1)).onSuccess(true); |
| 54 |
verify(observer, never()).onError(any(Throwable.class)); |
| 55 |
} |
| 56 |
|
| 57 |
@Test |
| 58 |
public void isEmptyWithTwoItems() { |
| 59 |
Flowable<Integer> w = Flowable.just(1, 2); |
| 60 |
Single<Boolean> single = w.isEmpty(); |
| 61 |
|
| 62 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 63 |
|
| 64 |
single.subscribe(observer); |
| 65 |
|
| 66 |
verify(observer, never()).onSuccess(true); |
| 67 |
verify(observer, times(1)).onSuccess(false); |
| 68 |
verify(observer, never()).onError(any(Throwable.class)); |
| 69 |
} |
| 70 |
|
| 71 |
@Test |
| 72 |
public void anyWithOneItem() { |
| 73 |
Flowable<Integer> w = Flowable.just(1); |
| 74 |
Single<Boolean> single = w.any(new Predicate<Integer>() { |
| 75 |
@Override |
| 76 |
public boolean test(Integer v) { |
| 77 |
return true; |
| 78 |
} |
| 79 |
}); |
| 80 |
|
| 81 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 82 |
|
| 83 |
single.subscribe(observer); |
| 84 |
|
| 85 |
verify(observer, never()).onSuccess(false); |
| 86 |
verify(observer, times(1)).onSuccess(true); |
| 87 |
verify(observer, never()).onError(any(Throwable.class)); |
| 88 |
} |
| 89 |
|
| 90 |
@Test |
| 91 |
public void isEmptyWithOneItem() { |
| 92 |
Flowable<Integer> w = Flowable.just(1); |
| 93 |
Single<Boolean> single = w.isEmpty(); |
| 94 |
|
| 95 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 96 |
|
| 97 |
single.subscribe(observer); |
| 98 |
|
| 99 |
verify(observer, never()).onSuccess(true); |
| 100 |
verify(observer, times(1)).onSuccess(false); |
| 101 |
verify(observer, never()).onError(any(Throwable.class)); |
| 102 |
} |
| 103 |
|
| 104 |
@Test |
| 105 |
public void anyWithEmpty() { |
| 106 |
Flowable<Integer> w = Flowable.empty(); |
| 107 |
Single<Boolean> single = w.any(new Predicate<Integer>() { |
| 108 |
@Override |
| 109 |
public boolean test(Integer v) { |
| 110 |
return true; |
| 111 |
} |
| 112 |
}); |
| 113 |
|
| 114 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 115 |
|
| 116 |
single.subscribe(observer); |
| 117 |
|
| 118 |
verify(observer, times(1)).onSuccess(false); |
| 119 |
verify(observer, never()).onSuccess(true); |
| 120 |
verify(observer, never()).onError(any(Throwable.class)); |
| 121 |
} |
| 122 |
|
| 123 |
@Test |
| 124 |
public void isEmptyWithEmpty() { |
| 125 |
Flowable<Integer> w = Flowable.empty(); |
| 126 |
Single<Boolean> single = w.isEmpty(); |
| 127 |
|
| 128 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 129 |
|
| 130 |
single.subscribe(observer); |
| 131 |
|
| 132 |
verify(observer, times(1)).onSuccess(true); |
| 133 |
verify(observer, never()).onSuccess(false); |
| 134 |
verify(observer, never()).onError(any(Throwable.class)); |
| 135 |
} |
| 136 |
|
| 137 |
@Test |
| 138 |
public void anyWithPredicate1() { |
| 139 |
Flowable<Integer> w = Flowable.just(1, 2, 3); |
| 140 |
Single<Boolean> single = w.any(new Predicate<Integer>() { |
| 141 |
@Override |
| 142 |
public boolean test(Integer t1) { |
| 143 |
return t1 < 2; |
| 144 |
} |
| 145 |
}); |
| 146 |
|
| 147 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 148 |
|
| 149 |
single.subscribe(observer); |
| 150 |
|
| 151 |
verify(observer, never()).onSuccess(false); |
| 152 |
verify(observer, times(1)).onSuccess(true); |
| 153 |
verify(observer, never()).onError(any(Throwable.class)); |
| 154 |
} |
| 155 |
|
| 156 |
@Test |
| 157 |
public void exists1() { |
| 158 |
Flowable<Integer> w = Flowable.just(1, 2, 3); |
| 159 |
Single<Boolean> single = w.any(new Predicate<Integer>() { |
| 160 |
@Override |
| 161 |
public boolean test(Integer t1) { |
| 162 |
return t1 < 2; |
| 163 |
} |
| 164 |
}); |
| 165 |
|
| 166 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 167 |
|
| 168 |
single.subscribe(observer); |
| 169 |
|
| 170 |
verify(observer, never()).onSuccess(false); |
| 171 |
verify(observer, times(1)).onSuccess(true); |
| 172 |
verify(observer, never()).onError(any(Throwable.class)); |
| 173 |
} |
| 174 |
|
| 175 |
@Test |
| 176 |
public void anyWithPredicate2() { |
| 177 |
Flowable<Integer> w = Flowable.just(1, 2, 3); |
| 178 |
Single<Boolean> single = w.any(new Predicate<Integer>() { |
| 179 |
@Override |
| 180 |
public boolean test(Integer t1) { |
| 181 |
return t1 < 1; |
| 182 |
} |
| 183 |
}); |
| 184 |
|
| 185 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 186 |
|
| 187 |
single.subscribe(observer); |
| 188 |
|
| 189 |
verify(observer, times(1)).onSuccess(false); |
| 190 |
verify(observer, never()).onSuccess(true); |
| 191 |
verify(observer, never()).onError(any(Throwable.class)); |
| 192 |
} |
| 193 |
|
| 194 |
@Test |
| 195 |
public void anyWithEmptyAndPredicate() { |
| 196 |
// If the source is empty, always output false. |
| 197 |
Flowable<Integer> w = Flowable.empty(); |
| 198 |
Single<Boolean> single = w.any(new Predicate<Integer>() { |
| 199 |
@Override |
| 200 |
public boolean test(Integer t) { |
| 201 |
return true; |
| 202 |
} |
| 203 |
}); |
| 204 |
|
| 205 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 206 |
|
| 207 |
single.subscribe(observer); |
| 208 |
|
| 209 |
verify(observer, times(1)).onSuccess(false); |
| 210 |
verify(observer, never()).onSuccess(true); |
| 211 |
verify(observer, never()).onError(any(Throwable.class)); |
| 212 |
} |
| 213 |
|
| 214 |
@Test |
| 215 |
public void withFollowingFirst() { |
| 216 |
Flowable<Integer> f = Flowable.fromArray(1, 3, 5, 6); |
| 217 |
Single<Boolean> anyEven = f.any(new Predicate<Integer>() { |
| 218 |
@Override |
| 219 |
public boolean test(Integer i) { |
| 220 |
return i % 2 == 0; |
| 221 |
} |
| 222 |
}); |
| 223 |
|
| 224 |
assertTrue(anyEven.blockingGet()); |
| 225 |
} |
| 226 |
|
| 227 |
@Test |
| 228 |
public void issue1935NoUnsubscribeDownstream() { |
| 229 |
Flowable<Integer> source = Flowable.just(1).isEmpty() |
| 230 |
.flatMapPublisher(new Function<Boolean, Publisher<Integer>>() { |
| 231 |
@Override |
| 232 |
public Publisher<Integer> apply(Boolean t1) { |
| 233 |
return Flowable.just(2).delay(500, TimeUnit.MILLISECONDS); |
| 234 |
} |
| 235 |
}); |
| 236 |
|
| 237 |
assertEquals((Object)2, source.blockingFirst()); |
| 238 |
} |
| 239 |
|
| 240 |
@Test |
| 241 |
public void backpressureIfOneRequestedOneShouldBeDelivered() { |
| 242 |
TestObserverEx<Boolean> to = new TestObserverEx<>(); |
| 243 |
Flowable.just(1).any(new Predicate<Integer>() { |
| 244 |
@Override |
| 245 |
public boolean test(Integer v) { |
| 246 |
return true; |
| 247 |
} |
| 248 |
}).subscribe(to); |
| 249 |
|
| 250 |
to.assertTerminated(); |
| 251 |
to.assertNoErrors(); |
| 252 |
to.assertComplete(); |
| 253 |
to.assertValue(true); |
| 254 |
} |
| 255 |
|
| 256 |
@Test |
| 257 |
public void predicateThrowsExceptionAndValueInCauseMessage() { |
| 258 |
TestObserverEx<Boolean> to = new TestObserverEx<>(); |
| 259 |
final IllegalArgumentException ex = new IllegalArgumentException(); |
| 260 |
|
| 261 |
Flowable.just("Boo!").any(new Predicate<String>() { |
| 262 |
@Override |
| 263 |
public boolean test(String v) { |
| 264 |
throw ex; |
| 265 |
} |
| 266 |
}).subscribe(to); |
| 267 |
|
| 268 |
to.assertTerminated(); |
| 269 |
to.assertNoValues(); |
| 270 |
to.assertNotComplete(); |
| 271 |
to.assertError(ex); |
| 272 |
// FIXME value as last cause? |
| 273 |
// assertTrue(ex.getCause().getMessage().contains("Boo!")); |
| 274 |
} |
| 275 |
|
| 276 |
@Test |
| 277 |
public void anyWithTwoItemsFlowable() { |
| 278 |
Flowable<Integer> w = Flowable.just(1, 2); |
| 279 |
Flowable<Boolean> flowable = w.any(new Predicate<Integer>() { |
| 280 |
@Override |
| 281 |
public boolean test(Integer v) { |
| 282 |
return true; |
| 283 |
} |
| 284 |
}) |
| 285 |
.toFlowable() |
| 286 |
; |
| 287 |
|
| 288 |
Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); |
| 289 |
|
| 290 |
flowable.subscribe(subscriber); |
| 291 |
|
| 292 |
verify(subscriber, never()).onNext(false); |
| 293 |
verify(subscriber, times(1)).onNext(true); |
| 294 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 295 |
verify(subscriber, times(1)).onComplete(); |
| 296 |
} |
| 297 |
|
| 298 |
@Test |
| 299 |
public void isEmptyWithTwoItemsFlowable() { |
| 300 |
Flowable<Integer> w = Flowable.just(1, 2); |
| 301 |
Flowable<Boolean> flowable = w.isEmpty().toFlowable(); |
| 302 |
|
| 303 |
Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); |
| 304 |
|
| 305 |
flowable.subscribe(subscriber); |
| 306 |
|
| 307 |
verify(subscriber, never()).onNext(true); |
| 308 |
verify(subscriber, times(1)).onNext(false); |
| 309 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 310 |
verify(subscriber, times(1)).onComplete(); |
| 311 |
} |
| 312 |
|
| 313 |
@Test |
| 314 |
public void anyWithOneItemFlowable() { |
| 315 |
Flowable<Integer> w = Flowable.just(1); |
| 316 |
Flowable<Boolean> flowable = w.any(new Predicate<Integer>() { |
| 317 |
@Override |
| 318 |
public boolean test(Integer v) { |
| 319 |
return true; |
| 320 |
} |
| 321 |
}).toFlowable(); |
| 322 |
|
| 323 |
Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); |
| 324 |
|
| 325 |
flowable.subscribe(subscriber); |
| 326 |
|
| 327 |
verify(subscriber, never()).onNext(false); |
| 328 |
verify(subscriber, times(1)).onNext(true); |
| 329 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 330 |
verify(subscriber, times(1)).onComplete(); |
| 331 |
} |
| 332 |
|
| 333 |
@Test |
| 334 |
public void isEmptyWithOneItemFlowable() { |
| 335 |
Flowable<Integer> w = Flowable.just(1); |
| 336 |
Single<Boolean> single = w.isEmpty(); |
| 337 |
|
| 338 |
SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); |
| 339 |
|
| 340 |
single.subscribe(observer); |
| 341 |
|
| 342 |
verify(observer, never()).onSuccess(true); |
| 343 |
verify(observer, times(1)).onSuccess(false); |
| 344 |
verify(observer, never()).onError(any(Throwable.class)); |
| 345 |
} |
| 346 |
|
| 347 |
@Test |
| 348 |
public void anyWithEmptyFlowable() { |
| 349 |
Flowable<Integer> w = Flowable.empty(); |
| 350 |
Flowable<Boolean> flowable = w.any(new Predicate<Integer>() { |
| 351 |
@Override |
| 352 |
public boolean test(Integer v) { |
| 353 |
return true; |
| 354 |
} |
| 355 |
}).toFlowable(); |
| 356 |
|
| 357 |
Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); |
| 358 |
|
| 359 |
flowable.subscribe(subscriber); |
| 360 |
|
| 361 |
verify(subscriber, times(1)).onNext(false); |
| 362 |
verify(subscriber, never()).onNext(true); |
| 363 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 364 |
verify(subscriber, times(1)).onComplete(); |
| 365 |
} |
| 366 |
|
| 367 |
@Test |
| 368 |
public void isEmptyWithEmptyFlowable() { |
| 369 |
Flowable<Integer> w = Flowable.empty(); |
| 370 |
Flowable<Boolean> flowable = w.isEmpty().toFlowable(); |
| 371 |
|
| 372 |
Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); |
| 373 |
|
| 374 |
flowable.subscribe(subscriber); |
| 375 |
|
| 376 |
verify(subscriber, times(1)).onNext(true); |
| 377 |
verify(subscriber, never()).onNext(false); |
| 378 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 379 |
verify(subscriber, times(1)).onComplete(); |
| 380 |
} |
| 381 |
|
| 382 |
@Test |
| 383 |
public void anyWithPredicate1Flowable() { |
| 384 |
Flowable<Integer> w = Flowable.just(1, 2, 3); |
| 385 |
Flowable<Boolean> flowable = w.any(new Predicate<Integer>() { |
| 386 |
@Override |
| 387 |
public boolean test(Integer t1) { |
| 388 |
return t1 < 2; |
| 389 |
} |
| 390 |
}).toFlowable(); |
| 391 |
|
| 392 |
Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); |
| 393 |
|
| 394 |
flowable.subscribe(subscriber); |
| 395 |
|
| 396 |
verify(subscriber, never()).onNext(false); |
| 397 |
verify(subscriber, times(1)).onNext(true); |
| 398 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 399 |
verify(subscriber, times(1)).onComplete(); |
| 400 |
} |
| 401 |
|
| 402 |
@Test |
| 403 |
public void exists1Flowable() { |
| 404 |
Flowable<Integer> w = Flowable.just(1, 2, 3); |
| 405 |
Flowable<Boolean> flowable = w.any(new Predicate<Integer>() { |
| 406 |
@Override |
| 407 |
public boolean test(Integer t1) { |
| 408 |
return t1 < 2; |
| 409 |
} |
| 410 |
}).toFlowable(); |
| 411 |
|
| 412 |
Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); |
| 413 |
|
| 414 |
flowable.subscribe(subscriber); |
| 415 |
|
| 416 |
verify(subscriber, never()).onNext(false); |
| 417 |
verify(subscriber, times(1)).onNext(true); |
| 418 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 419 |
verify(subscriber, times(1)).onComplete(); |
| 420 |
} |
| 421 |
|
| 422 |
@Test |
| 423 |
public void anyWithPredicate2Flowable() { |
| 424 |
Flowable<Integer> w = Flowable.just(1, 2, 3); |
| 425 |
Flowable<Boolean> flowable = w.any(new Predicate<Integer>() { |
| 426 |
@Override |
| 427 |
public boolean test(Integer t1) { |
| 428 |
return t1 < 1; |
| 429 |
} |
| 430 |
}).toFlowable(); |
| 431 |
|
| 432 |
Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); |
| 433 |
|
| 434 |
flowable.subscribe(subscriber); |
| 435 |
|
| 436 |
verify(subscriber, times(1)).onNext(false); |
| 437 |
verify(subscriber, never()).onNext(true); |
| 438 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 439 |
verify(subscriber, times(1)).onComplete(); |
| 440 |
} |
| 441 |
|
| 442 |
@Test |
| 443 |
public void anyWithEmptyAndPredicateFlowable() { |
| 444 |
// If the source is empty, always output false. |
| 445 |
Flowable<Integer> w = Flowable.empty(); |
| 446 |
Flowable<Boolean> flowable = w.any(new Predicate<Integer>() { |
| 447 |
@Override |
| 448 |
public boolean test(Integer t) { |
| 449 |
return true; |
| 450 |
} |
| 451 |
}).toFlowable(); |
| 452 |
|
| 453 |
Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); |
| 454 |
|
| 455 |
flowable.subscribe(subscriber); |
| 456 |
|
| 457 |
verify(subscriber, times(1)).onNext(false); |
| 458 |
verify(subscriber, never()).onNext(true); |
| 459 |
verify(subscriber, never()).onError(any(Throwable.class)); |
| 460 |
verify(subscriber, times(1)).onComplete(); |
| 461 |
} |
| 462 |
|
| 463 |
@Test |
| 464 |
public void withFollowingFirstFlowable() { |
| 465 |
Flowable<Integer> f = Flowable.fromArray(1, 3, 5, 6); |
| 466 |
Flowable<Boolean> anyEven = f.any(new Predicate<Integer>() { |
| 467 |
@Override |
| 468 |
public boolean test(Integer i) { |
| 469 |
return i % 2 == 0; |
| 470 |
} |
| 471 |
}).toFlowable(); |
| 472 |
|
| 473 |
assertTrue(anyEven.blockingFirst()); |
| 474 |
} |
| 475 |
|
| 476 |
@Test |
| 477 |
public void issue1935NoUnsubscribeDownstreamFlowable() { |
| 478 |
Flowable<Integer> source = Flowable.just(1).isEmpty() |
| 479 |
.flatMapPublisher(new Function<Boolean, Publisher<Integer>>() { |
| 480 |
@Override |
| 481 |
public Publisher<Integer> apply(Boolean t1) { |
| 482 |
return Flowable.just(2).delay(500, TimeUnit.MILLISECONDS); |
| 483 |
} |
| 484 |
}); |
| 485 |
|
| 486 |
assertEquals((Object)2, source.blockingFirst()); |
| 487 |
} |
| 488 |
|
| 489 |
@Test |
| 490 |
public void backpressureIfNoneRequestedNoneShouldBeDeliveredFlowable() { |
| 491 |
TestSubscriber<Boolean> ts = new TestSubscriber<>(0L); |
| 492 |
|
| 493 |
Flowable.just(1).any(new Predicate<Integer>() { |
| 494 |
@Override |
| 495 |
public boolean test(Integer t) { |
| 496 |
return true; |
| 497 |
} |
| 498 |
}).toFlowable() |
| 499 |
.subscribe(ts); |
| 500 |
|
| 501 |
ts.assertNoValues(); |
| 502 |
ts.assertNoErrors(); |
| 503 |
ts.assertNotComplete(); |
| 504 |
} |
| 505 |
|
| 506 |
@Test |
| 507 |
public void backpressureIfOneRequestedOneShouldBeDeliveredFlowable() { |
| 508 |
TestSubscriberEx<Boolean> ts = new TestSubscriberEx<>(1L); |
| 509 |
Flowable.just(1).any(new Predicate<Integer>() { |
| 510 |
@Override |
| 511 |
public boolean test(Integer v) { |
| 512 |
return true; |
| 513 |
} |
| 514 |
}).toFlowable().subscribe(ts); |
| 515 |
|
| 516 |
ts.assertTerminated(); |
| 517 |
ts.assertNoErrors(); |
| 518 |
ts.assertComplete(); |
| 519 |
ts.assertValue(true); |
| 520 |
} |
| 521 |
|
| 522 |
@Test |
| 523 |
public void predicateThrowsExceptionAndValueInCauseMessageFlowable() { |
| 524 |
TestSubscriberEx<Boolean> ts = new TestSubscriberEx<>(); |
| 525 |
final IllegalArgumentException ex = new IllegalArgumentException(); |
| 526 |
|
| 527 |
Flowable.just("Boo!").any(new Predicate<String>() { |
| 528 |
@Override |
| 529 |
public boolean test(String v) { |
| 530 |
throw ex; |
| 531 |
} |
| 532 |
}).toFlowable().subscribe(ts); |
| 533 |
|
| 534 |
ts.assertTerminated(); |
| 535 |
ts.assertNoValues(); |
| 536 |
ts.assertNotComplete(); |
| 537 |
ts.assertError(ex); |
| 538 |
// FIXME value as last cause? |
| 539 |
// assertTrue(ex.getCause().getMessage().contains("Boo!")); |
| 540 |
} |
| 541 |
|
| 542 |
@Test |
| 543 |
public void dispose() { |
| 544 |
TestHelper.checkDisposed(Flowable.just(1).any(Functions.alwaysTrue()).toFlowable()); |
| 545 |
|
| 546 |
TestHelper.checkDisposed(Flowable.just(1).any(Functions.alwaysTrue())); |
| 547 |
} |
| 548 |
|
| 549 |
@Test |
| 550 |
public void doubleOnSubscribe() { |
| 551 |
TestHelper.checkDoubleOnSubscribeFlowable(new Function<Flowable<Object>, Publisher<Boolean>>() { |
| 552 |
@Override |
| 553 |
public Publisher<Boolean> apply(Flowable<Object> f) throws Exception { |
| 554 |
return f.any(Functions.alwaysTrue()).toFlowable(); |
| 555 |
} |
| 556 |
}); |
| 557 |
|
| 558 |
TestHelper.checkDoubleOnSubscribeFlowableToSingle(new Function<Flowable<Object>, Single<Boolean>>() { |
| 559 |
@Override |
| 560 |
public Single<Boolean> apply(Flowable<Object> f) throws Exception { |
| 561 |
return f.any(Functions.alwaysTrue()); |
| 562 |
} |
| 563 |
}); |
| 564 |
} |
| 565 |
|
| 566 |
@Test |
| 567 |
public void predicateThrowsSuppressOthers() { |
| 568 |
List<Throwable> errors = TestHelper.trackPluginErrors(); |
| 569 |
try { |
| 570 |
new Flowable<Integer>() { |
| 571 |
@Override |
| 572 |
protected void subscribeActual(Subscriber<? super Integer> subscriber) { |
| 573 |
subscriber.onSubscribe(new BooleanSubscription()); |
| 574 |
|
| 575 |
subscriber.onNext(1); |
| 576 |
subscriber.onNext(2); |
| 577 |
subscriber.onError(new IOException()); |
| 578 |
subscriber.onComplete(); |
| 579 |
} |
| 580 |
} |
| 581 |
.any(new Predicate<Integer>() { |
| 582 |
@Override |
| 583 |
public boolean test(Integer v) throws Exception { |
| 584 |
throw new TestException(); |
| 585 |
} |
| 586 |
}) |
| 587 |
.toFlowable() |
| 588 |
.test() |
| 589 |
.assertFailure(TestException.class); |
| 590 |
|
| 591 |
TestHelper.assertUndeliverable(errors, 0, IOException.class); |
| 592 |
} finally { |
| 593 |
RxJavaPlugins.reset(); |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
@Test |
| 598 |
public void badSourceSingle() { |
| 599 |
List<Throwable> errors = TestHelper.trackPluginErrors(); |
| 600 |
try { |
| 601 |
new Flowable<Integer>() { |
| 602 |
@Override |
| 603 |
protected void subscribeActual(Subscriber<? super Integer> subscriber) { |
| 604 |
subscriber.onSubscribe(new BooleanSubscription()); |
| 605 |
subscriber.onError(new TestException("First")); |
| 606 |
|
| 607 |
subscriber.onNext(1); |
| 608 |
subscriber.onError(new TestException("Second")); |
| 609 |
subscriber.onComplete(); |
| 610 |
} |
| 611 |
} |
| 612 |
.any(Functions.alwaysTrue()) |
| 613 |
.to(TestHelper.<Boolean>testConsumer()) |
| 614 |
.assertFailureAndMessage(TestException.class, "First"); |
| 615 |
|
| 616 |
TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); |
| 617 |
} finally { |
| 618 |
RxJavaPlugins.reset(); |
| 619 |
} |
| 620 |
} |
| 621 |
} |