GraphsInteractor { public Maybe<GraphUiIndicator> getSummationByCategories(Trip trip) { return groupingController.getSummationByCategoryAsGraphEntries(trip) .filter(graphEntries -> !graphEntries.isEmpty()) .flatMapSingleElement(Single::just) .map(GraphUiIndicator::summationByCategory) .observeOn(AndroidSchedulers.mainThread()); } @Inject  GraphsInteractor(Context context, GroupingController groupingController); Maybe<GraphUiIndicator> getSummationByCategories(Trip trip); Maybe<GraphUiIndicator> getSummationByReimbursement(Trip trip); Maybe<GraphUiIndicator> getSummationByPaymentMethod(Trip trip); Maybe<GraphUiIndicator> getSummationByDate(Trip trip); final static int PAYMENT_METHODS_MAX_COUNT; }
@Test public void getSumByCategoryNormal() { entries = new ArrayList<>(); entries.add(new LabeledGraphEntry(10, LABEL_1)); entries.add(new LabeledGraphEntry(9, LABEL_2)); entries.add(new LabeledGraphEntry(18, LABEL_3)); entries.add(new LabeledGraphEntry(7, LABEL_4)); entries.add(new LabeledGraphEntry(6, LABEL_5)); entries.add(new LabeledGraphEntry(3, LABEL_6)); when(groupingController.getSummationByCategoryAsGraphEntries(trip)).thenReturn(Single.just(entries)); interactor.getSummationByCategories(trip) .test() .assertNoErrors() .assertComplete() .assertValue(graphUiIndicator -> { if (graphUiIndicator.getGraphType() == GraphUiIndicator.GraphType.SummationByCategory) { List<? extends BaseEntry> graphUiIndicatorEntries = graphUiIndicator.getEntries(); return graphUiIndicatorEntries.containsAll(entries) && graphUiIndicatorEntries.size() == entries.size(); } return false; }); }
@Test public void getSumCategoryLot() { entries = new ArrayList<>(); entries.add(new LabeledGraphEntry(10, LABEL_1)); entries.add(new LabeledGraphEntry(9, LABEL_2)); entries.add(new LabeledGraphEntry(18, LABEL_3)); entries.add(new LabeledGraphEntry(7, LABEL_4)); entries.add(new LabeledGraphEntry(6, LABEL_5)); entries.add(new LabeledGraphEntry(3, LABEL_6)); entries.add(new LabeledGraphEntry(2, LABEL_7)); entries.add(new LabeledGraphEntry(1, LABEL_8)); when(groupingController.getSummationByCategoryAsGraphEntries(trip)).thenReturn(Single.just(entries)); List<LabeledGraphEntry> sortedEntries = new ArrayList<>(entries); Collections.sort(sortedEntries); interactor.getSummationByCategories(trip) .test() .assertNoErrors() .assertComplete() .assertValue(graphUiIndicator -> { if (graphUiIndicator.getGraphType() == GraphUiIndicator.GraphType.SummationByCategory) { List<? extends BaseEntry> graphUiIndicatorEntries = graphUiIndicator.getEntries(); return graphUiIndicatorEntries.containsAll(sortedEntries) && graphUiIndicatorEntries.size() == sortedEntries.size(); } return false; }); }