CreateVariableValidationMatcher implements ValidationMatcher { @Override public void validate(String fieldName, String value, List<String> controlParameters, TestContext context) throws ValidationException { String name = fieldName; if (controlParameters != null && controlParameters.size() > 0) { name = controlParameters.get(0); } log.info("Setting variable: " + name + " to value: " + value); context.setVariable(name, value); }  @Override void validate(String fieldName, String value, List<String> controlParameters, TestContext context);  }
@Test public void testValidateSuccess() { matcher.validate("field", "This is a test", Arrays.<String>asList(), context); Assert.assertEquals(context.getVariable("field"), "This is a test"); matcher.validate("field", "This is a 2nd test", Arrays.<String>asList(), context); Assert.assertEquals(context.getVariable("field"), "This is a 2nd test"); context.setVariable("foo", "bar"); matcher.validate("field", "Another test", Arrays.asList("foo"), context); Assert.assertEquals(context.getVariable("field"), "This is a 2nd test"); Assert.assertEquals(context.getVariable("foo"), "Another test"); matcher.validate("field", "This is a 3rd test", null, context); Assert.assertEquals(context.getVariable("field"), "This is a 3rd test"); }