Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2324S1#183 from jx124/add-key-milesto…
Browse files Browse the repository at this point in the history
…ne-null-check

Add null check for key milestone
  • Loading branch information
garylow2001 committed Nov 12, 2023
2 parents dd045fd + b22f234 commit ec754f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,15 @@ public Person toModelType() throws IllegalValueException {
final Set<Tag> modelTags = new HashSet<>(personTags);

if (type == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "Type"));
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Type.class.getSimpleName()));
}
if (type.equals(TYPE_CLIENT)) {
return new Client(modelName, modelPhone, modelEmail, modelAddress, modelMeetingTime, modelTags);
} else if (type.equals(TYPE_LEAD)) {
if (keyMilestone == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
KeyMilestone.class.getSimpleName()));
}
if (!KeyMilestone.isValidKeyMilestone(keyMilestone)) {
throw new IllegalValueException(KeyMilestone.MESSAGE_CONSTRAINTS);
}
Expand Down
14 changes: 10 additions & 4 deletions src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public void toModelType_nullPhone_throwsIllegalValueException() {
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
//uncomment later
@Test
public void toModelType_nullPhoneWithValidKeyMilestone_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_TYPE,
Expand Down Expand Up @@ -142,7 +141,6 @@ public void toModelType_nullAddress_throwsIllegalValueException() {

@Test
public void toModelType_invalidType_throwsIllegalValueException() {
//todo: this test need to be fixed, the exception thrown is for meeting type, not for type
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_TYPE, VALID_ADDRESS,
CLIENT_KEYMILESTONE_NULL, VALID_MEETING_TIME, VALID_TAGS);
Expand Down Expand Up @@ -174,6 +172,7 @@ public void toModelType_leadWithInvalidKeyMilestone_throwsIllegalValueException(
VALID_MEETING_TIME, VALID_TAGS);
assertThrows(IllegalValueException.class, person::toModelType);
}

@Test
public void toModelType_invalidTagsWithValidKeyMilestone_throwsIllegalValueException() {
List<JsonAdaptedTag> invalidTags = new ArrayList<>(VALID_TAGS);
Expand All @@ -195,18 +194,25 @@ public void toModelType_invalidMeetingTime_throwsIllegalValueException() {

@Test
public void toModelType_invalidKeyMilestone_throwsIllegalValueException() {
//the meeting time is invalid, need to fix
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, TYPE_LEAD,
VALID_ADDRESS, VALID_KEYMILESTONE, VALID_MEETING_TIME, VALID_TAGS);
String expectedMessage = KeyMilestone.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullKeyMilestone_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, TYPE_LEAD,
VALID_ADDRESS, null, VALID_MEETING_TIME, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT,
KeyMilestone.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_validKeyMilestone_returnsPerson() throws Exception {
//the meeting time is invalid, need to fix
final List<JsonAdaptedTag> validTagBob = BOB.getTags().stream()
.map(JsonAdaptedTag::new)
.collect(Collectors.toList());
Expand Down

0 comments on commit ec754f5

Please sign in to comment.