Exemplo n.º 1
0
  /**
   * Occasionally zip may be invoked with 0 observables. Test that we don't block indefinitely
   * instead of immediately invoking zip with 0 argument.
   *
   * <p>We now expect an NoSuchElementException since last() requires at least one value and nothing
   * will be emitted.
   */
  @Test(expected = NoSuchElementException.class)
  public void nonBlockingObservable() {

    final Object invoked = new Object();

    Collection<Observable<Object>> observables = Collections.emptyList();

    Observable<Object> result =
        Observable.zip(
            observables,
            args -> {
              System.out.println("received: " + args);
              assertEquals("No argument should have been passed", 0, args.length);
              return invoked;
            });

    assertSame(invoked, result.toBlocking().last());
  }
Exemplo n.º 2
0
  /** This won't compile if super/extends isn't done correctly on generics */
  @Test
  public void testCovarianceOfZip() {
    Observable<HorrorMovie> horrors = Observable.just(new HorrorMovie());
    Observable<CoolRating> ratings = Observable.just(new CoolRating());

    Observable.<Movie, CoolRating, Result>zip(horrors, ratings, combine)
        .toBlocking()
        .forEach(action);
    Observable.<Movie, CoolRating, Result>zip(horrors, ratings, combine)
        .toBlocking()
        .forEach(action);
    Observable.<Media, Rating, ExtendedResult>zip(horrors, ratings, combine)
        .toBlocking()
        .forEach(extendedAction);
    Observable.<Media, Rating, Result>zip(horrors, ratings, combine).toBlocking().forEach(action);
    Observable.<Media, Rating, ExtendedResult>zip(horrors, ratings, combine)
        .toBlocking()
        .forEach(action);

    Observable.<Movie, CoolRating, Result>zip(horrors, ratings, combine);
  }