Beispiel #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]");
    }
Beispiel #2
0
    @SuppressWarnings("unchecked")
    /* mock calls don't do generics */
    @Test
    public void testAggregatorsWithDifferentSizesAndTiming() {
      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.next(r1, "three");
      a.next(r2, "A");

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

      a.next(r1, "four");
      a.complete(r1);
      a.next(r2, "B");
      verify(aObserver, times(1)).onNext("twoB");
      a.next(r2, "C");
      verify(aObserver, times(1)).onNext("threeC");
      a.next(r2, "D");
      verify(aObserver, times(1)).onNext("fourD");
      a.next(r2, "E");
      verify(aObserver, never()).onNext("E");
      a.complete(r2);

      verify(aObserver, never()).onError(any(Exception.class));
      verify(aObserver, times(1)).onCompleted();
    }
Beispiel #3
0
    @SuppressWarnings("unchecked")
    /* mock calls don't do generics */
    @Test
    public void testAggregatorDifferentSizedResultsWithOnComplete() {
      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");
      a.complete(r2);

      InOrder inOrder = inOrder(aObserver);

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

      a.next(r1, "hi");
      a.complete(r1);

      inOrder.verify(aObserver, never()).onError(any(Exception.class));
      inOrder.verify(aObserver, times(1)).onCompleted();
      inOrder.verify(aObserver, never()).onNext(anyString());
    }
Beispiel #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");
    }