assertEquals(expectedCount++, v.count);
}
public void testValidationMessages() {
DefaultFormModel fm = (DefaultFormModel) getFormModel(new TestBean());
ValidationResultsModel r = fm.getValidationResults();
TestValidator v = new TestValidator();
fm.setValidator(v);
ValueModel vm = fm.getValueModel("simpleProperty");
// starting at 2: constructing a formmodel + creating valueModel
int expectedCount = 2;
assertEquals(expectedCount++, v.count);
assertEquals(0, r.getMessageCount());
v.results = getValidationResults("message1");
vm.setValue("1");
assertEquals(expectedCount++, v.count);
assertEquals(1, r.getMessageCount());
assertContainsMessage("message1", r.getMessages());
v.results = getValidationResults("message2");
vm.setValue("2");
assertEquals(expectedCount, v.count);
assertEquals(1, r.getMessageCount());
assertContainsMessage("message2", r.getMessages());
// this will cause a binding exception
vm.setValue(new Object());
assertEquals(expectedCount++, v.count);
assertEquals(2, r.getMessageCount());
assertContainsMessage("message2", r.getMessages());
// this will clear the binding exception
vm.setValue("3");
assertEquals(expectedCount++, v.count);
assertEquals(1, r.getMessageCount());
assertContainsMessage("message2", r.getMessages());
fm.validate();
assertEquals(expectedCount++, v.count);
assertEquals(1, r.getMessageCount());
assertContainsMessage("message2", r.getMessages());
}