expense.setIncome(Boolean.FALSE);
Subcategory fooExpense = new Subcategory();
fooExpense.setId(1L);
fooExpense.setParentCategory(expense);
fooExpense.setCategory("fooExpense");
Account account = new Account();
account.setLocale(Locale.GERMANY);
Account usAccount = new Account();
usAccount.setLocale(Locale.US);
List<AccountTransaction> transactions = null;
Map<Currency, Map<Subcategory, BigDecimal>> data = controller.organizeByCategory(transactions);
assertEquals("No data organized", 0, data.size());
transactions = new ArrayList<AccountTransaction>();
AccountTransaction transaction = new AccountTransaction();
transaction.setAccount(account);
transaction.setOperationDate(new Date());
transaction.setAmount(BigDecimal.TEN);
transaction.setSubcategory(fooIncome);
transactions.add(transaction);
data = controller.organizeByCategory(transactions);
assertEquals("No expense data", 0, data.size());
AccountTransaction expensetransaction = new AccountTransaction();
expensetransaction.setAccount(account);
expensetransaction.setOperationDate(new Date());
expensetransaction.setAmount(new BigDecimal(-75));
expensetransaction.setSubcategory(fooExpense);
transactions.add(expensetransaction);
data = controller.organizeByCategory(transactions);
assertEquals("Some expense data", 1, data.size());
assertEquals("Some categories", 1, data.get(Currency.getInstance(account.getLocale())).size());
assertEquals("Some total amount", new BigDecimal(75), data.get(Currency.getInstance(account.getLocale())).get(fooExpense));
AccountTransaction otherExpenseInCategory = new AccountTransaction();
otherExpenseInCategory.setAccount(account);
otherExpenseInCategory.setOperationDate(new Date());
otherExpenseInCategory.setAmount(new BigDecimal(-75));
otherExpenseInCategory.setSubcategory(fooExpense);
transactions.add(otherExpenseInCategory);
data = controller.organizeByCategory(transactions);
assertEquals("Same categories", 1, data.get(Currency.getInstance(account.getLocale())).size());
assertEquals("Added total amount", new BigDecimal(150), data.get(Currency.getInstance(account.getLocale())).get(fooExpense));
AccountTransaction otherExpense = new AccountTransaction();
otherExpense.setAccount(usAccount);
otherExpense.setOperationDate(new Date());
otherExpense.setAmount(new BigDecimal(-75));
otherExpense.setSubcategory(fooExpense);
transactions.add(otherExpense);
data = controller.organizeByCategory(transactions);
assertEquals("Two currencies", 2, data.size());
assertEquals("Added total amount", new BigDecimal(75), data.get(Currency.getInstance(usAccount.getLocale())).get(fooExpense));
Category expense2 = new Category();
expense2.setIncome(Boolean.FALSE);
Subcategory fooExpense2 = new Subcategory();
fooExpense2.setId(2L);
fooExpense2.setParentCategory(expense2);