Skip to content

Commit

Permalink
fix: update DateOfBirth regex
Browse files Browse the repository at this point in the history
Update DateOfBirth Regex and solve Null Test Cases
  • Loading branch information
jovantanyk committed Mar 20, 2024
1 parent 99b2bb7 commit 9436d09
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/DateOfBirth.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DateOfBirth {
public static final String MESSAGE_CONSTRAINTS =
"Date of birth should be in the format of YYYY-MM-DD, and it should not be blank.";

public static final String VALIDATION_REGEX = "^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/\\d{4}$";
public static final String VALIDATION_REGEX = "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])";

private final LocalDate dateOfBirth;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Person toModelType() throws IllegalValueException {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Status.class.getSimpleName()));
}
if (!Status.isValidStatus(status)) {
throw new IllegalValueException(Sex.MESSAGE_CONSTRAINTS);
throw new IllegalValueException(Status.MESSAGE_CONSTRAINTS);
}
final Status modelStatus = new Status(status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void toModelType_nullDob_throwsIllegalValueException() {
VALID_ADDRESS, null, VALID_SEX, VALID_STATUS, VALID_EMAIL, VALID_COUNTRY,
VALID_ALLERGIES, VALID_BLOODTYPE, VALID_CONDITION, VALID_DOA, VALID_DIAGNOSIS,
VALID_SYMPTOM);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName());
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, DateOfBirth.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@Test
Expand All @@ -172,7 +172,7 @@ public void toModelType_nullSex_throwsIllegalValueException() {
VALID_ADDRESS, VALID_DOB, null, VALID_STATUS, VALID_EMAIL, VALID_COUNTRY,
VALID_ALLERGIES, VALID_BLOODTYPE, VALID_CONDITION, VALID_DOA, VALID_DIAGNOSIS,
VALID_SYMPTOM);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName());
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Sex.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@Test
Expand All @@ -193,7 +193,7 @@ public void toModelType_nullStatus_throwsIllegalValueException() {
VALID_ADDRESS, VALID_DOB, VALID_SEX, null, VALID_EMAIL, VALID_COUNTRY,
VALID_ALLERGIES, VALID_BLOODTYPE, VALID_CONDITION, VALID_DOA, VALID_DIAGNOSIS,
VALID_SYMPTOM);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName());
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Status.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
}

0 comments on commit 9436d09

Please sign in to comment.