IgnoreNewLineValidationMatcher implements ValidationMatcher { public void validate(String fieldName, String value, List<String> controlParameters, TestContext context) throws ValidationException { String control = controlParameters.get(0); String normalizedValue = value.replaceAll("\\r(\\n)?", "\n").replaceAll("\\n", ""); String normalizedControl = control.replaceAll("\\r(\\n)?", "\n").replaceAll("\\n", ""); if (!normalizedValue.equalsIgnoreCase(normalizedControl)) { throw new ValidationException(this.getClass().getSimpleName() + " failed for field '" + fieldName + "'. Received value is '" + normalizedValue + "', control value is '" + normalizedControl + "'."); } }  void validate(String fieldName, String value, List<String> controlParameters, TestContext context);  }
@Test public void testValidateSuccess() { matcher.validate("field", "value", Collections.singletonList("value"), context); matcher.validate("field", "value1 \nvalue2 \nvalue3!", Collections.singletonList("value1 value2 value3!"), context); matcher.validate("field", "\nvalue1 \nvalue2 \nvalue3!\n", Collections.singletonList("value1 value2 value3!"), context); matcher.validate("field", "value1 \r\nvalue2 \r\nvalue3!\r\n", Collections.singletonList("value1 value2 value3!"), context); matcher.validate("field", "\r\nvalue1 \r\nvalue2 \r\nvalue3!", Collections.singletonList("value1 value2 value3!"), context); matcher.validate("field", "value1 \n\n\nvalue2 \n\nvalue3!", Collections.singletonList("value1 value2 value3!"), context); matcher.validate("field", "value1 \r\n\r\n\r\nvalue2 \r\n\r\nvalue3!", Collections.singletonList("value1 value2 value3!"), context); matcher.validate("field", "value1 \n\n\nvalue2 \n\nvalue3!", Collections.singletonList("value1 \nvalue2 \nvalue3!"), context); matcher.validate("field", "value1 \r\n\r\n\r\nvalue2 \r\n\r\nvalue3!", Collections.singletonList("value1 \r\nvalue2 \r\nvalue3!"), context); }
@Test(expectedExceptions = ValidationException.class) public void testValidateError() { matcher.validate("field", "value1 \nvalue2 \nvalue3!", Collections.singletonList("value1! value2! value3!"), context); }