ReportsService { public IncomeVersusExpensesReport incomeVersusExpenses() { IncomeVersusExpensesReport report = new IncomeVersusExpensesReport(); Transactions transactions = transactionsService.retrieve(); ListMultimap<Long, Transaction> transactionsByMonth = ArrayListMultimap.create(); for (Transaction transaction : transactions.getTransactions()) { Long yearMonth = yearMonth(transaction.getDate()); transactionsByMonth.put(yearMonth, transaction); } List<Long> sortedMonths = new ArrayList<>(transactionsByMonth.keySet()); Collections.sort(sortedMonths); for (final Long yearMonth : sortedMonths) { String name = monthName(yearMonth); report.addMonth(new Month(yearMonth, name, transactionsByMonth.get(yearMonth))); } return report; } @Inject  ReportsService(TransactionsService transactionsService); IncomeVersusExpensesReport incomeVersusExpenses(); ExpensesByCategoryReport expensesByCategory(); PeriodTransactions transactionsForMonth(long yearMonth); PeriodDetails detailsForMonth(long yearMonth);  }
@Test public void incomeVersusExpenses() { IncomeVersusExpensesReport report = service.incomeVersusExpenses(); List<Month> months = report.getMonths(); assertNotNull(months); assertEquals(2, months.size()); assertMonth("January 2015", 102300, 1500, months.get(0)); assertMonth("February 2015", 0, 12345, months.get(1)); }