Skip to content

Commit 1c0c213

Browse files
committed
TRUNK-4860: Assert validation error code for blank gender in PatientValidatorTest
TRUNK-4860: Assert validation error codes in PatientValidatorTest
1 parent c14a6eb commit 1c0c213

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

api/src/test/java/org/openmrs/validator/PatientValidatorTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.springframework.validation.BindException;
3030
import org.springframework.validation.Errors;
3131
import org.springframework.validation.Validator;
32+
import static org.junit.Assert.assertEquals;
33+
3234

3335
/**
3436
* Tests methods on the {@link PatientValidator} class.
@@ -56,6 +58,8 @@ public void validate_shouldFailValidationIfAPreferredPatientIdentifierIsNotChose
5658
Errors errors = new BindException(pa, "patient");
5759
validator.validate(pa, errors);
5860
assertTrue(errors.hasErrors());
61+
assertTrue(errors.hasGlobalErrors());
62+
assertEquals("error.preferredIdentifier", errors.getGlobalError().getCode());
5963
}
6064

6165
/**
@@ -117,6 +121,10 @@ public void validate_shouldFailValidationIfGenderIsBlank() {
117121
validator.validate(pa, errors);
118122

119123
assertTrue(errors.hasFieldErrors("gender"));
124+
assertTrue(
125+
errors.getFieldErrors("gender").stream()
126+
.anyMatch(e -> "Person.gender.required".equals(e.getCode()))
127+
);
120128
}
121129

122130
/**
@@ -194,5 +202,6 @@ public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
194202
validator.validate(patient, errors);
195203

196204
assertTrue(errors.hasFieldErrors("voidReason"));
205+
assertEquals("error.exceededMaxLengthOfField",errors.getFieldError("voidReason").getCode());
197206
}
198207
}

0 commit comments

Comments
 (0)