AndBodyChecker implements ConditionChecker { @Override public boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList) { List<Parameter> params = parameterList.getAllParameters(); Iterator<Parameter> iterator = params.iterator(); boolean result = !params.isEmpty(); while (iterator.hasNext() && result) { Parameter parameter = iterator.next(); String parameterValue = parameter.getValue(); result = evaluateParameter(request, parameterValue); } return result; } AndBodyChecker(final ConditionCheckerOperator operator); @Override boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList);  }
@Test public void testCheckConditionWhenConditionIsFulfilledShouldReturnTrue() { parameterList.addParameter(new Parameter(PARAMETER_NAME, MSG_ID)); given(request.getBody()).willReturn(MSG_ID); given(operator.checkTarget(anyString(), anyString())).willReturn(true); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, true); }
@Test public void testCheckConditionWhenMultipleConditionsAreFulfilledShouldReturnTrue() { String otherValue = "other value"; parameterList.addParameter(new Parameter(PARAMETER_NAME, MSG_ID)); parameterList.addParameter(new Parameter("OTHER_VALUE", otherValue)); given(request.getBody()).willReturn(MSG_ID, otherValue); given(operator.checkTarget(anyString(), anyString())).willReturn(true, true); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, true); }
@Test public void testCheckConditionWhenOneConditionIsFulfilledShouldReturnFalse() { String otherValue = "other value"; parameterList.addParameter(new Parameter(PARAMETER_NAME, MSG_ID)); parameterList.addParameter(new Parameter("OTHER_VALUE", otherValue)); given(request.getBody()).willReturn(MSG_ID, ""); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, false); }
@Test public void testCheckConditionWhenOneConditionIsNotFulfilledShouldReturnFalse() { String otherValue = "other value"; parameterList.addParameter(new Parameter(PARAMETER_NAME, MSG_ID)); parameterList.addParameter(new Parameter("OTHER_VALUE", otherValue)); given(request.getBody()).willReturn("", otherValue); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, false); }
@Test public void testCheckConditionWhenNoConditionIsFulfilledShouldReturnFalse() { String otherValue = "other value"; parameterList.addParameter(new Parameter(PARAMETER_NAME, MSG_ID)); parameterList.addParameter(new Parameter("OTHER_VALUE", otherValue)); given(request.getBody()).willReturn("something else", "something else"); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, false); }
@Test public void testCheckConditionWhenParameterMapIsEmptyShouldReturnFalse() { given(request.getBody()).willReturn(MSG_ID); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, false); }
@Test public void testCheckConditionWhenParameterMapHasEmptyEntryShouldReturnFalse() { parameterList.addParameter(new Parameter(PARAMETER_NAME, "")); given(request.getBody()).willReturn(MSG_ID); boolean actual = underTest.checkCondition(request, parameterList); assertEquals(actual, false); }