Example #1
0
    @SuppressWarnings("unchecked")
    /* mock calls don't do generics */
    @Test
    public void testAggregate3Types() {
      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, Integer> r2 = mock(ZipObserver.class);
      ZipObserver<String, int[]> r3 = mock(ZipObserver.class);

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

      /* simulate the Observables pushing data into the aggregator */
      a.next(r1, "hello");
      a.next(r2, 2);
      a.next(r3, new int[] {5, 6, 7});

      verify(aObserver, never()).onError(any(Exception.class));
      verify(aObserver, never()).onCompleted();
      verify(aObserver, times(1)).onNext("hello2[5, 6, 7]");
    }
Example #2
0
 @Override
 public void onNext(T args) {
   try {
     a.next(this, args);
   } catch (Exception e) {
     onError(e);
   }
 }
Example #3
0
    @SuppressWarnings("unchecked")
    /* mock calls don't do generics */
    @Test
    public void testAggregatorEarlyCompletion() {
      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, "one");
      a.next(r1, "two");
      a.complete(r1);
      a.next(r2, "A");

      InOrder inOrder = inOrder(aObserver);

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

      a.complete(r2);

      inOrder.verify(aObserver, never()).onError(any(Exception.class));
      inOrder.verify(aObserver, times(1)).onCompleted();
      inOrder.verify(aObserver, never()).onNext(anyString());
    }
Example #4
0
    @SuppressWarnings("unchecked")
    /* mock calls don't do generics */
    @Test
    public void testAggregatorUnsubscribe() {
      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);
      Subscription subscription = 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");

      subscription.unsubscribe();
      a.next(r1, "hello");
      a.next(r2, "again");

      verify(aObserver, times(0)).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");
    }