AndRule extends AbstractRule { public static Rule getRule(final Stack<Object> stack) { if (stack.size() < 2) { throw new IllegalArgumentException("Invalid AND rule - expected two rules but received " + stack.size()); } Object o2 = stack.pop(); Object o1 = stack.pop(); if ((o2 instanceof Rule) && (o1 instanceof Rule)) { Rule p2 = (Rule) o2; Rule p1 = (Rule) o1; return new AndRule(p1, p2); } throw new IllegalArgumentException("Invalid AND rule: " + o2 + "..." + o1); } private  AndRule(final Rule first, final Rule second); static Rule getRule(final Stack<Object> stack); static Rule getRule(final Rule firstParam, final Rule secondParam); @SuppressWarnings({"rawtypes", "unchecked"}) boolean evaluate(final LogData event, Map matches);  }
@Test public void test1() { Stack<Object> stack = new Stack<>(); stack.push(LevelEqualsRule.getRule("INFO")); try { AndRule.getRule(stack); Assert.fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException ex) { } }
@Test public void test2() { Stack<Object> stack = new Stack<>(); stack.push("Hello"); stack.push("World"); try { AndRule.getRule(stack); Assert.fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException ex) { } }