}
public void testCommitCommandGuarding() {
TestForm form = new TestForm(formModel);
new FormGuard(formModel, guarded, FormGuard.LIKE_COMMITCOMMAND);
Guarded cmtCmd = form.getCommitCommand();
// initially --> disabled
assertFalse("guarded like commit should be initially disabled", guarded.isEnabled());
assertFalse("commit should be initially disabled", cmtCmd.isEnabled());
// create dirt with errors --> disabled
((JTextField)form.getControl()).setText(null);
assertTrue(formModel.getValidationResults().getHasErrors());
assertTrue(formModel.isDirty());
assertFalse("guarded like commit should be disabled when model has validation-errors", guarded.isEnabled());
assertFalse("commit should be disabled when model has validation-errors", cmtCmd.isEnabled());
// relieve errors --> enabled
((JTextField)form.getControl()).setText("nok");
assertFalse(formModel.getValidationResults().getHasErrors());
assertTrue(formModel.isDirty());
assertTrue("guarded like commit should be enabled if there are errors", guarded.isEnabled());
assertTrue("commit should be enabled if there are errors", cmtCmd.isEnabled());
// disable form --> disabled
form.setEnabled(false);
assertFalse("guarded like commit should be disabled with form", guarded.isEnabled());
assertFalse("commit should be disabled with form", cmtCmd.isEnabled());
// enable form --> enabled
form.setEnabled(true);
assertTrue("guarded like commit should be enabled with form", guarded.isEnabled());
assertTrue("commit should be enabled with form", cmtCmd.isEnabled());
// revert --> disabled
form.revert();
assertFalse("guarded like commit should be disabled when no changes left", guarded.isEnabled());
assertFalse("commit should be disabled when no changes left", cmtCmd.isEnabled());
}