BPIServiceClient { public Observable<List<BPI>> getHistory() { return bpiService.getHistory().flatMap(new Func1<HistoryDto, Observable<List<BPI>>>() { @Override public Observable<List<BPI>> call(HistoryDto historyDto) { return Observable.from(historyDto.getBpi().entrySet()) .map(new Func1<Map.Entry<Date, Float>, BPI>() { @Override public BPI call(Map.Entry<Date, Float> entry) { return new BPI(entry.getKey(), entry.getValue()); } }) .scan(new Func2<BPI, BPI, BPI>() { @Override public BPI call(BPI bpi, BPI bpi2) { if (bpi.getClose() != 0) { bpi2.setChange(bpi); } return bpi2; } }) .filter(new Func1<BPI, Boolean>() { @Override public Boolean call(BPI bpi) { return bpi.getChange() != null; } }) .toSortedList(new Func2<BPI, BPI, Integer>() { @Override public Integer call(BPI bpi, BPI bpi2) { return - bpi.getDate().compareTo(bpi2.getDate()); } }); } }); } BPIServiceClient(BPIService bpiService); Observable<BPI> getCurrentUSDPrice(); Observable<List<BPI>> getHistory();  }
@Test public void getHistory_oneNext() throws ParseException { BPIService service = mock(BPIService.class); when(service.getHistory()).thenReturn(Observable.from(new HistoryDto[] { newHistory(3) })); BPIServiceClient client = new BPIServiceClient(service); TestSubscriber<List<BPI>> subscriber = new TestSubscriber<>(); client.getHistory().subscribe(subscriber); List<List<BPI>> expectedResults = new ArrayList<>(); expectedResults.add(Lists.newArrayList( new BPI(newDate(3), 3f, 1f/2f), new BPI(newDate(2), 2f, 1f) )); subscriber.assertReceivedOnNext(expectedResults); subscriber.assertTerminalEvent(); subscriber.assertNoErrors(); }