GraphsInteractor { public Maybe<GraphUiIndicator> getSummationByDate(Trip trip) { return groupingController.getSummationByDateAsGraphEntries(trip) .filter(graphEntries -> !graphEntries.isEmpty()) .map(entries -> { List<Entry> result = new ArrayList<>(entries); List<Integer> filledDaysNumbers = new ArrayList<>(); int firstDay = (int) entries.get(0).getX(); int lastDay = (int) entries.get(entries.size() - 1).getX(); for (Entry entry : entries) { filledDaysNumbers.add((int) entry.getX()); } for (int i = firstDay; i < lastDay; i++) { if (!filledDaysNumbers.contains(i)) { result.add(new Entry(i, 0)); } } Collections.sort(result, (o1, o2) -> Float.compare(o1.getX(), o2.getX())); return result; }) .map(GraphUiIndicator::summationByDate) .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 fillEmptyDaysWithZero() { float someValue = 5; List<Entry> entries = new ArrayList<>(Arrays.asList( new Entry(2, someValue), new Entry(5, someValue), new Entry(7, someValue) )); when(groupingController.getSummationByDateAsGraphEntries(trip)).thenReturn(Single.just(entries)); List<Entry> expectedEntries = new ArrayList<>(Arrays.asList( new Entry(2, someValue), new Entry(3, 0), new Entry(4, 0), new Entry(5, someValue), new Entry(6, 0), new Entry(7, someValue) )); GraphUiIndicator graphUiIndicator = interactor.getSummationByDate(trip).blockingGet(); List<? extends BaseEntry> resultEntries = graphUiIndicator.getEntries(); for (int i = 0; i < resultEntries.size(); i++) { Entry e1 = (Entry) resultEntries.get(i); Entry e2 = expectedEntries.get(i); assertTrue(e1.getX() == e2.getX() && e1.getY() == e2.getY()); } assertEquals(expectedEntries.size(), resultEntries.size()); assertEquals(GraphUiIndicator.GraphType.SummationByDate, graphUiIndicator.getGraphType()); }