Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/src/test/java/org/openmrs/validator/ValidateUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package org.openmrs.validator;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -208,4 +209,21 @@ public void validate_shouldReturnThrowExceptionAlongWithAppropriateMessageIfTheO
ValidationException exception = assertThrows(ValidationException.class, () -> ValidateUtil.validate(drug));
assertTrue(exception.getMessage().contains("failed to validate with reason: name: This value exceeds the maximum length of 255 permitted for this field."));
}

//fixed :validating a location
@Test
public void validate_shouldExposeExactValidationMessage() {
// Arrange
Location loc = new Location(); // invalid: name missing
BindException errors = new BindException(loc, "location");

// Act
ValidationException ex = assertThrows(ValidationException.class,
() -> ValidateUtil.validate(loc));

// Assert
assertTrue(ex.getErrors().hasFieldErrors("name"));
assertEquals("error.name", ex.getErrors().getFieldError("name").getCode());
}

}