Category { public boolean matches(Transaction transaction) { checkNotNull(transaction); if (!Strings.isNullOrEmpty(transaction.getCategoryName())) { return getName().equals(transaction.getCategoryName()); } for (MatchRule matchRule : getMatchRules()) { if (matchRule.matches(transaction)) { return true; } } return false; } Category(String name);  Category(String name, List<MatchRule> matchRules); String getName(); List<MatchRule> getMatchRules(); boolean matches(Transaction transaction); Category withMatchRule(MatchRule rule); @Override String toString();  }
@Test public void matches() { MatchRule rule = MatchRule.withPattern("abc"); MatchRule rule2 = MatchRule.withPattern("def"); Category category = new Category("a name", ImmutableList.of(rule, rule2)); assertTrue(category.matches(MockTransaction.create("2015-01-01", "aaabc", 123))); assertTrue(category.matches(MockTransaction.create("2015-01-01", "def", 123))); assertFalse(category.matches(MockTransaction.create("2015-01-01", "ghi", 123))); assertFalse(new Category("nope").matches(MockTransaction.create("2015-01-01", "def", 123))); }