ConditionEvaluator { public boolean evaluate(final Condition condition, final WilmaHttpRequest request) { boolean fulfilled = false; if (condition instanceof CompositeCondition) { if (condition.getConditionType() == ConditionType.AND) { fulfilled = evaluateAndCondition(condition, request); } else if (condition.getConditionType() == ConditionType.OR) { fulfilled = evaluateOrCondition(condition, request); } else if (condition.getConditionType() == ConditionType.NOT) { fulfilled = evaluateNotCondition(condition, request); } } else if (condition instanceof SimpleCondition) { SimpleCondition simpleCondition = (SimpleCondition) condition; ConditionChecker conditionChecker = simpleCondition.getConditionChecker(); boolean negate = simpleCondition.isNegate(); fulfilled = !negate && conditionChecker.checkCondition(request, simpleCondition.getParameters()); } return fulfilled; }  boolean evaluate(final Condition condition, final WilmaHttpRequest request);  }
@Test public void testEvaluateWhenConditionIsAndShouldReturnTrue() { List<Condition> conditionList = new ArrayList<>(); conditionList.add(simpleCondition); conditionList.add(simpleCondition); compositeCondition = new CompositeCondition(ConditionType.AND, conditionList); given(conditionChecker.checkCondition(request, parameterMap)).willReturn(true); boolean actual = underTest.evaluate(compositeCondition, request); assertEquals(actual, true); }
@Test public void testEvaluateWhenConditionIsAndShouldReturnFalse() { List<Condition> conditionList = new ArrayList<>(); conditionList.add(simpleCondition); conditionList.add(simpleCondition); compositeCondition = new CompositeCondition(ConditionType.AND, conditionList); given(conditionChecker.checkCondition(request, parameterMap)).willReturn(false); boolean actual = underTest.evaluate(compositeCondition, request); assertEquals(actual, false); }
@Test public void testEvaluateWhenConditionIsOrShouldReturnTrue() { List<Condition> conditionList = new ArrayList<>(); conditionList.add(simpleCondition); conditionList.add(simpleCondition); compositeCondition = new CompositeCondition(ConditionType.OR, conditionList); given(conditionChecker.checkCondition(request, parameterMap)).willReturn(true); boolean actual = underTest.evaluate(compositeCondition, request); assertEquals(actual, true); }
@Test public void testEvaluateWhenConditionIsOrShouldReturnFalse() { List<Condition> conditionList = new ArrayList<>(); conditionList.add(simpleCondition); conditionList.add(simpleCondition); compositeCondition = new CompositeCondition(ConditionType.OR, conditionList); given(conditionChecker.checkCondition(request, parameterMap)).willReturn(false); boolean actual = underTest.evaluate(compositeCondition, request); assertEquals(actual, false); }
@Test public void testEvaluateWhenConditionIsNotShouldReturnFalse() { List<Condition> conditionList = new ArrayList<>(); conditionList.add(simpleCondition); conditionList.add(simpleCondition); compositeCondition = new CompositeCondition(ConditionType.NOT, conditionList); given(conditionChecker.checkCondition(request, parameterMap)).willReturn(true); boolean actual = underTest.evaluate(compositeCondition, request); assertEquals(actual, false); }
@Test public void testEvaluateWhenSimpleConditionIsNegatedShouldReturnTrue() { List<Condition> conditionList = new ArrayList<>(); conditionList.add(simpleCondition); conditionList.add(simpleCondition); compositeCondition = new CompositeCondition(ConditionType.NOT, conditionList); given(simpleCondition.isNegate()).willReturn(true); given(conditionChecker.checkCondition(request, parameterMap)).willReturn(true); boolean actual = underTest.evaluate(compositeCondition, request); assertEquals(actual, true); }
@Test public void testEvaluateWhenSimpleConditionReturnsFalseAndIsNotShouldReturnTrue() { List<Condition> conditionList = new ArrayList<>(); conditionList.add(simpleCondition); conditionList.add(simpleCondition); compositeCondition = new CompositeCondition(ConditionType.NOT, conditionList); given(conditionChecker.checkCondition(request, parameterMap)).willReturn(false); boolean actual = underTest.evaluate(compositeCondition, request); assertEquals(actual, true); }
@Test public void testEvaluateWhenConditionIsNestedOrShouldReturnTrue() { List<Condition> conditionList = new ArrayList<>(); conditionList.add(simpleCondition); conditionList.add(simpleCondition); CompositeCondition nestedCondition = new CompositeCondition(ConditionType.OR, new ArrayList<>(conditionList)); conditionList.clear(); conditionList.add(simpleCondition); conditionList.add(nestedCondition); compositeCondition = new CompositeCondition(ConditionType.OR, conditionList); given(conditionChecker.checkCondition(request, parameterMap)).willReturn(true); boolean actual = underTest.evaluate(compositeCondition, request); assertEquals(actual, true); }
@Test public void testEvaluateWhenConditionIsNestedAndShouldReturnTrue() { List<Condition> conditionList = new ArrayList<>(); conditionList.add(simpleCondition); conditionList.add(simpleCondition); CompositeCondition nestedCondition = new CompositeCondition(ConditionType.AND, new ArrayList<>(conditionList)); conditionList.clear(); conditionList.add(simpleCondition); conditionList.add(nestedCondition); compositeCondition = new CompositeCondition(ConditionType.AND, conditionList); given(conditionChecker.checkCondition(request, parameterMap)).willReturn(true); boolean actual = underTest.evaluate(compositeCondition, request); assertEquals(actual, true); }
@Test public void testEvaluateWhenConditionIsNotInstanceOfAnyImplementationShouldReturnFalse() { boolean actual = underTest.evaluate(condition, request); assertEquals(actual, false); }
@Test public void testEvaluateWhenCompositeConditionIsNotInstanceOfAnyImplementationShouldReturnFalse() { boolean actual = underTest.evaluate(compositeConditionMock, request); assertEquals(actual, false); }