use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class Validation_Test method testMandatory.
@Test
public void testMandatory() {
List<Diagnostic> diags = new ArrayList<>();
WTextField textField = new WTextField();
Assert.assertFalse("Text field should not be mandatory by default", textField.isMandatory());
// No validation logic yet, but that should still be ok.
textField.validate(diags);
Assert.assertEquals("Diags should be empty when there are no validators", 0, diags.size());
// Add a mandatory validation
textField.setMandatory(true);
Assert.assertTrue("Text field should be mandatory", textField.isMandatory());
textField.validate(diags);
Assert.assertEquals("Diags should contain mandatory validation error", 1, diags.size());
// Add some text to the text field
textField.setText("Blah");
diags.clear();
textField.validate(diags);
Assert.assertEquals("Diags should be empty when mandatory field is filled in", 0, diags.size());
}
Aggregations