TranslatedField field = newMock(TranslatedField.class);
checkOrder(field, false);
Date minDate = new Date(System.currentTimeMillis() + ONE_DAY);
DateTranslator translator = new DateTranslator();
expect(field.getTranslator()).andReturn(translator);
expect(field.getClientId()).andReturn("myfield").anyTimes();
expect(field.getDisplayName()).andReturn("My Field");
FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
Locale locale = Locale.ENGLISH;
expect(context.getLocale()).andReturn(locale).anyTimes();
expect(context.getProfile()).andReturn(json);
context.addInitializationScript(field, "dojo.require(\"tapestry.form.datetime\");");
String strMin = translator.format(field, locale, minDate);
trainFormatMessage(context, "custom", ValidationStrings.DATE_TOO_EARLY,
new Object[] { "My Field", strMin },
"custom\\message");
replay();
new MinDate("minDate=" + strMin + ",message=custom").renderContribution(writer, cycle, context, field);
verify();
assertEquals(json.toString(), "{\"constraints\":{\"myfield\":[["
+ "tapestry.form.datetime.isValidDate,{min:\""
+ strMin + "\",datePattern:"
+ JSONObject.quote(translator.getPattern())
+ "}]]},"
+"\"myfield\":{\"constraints\":[\"custom\\\\message\"]}}");
}