OrHeaderChecker implements ConditionChecker { @Override public boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList) { List<Parameter> params = parameterList.getAllParameters(); Iterator<Parameter> iterator = params.iterator(); boolean result = false; if (!params.isEmpty()) { while (iterator.hasNext() && !result) { result = checkInRequestHeaders(request, iterator.next()); } } return result; } OrHeaderChecker(final ConditionCheckerOperator operator); @Override boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList);  }
@Test public void testCheckConditionShouldReturnFalseWhenParamsIsEmpty() { given(paramList.getAllParameters()).willReturn(params); boolean actual = underTest.checkCondition(request, paramList); assertFalse(actual); }
@Test public void testCheckConditionShouldReturnFalseWhenOneParamIsEmptyString() { given(paramList.getAllParameters()).willReturn(params); params.add(new Parameter("", "")); boolean actual = underTest.checkCondition(request, paramList); assertFalse(actual); }
@Test public void testCheckConditionShouldReturnFalseWhenHeaderDoesNotContainParam() { Map<String, String> headers = new HashMap<String, String>(); headers.put("b", "bb"); headers.put("c", "cc"); given(request.getHeaders()).willReturn(headers); given(paramList.getAllParameters()).willReturn(params); params.add(new Parameter("", "aa")); params.add(new Parameter("", "dd")); boolean actual = underTest.checkCondition(request, paramList); assertFalse(actual); }
@Test public void testCheckConditionShouldReturnFalseWhenHeaderContainsJustTheDesiredParam() { Map<String, String> headers = new HashMap<String, String>(); headers.put("a", "aa"); given(request.getHeaders()).willReturn(headers); given(paramList.getAllParameters()).willReturn(params); given(operator.checkTarget(anyString(), anyString())).willReturn(true); params.add(new Parameter("", "aa")); boolean actual = underTest.checkCondition(request, paramList); assertTrue(actual); }
@Test public void testCheckConditionShouldReturnTrueWhenHeaderContainsOneOfTheParams() { Map<String, String> headers = new HashMap<String, String>(); headers.put("a", "aa"); headers.put("c", "cc"); headers.put("b", "bb"); given(request.getHeaders()).willReturn(headers); given(paramList.getAllParameters()).willReturn(params); params.add(new Parameter("", "aa")); params.add(new Parameter("", "dd")); given(operator.checkTarget(anyString(), anyString())).willReturn(true); boolean actual = underTest.checkCondition(request, paramList); assertTrue(actual); }