@Test public void shouldReturnExpensesGroupedByDate() throws Exception { Map<String, List<Expense>> expenses = expenseCollection.groupByDate(); assertThat(expenses.keySet().size(), is(2)); assertThat(expenses.get(travel.getDate()).size(), is(2)); assertThat(expenses.get(food.getDate()).size(), is(1)); }
public Map<String, List<Expense>> groupByDate() { Map<String, List<Expense>> expensesByDate = new HashMap<>(); for (Expense expense : expenses) { if(expensesByDate.get(expense.getDate()) == null){ List<Expense> expensesList = new ArrayList<>(); expensesList.add(expense); expensesByDate.put(expense.getDate(), expensesList); } else { expensesByDate.get(expense.getDate()).add(expense); } } return expensesByDate; }
ExpenseCollection { public Map<String, List<Expense>> groupByDate() { Map<String, List<Expense>> expensesByDate = new HashMap<>(); for (Expense expense : expenses) { if(expensesByDate.get(expense.getDate()) == null){ List<Expense> expensesList = new ArrayList<>(); expensesList.add(expense); expensesByDate.put(expense.getDate(), expensesList); } else { expensesByDate.get(expense.getDate()).add(expense); } } return expensesByDate; } }
ExpenseCollection { public Map<String, List<Expense>> groupByDate() { Map<String, List<Expense>> expensesByDate = new HashMap<>(); for (Expense expense : expenses) { if(expensesByDate.get(expense.getDate()) == null){ List<Expense> expensesList = new ArrayList<>(); expensesList.add(expense); expensesByDate.put(expense.getDate(), expensesList); } else { expensesByDate.get(expense.getDate()).add(expense); } } return expensesByDate; } ExpenseCollection(List<Expense> expenses); }
ExpenseCollection { public Map<String, List<Expense>> groupByDate() { Map<String, List<Expense>> expensesByDate = new HashMap<>(); for (Expense expense : expenses) { if(expensesByDate.get(expense.getDate()) == null){ List<Expense> expensesList = new ArrayList<>(); expensesList.add(expense); expensesByDate.put(expense.getDate(), expensesList); } else { expensesByDate.get(expense.getDate()).add(expense); } } return expensesByDate; } ExpenseCollection(List<Expense> expenses); Long getTotalExpense(); Map<String, List<Expense>> groupByDate(); List<Expense> withoutMoneyTransfer(); }
ExpenseCollection { public Map<String, List<Expense>> groupByDate() { Map<String, List<Expense>> expensesByDate = new HashMap<>(); for (Expense expense : expenses) { if(expensesByDate.get(expense.getDate()) == null){ List<Expense> expensesList = new ArrayList<>(); expensesList.add(expense); expensesByDate.put(expense.getDate(), expensesList); } else { expensesByDate.get(expense.getDate()).add(expense); } } return expensesByDate; } ExpenseCollection(List<Expense> expenses); Long getTotalExpense(); Map<String, List<Expense>> groupByDate(); List<Expense> withoutMoneyTransfer();  }