CategorizerService { public List<Transaction> categorize(List<Transaction> transactions) { checkNotNull(transactions); ImmutableList.Builder<Transaction> builder = ImmutableList.builder(); for (Transaction transaction : transactions) { builder.add(categorize(transaction)); } return builder.build(); } @Inject  CategorizerService(CategoriesService categoriesService); List<Transaction> categorize(List<Transaction> transactions);  }
@Test public void categorize() { List<Transaction> transactions = ImmutableList.of(MockTransaction.create("2015-01-01", "a two", 123), MockTransaction.create("2015-01-02", "zzz", 123).withCategoryName("one"), MockTransaction.create("2015-01-03", "zzz", 123), MockTransaction.create("2015-01-02", "zzz", 123).withCategoryName("No Such Thing")); List<Transaction> categorized = service.categorize(transactions); assertEquals(transactions, categorized); assertCategory("two", categorized.get(0)); assertCategory("one", categorized.get(1)); assertEquals(null, categorized.get(2).getCategory()); assertEquals(null, categorized.get(3).getCategory()); }
@Test public void categorizeNone() { List<Transaction> transactions = ImmutableList.of(MockTransaction.create("2015-01-01", "no", 123)); List<Transaction> categorized = service.categorize(transactions); assertEquals(transactions, categorized); assertEquals(null, categorized.get(0).getCategory()); }