Ejemplo n.º 1
0
    @SuppressWarnings("unchecked")
    /* mock calls don't do generics */
    @Test
    public void testAggregatorError() {
      FuncN<String> zipr = getConcatZipr();
      /* create the aggregator which will execute the zip function when all Observables provide values */
      Aggregator<String> a = new Aggregator<String>(zipr);

      /* define a Observer to receive aggregated events */
      Observer<String> aObserver = mock(Observer.class);
      a.call(aObserver);

      /* mock the Observable Observers that are 'pushing' data for us */
      ZipObserver<String, String> r1 = mock(ZipObserver.class);
      ZipObserver<String, String> r2 = mock(ZipObserver.class);

      /* pretend we're starting up */
      a.addObserver(r1);
      a.addObserver(r2);

      /* simulate the Observables pushing data into the aggregator */
      a.next(r1, "hello");
      a.next(r2, "world");

      verify(aObserver, never()).onError(any(Exception.class));
      verify(aObserver, never()).onCompleted();
      verify(aObserver, times(1)).onNext("helloworld");

      a.error(r1, new RuntimeException(""));
      a.next(r1, "hello");
      a.next(r2, "again");

      verify(aObserver, times(1)).onError(any(Exception.class));
      verify(aObserver, never()).onCompleted();
      // we don't want to be called again after an error
      verify(aObserver, times(0)).onNext("helloagain");
    }
Ejemplo n.º 2
0
 @Override
 public void onError(Exception e) {
   a.error(this, e);
 }