### Question:
AndRule implements Rule { @Override public boolean ruleMatches(Product product) throws IllegalArgumentException { boolean matches = true; for(Rule rule : rules) { if(! rule.ruleMatches(product)) { matches = false; } } return matches; } AndRule(Rule rule1, Rule rule2, Rule ... rules); @Override boolean ruleMatches(Product product);  }### Answer:
@Test public void testRuleMatches() { Rule rule = new AndRule( new AlwaysTrueRule(), new AlwaysTrueRule()); Assert.assertTrue(rule.ruleMatches(null)); rule = new AndRule( new AlwaysTrueRule(), new NotRule( new AlwaysTrueRule())); Assert.assertFalse(rule.ruleMatches(null)); rule = new AndRule( new NotRule( new AlwaysTrueRule()), new AlwaysTrueRule()); Assert.assertFalse(rule.ruleMatches(null)); rule = new AndRule( new NotRule( new AlwaysTrueRule()), new NotRule( new AlwaysTrueRule())); Assert.assertFalse(rule.ruleMatches(null)); }