HamcrestHeaderValidator implements HeaderValidator { @Override public void validateHeader(String headerName, Object receivedValue, Object controlValue, TestContext context, HeaderValidationContext validationContext) { try { if (controlValue instanceof Matcher) { Assert.isTrue(((Matcher<?>) controlValue).matches(receivedValue), ValidationUtils.buildValueMismatchErrorMessage( "Values not matching for header '" + headerName + "'", controlValue, receivedValue)); } else { IsEqual<Object> equalMatcher = new IsEqual<>(controlValue); Assert.isTrue(equalMatcher.matches(receivedValue), ValidationUtils.buildValueMismatchErrorMessage( "Values not equal for header '" + headerName + "'", controlValue, receivedValue)); } } catch (IllegalArgumentException e) { throw new ValidationException("Validation failed:", e); } if (log.isDebugEnabled()) { log.debug("Validating header element: " + headerName + "='" + controlValue + "': OK."); } }  @Override void validateHeader(String headerName, Object receivedValue, Object controlValue, TestContext context, HeaderValidationContext validationContext); @Override boolean supports(String headerName, Class<?> type);  }
@Test(dataProvider = "successData") public void testValidateHeader(Object receivedValue, Object controlValue) { validator.validateHeader("foo", receivedValue, controlValue, context, validationContext); }
@Test(dataProvider = "errorData", expectedExceptions = ValidationException.class) public void testValidateHeaderError(Object receivedValue, Object controlValue) { validator.validateHeader("foo", receivedValue, controlValue, context, validationContext); }