diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index 9aa028a2b38..2715bf85579 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -141,11 +141,15 @@ public Person toModelType() throws IllegalValueException { final Set 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); } diff --git a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java index 52cbc429607..d299a2eb143 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java @@ -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, @@ -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); @@ -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 invalidTags = new ArrayList<>(VALID_TAGS); @@ -195,7 +194,6 @@ 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); @@ -203,10 +201,18 @@ public void toModelType_invalidKeyMilestone_throwsIllegalValueException() { 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 validTagBob = BOB.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList());