Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.openmrs.validator;
- import org.junit.Assert;
- import org.junit.Test;
- import org.openmrs.RelationshipType;
- import org.springframework.validation.BindException;
- import org.springframework.validation.Errors;
- public class RelationshipTypeValidatorTest {
- /**
- * @see RelationshipTypeValidator#validate(Object,Errors)
- * @verifies fail validation if aIsToB(or A is To B) is null or empty or whitespace
- */
- @Test
- public void validate_shouldFailValidationIfaIsTobIsNullOrEmptyOrWhitespace()
- throws Exception {
- RelationshipType type = new RelationshipType();
- type.setName(null);
- type.setDescription("Humba humba humba ...");
- Errors errors = new BindException(type, "type");
- new RelationshipTypeValidator().validate(type, errors);
- Assert.assertTrue(errors.hasFieldErrors("aIsTob"));
- type.setName("");
- errors = new BindException(type, "type");
- new RelationshipTypeValidator().validate(type, errors);
- Assert.assertTrue(errors.hasFieldErrors("aIsTob"));
- type.setName(" ");
- errors = new BindException(type, "type");
- new RelationshipTypeValidator().validate(type, errors);
- Assert.assertTrue(errors.hasFieldErrors("aIsTob"));
- }
- /**
- * @see RelationshipTypeValidator#validate(Object,Errors)
- * @verifies fail validation if bIsToA(or B is To A) is null or empty or whitespace
- */
- @Test
- public void validate_shouldFailValidationIfbIsToaIsNullOrEmptyOrWhitespace()
- throws Exception {
- RelationshipType type = new RelationshipType();
- type.setName("B is To A");
- type.setDescription(null);
- Errors errors = new BindException(type, "type");
- new RelationshipTypeValidator().validate(type, errors);
- Assert.assertFalse(errors.hasFieldErrors("bIsToA"));
- type.setDescription("");
- errors = new BindException(type, "type");
- new RelationshipTypeValidator().validate(type, errors);
- Assert.assertFalse(errors.hasFieldErrors("bIsToA"));
- type.setDescription(" ");
- errors = new BindException(type, "type");
- new RelationshipTypeValidator().validate(type, errors);
- Assert.assertFalse(errors.hasFieldErrors("bIsToA"));
- }
- /**
- * @see RelationshipTypeValidator#validate(Object,Errors)
- * @verifies fail validation if description is null or empty or whitespace
- */
- @Test
- public void validate_shouldFailValidationIfDescriptionIsNullOrEmptyOrWhitespace()
- throws Exception {
- RelationshipType type = new RelationshipType();
- type.setName("name");
- type.setDescription(null);
- Errors errors = new BindException(type, "type");
- new RelationshipTypeValidator().validate(type, errors);
- Assert.assertFalse(errors.hasFieldErrors("description"));
- type.setDescription("");
- errors = new BindException(type, "type");
- new RelationshipTypeValidator().validate(type, errors);
- Assert.assertFalse(errors.hasFieldErrors("description"));
- type.setDescription(" ");
- errors = new BindException(type, "type");
- new RelationshipTypeValidator().validate(type, errors);
- Assert.assertFalse(errors.hasFieldErrors("description"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement