Skip to content

Commit

Permalink
Merge pull request #230 from choiwab/alphabugfix/comments-storage-test
Browse files Browse the repository at this point in the history
ep comments for storage test cases
  • Loading branch information
zaidansani authored Nov 7, 2024
2 parents 9067f56 + ce9b12a commit 78f979c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ class JsonAdaptedAppointmentTest {

@Test
void constructor_validArguments_returnsCorrectJsonAdaptedAppointment() throws IllegalValueException {
// EP: Standard valid input test
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(1, VALID_APPOINTMENT_TYPE,
VALID_APPOINTMENT_DATE_TIME, 1, VALID_SICKNESS, VALID_MEDICINE);
Appointment modelAppointment = appointment.toModelType(addressBookStub);
JsonAdaptedAppointment appointment1 = new JsonAdaptedAppointment(modelAppointment);
modelAppointment = appointment1.toModelType(addressBookStub);

// EP: Validate each attribute of the created Appointment object
assertEquals(LocalDateTime.parse(VALID_APPOINTMENT_DATE_TIME), modelAppointment.getAppointmentDateTime());
assertEquals(VALID_PERSON_ID, modelAppointment.getPerson().getPersonId());
assertEquals(VALID_SICKNESS, modelAppointment.getSickness().value);
Expand All @@ -51,10 +53,12 @@ void constructor_validArguments_returnsCorrectJsonAdaptedAppointment() throws Il

@Test
void toModelType_validAppointmentDetails_returnsAppointment() throws Exception {
// EP: Valid input test to ensure model conversion works as expected
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(1, VALID_APPOINTMENT_TYPE,
VALID_APPOINTMENT_DATE_TIME, 1, VALID_SICKNESS, VALID_MEDICINE);
Appointment modelAppointment = appointment.toModelType(addressBookStub);

// EP: Assert that each component is correctly set
assertEquals(VALID_APPOINTMENT_TYPE, modelAppointment.getAppointmentType().value);
assertEquals(LocalDateTime.parse(VALID_APPOINTMENT_DATE_TIME), modelAppointment.getAppointmentDateTime());
assertEquals(VALID_PERSON_ID, modelAppointment.getPerson().getPersonId());
Expand All @@ -64,41 +68,47 @@ void toModelType_validAppointmentDetails_returnsAppointment() throws Exception {

@Test
void toModelType_nullAppointmentType_throwsIllegalValueException() {
// EP: Null appointment type test
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(
1, null, VALID_APPOINTMENT_DATE_TIME, VALID_PERSON_ID, VALID_SICKNESS, VALID_MEDICINE);
assertThrows(IllegalValueException.class, () -> appointment.toModelType(addressBookStub));
}

@Test
void toModelType_invalidAppointmentType_throwsIllegalValueException() {
// EP: Invalid appointment type using boundary empty string test
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(1, INVALID_APPOINTMENT_TYPE,
VALID_APPOINTMENT_DATE_TIME, VALID_PERSON_ID, VALID_SICKNESS, VALID_MEDICINE);
assertThrows(IllegalValueException.class, () -> appointment.toModelType(addressBookStub));
}

@Test
void toModelType_nullAppointmentDateTime_throwsIllegalValueException() {
// EP: Null date/time test to ensure error handling
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(
1, VALID_APPOINTMENT_TYPE, null, VALID_PERSON_ID, VALID_SICKNESS, VALID_MEDICINE);
assertThrows(IllegalValueException.class, () -> appointment.toModelType(addressBookStub));
}

@Test
void toModelType_invalidAppointmentDateTime_throwsIllegalValueException() {
// EP: Invalid date/time format (month > 12) for boundary testing of date parsing
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(
1, VALID_APPOINTMENT_TYPE, INVALID_DATE_TIME, VALID_PERSON_ID, VALID_SICKNESS, VALID_MEDICINE);
assertThrows(IllegalValueException.class, () -> appointment.toModelType(addressBookStub));
}

@Test
void toModelType_nullPersonId_throwsIllegalValueException() {
// EP: Boundary test with zero ID
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(
1, VALID_APPOINTMENT_TYPE, VALID_APPOINTMENT_DATE_TIME, 0, VALID_SICKNESS, VALID_MEDICINE);
assertThrows(IllegalValueException.class, () -> appointment.toModelType(addressBookStub));
}

@Test
void toModelType_invalidPersonId_throwsIllegalValueException() {
// EP: Invalid negative person ID
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(1, VALID_APPOINTMENT_TYPE,
VALID_APPOINTMENT_DATE_TIME, INVALID_PERSON_ID, VALID_SICKNESS, VALID_MEDICINE);
assertThrows(IllegalValueException.class, () -> appointment.toModelType(addressBookStub));
Expand All @@ -108,13 +118,15 @@ void toModelType_invalidPersonId_throwsIllegalValueException() {
@Disabled("Works fine on pc but throws a null pointer exception in github")
@Test
void toModelType_nullSickness_throwsIllegalValueException() {
// EP: Null sickness field test
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(
1, VALID_APPOINTMENT_TYPE, VALID_APPOINTMENT_DATE_TIME, VALID_PERSON_ID, null, VALID_MEDICINE);
assertThrows(IllegalValueException.class, () -> appointment.toModelType(addressBookStub));
}

@Test
void toModelType_invalidSickness_throwsIllegalValueException() {
// EP: Boundary test with empty sickness string
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(1, VALID_APPOINTMENT_TYPE,
VALID_APPOINTMENT_DATE_TIME, VALID_PERSON_ID, INVALID_SICKNESS, VALID_MEDICINE);
assertThrows(IllegalValueException.class, () -> appointment.toModelType(addressBookStub));
Expand All @@ -124,13 +136,15 @@ void toModelType_invalidSickness_throwsIllegalValueException() {
@Disabled("Works fine on pc but throws a null pointer exception in github")
@Test
void toModelType_nullMedicine_throwsIllegalValueException() {
// EP: Null medicine field test
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(
1, VALID_APPOINTMENT_TYPE, VALID_APPOINTMENT_DATE_TIME, VALID_PERSON_ID, VALID_SICKNESS, null);
assertThrows(IllegalValueException.class, () -> appointment.toModelType(addressBookStub));
}

@Test
void toModelType_invalidMedicine_throwsIllegalValueException() {
// EP: Boundary test
JsonAdaptedAppointment appointment = new JsonAdaptedAppointment(1, VALID_APPOINTMENT_TYPE,
VALID_APPOINTMENT_DATE_TIME, VALID_PERSON_ID, VALID_SICKNESS, INVALID_MEDICINE);
assertThrows(IllegalValueException.class, () -> appointment.toModelType(addressBookStub));
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class JsonAdaptedPersonTest {
@Test
public void toModelType_validPersonDetails_returnsPerson() throws Exception {
JsonAdaptedPerson person = new JsonAdaptedPerson(new Person(0, BENSON));
// EP: Ensures object equality with valid inputs
assertEquals(BENSON, person.toModelType().getPersonDescriptor());
}

Expand All @@ -49,6 +50,7 @@ public void toModelType_invalidName_throwsIllegalValueException() {
new JsonAdaptedPerson(INVALID_PERSON_ID, INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_STATUS, VALID_TAGS);
String expectedMessage = Name.MESSAGE_CONSTRAINTS;
// EP: Boundary test (invalid characters)
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand All @@ -57,6 +59,7 @@ public void toModelType_nullName_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(INVALID_PERSON_ID, null,
VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_STATUS, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName());
// EP: Null check
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand All @@ -66,6 +69,7 @@ public void toModelType_invalidPhone_throwsIllegalValueException() {
new JsonAdaptedPerson(INVALID_PERSON_ID, VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_STATUS, VALID_TAGS);
String expectedMessage = Phone.MESSAGE_CONSTRAINTS;
// EP: Boundary test (phone length)
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand All @@ -74,6 +78,7 @@ public void toModelType_nullPhone_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(INVALID_PERSON_ID, VALID_NAME, null, VALID_EMAIL,
VALID_ADDRESS, VALID_STATUS, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName());
// EP: Null check for phone
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand All @@ -83,6 +88,7 @@ public void toModelType_invalidEmail_throwsIllegalValueException() {
new JsonAdaptedPerson(INVALID_PERSON_ID, VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS,
VALID_STATUS, VALID_TAGS);
String expectedMessage = Email.MESSAGE_CONSTRAINTS;
// EP: Missing '@' symbol boundary check
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand All @@ -91,6 +97,7 @@ public void toModelType_nullEmail_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(INVALID_PERSON_ID, VALID_NAME, VALID_PHONE, null,
VALID_ADDRESS, VALID_STATUS, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName());
// EP: Null check for email
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand All @@ -100,6 +107,7 @@ public void toModelType_invalidAddress_throwsIllegalValueException() {
new JsonAdaptedPerson(INVALID_PERSON_ID, VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS,
VALID_STATUS, VALID_TAGS);
String expectedMessage = Address.MESSAGE_CONSTRAINTS;
// EP: Address cannot be blank
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand All @@ -108,6 +116,7 @@ public void toModelType_nullAddress_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(INVALID_PERSON_ID, VALID_NAME, VALID_PHONE, VALID_EMAIL,
null, VALID_STATUS, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName());
// EP: Null check for address
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand All @@ -118,6 +127,7 @@ public void toModelType_invalidTags_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(INVALID_PERSON_ID, VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
VALID_STATUS, invalidTags);
// EP: Boundary test (tag format)
assertThrows(IllegalValueException.class, person::toModelType);
}

Expand All @@ -127,6 +137,7 @@ public void toModelType_invalidStatus_throwsIllegalValueException() {
new JsonAdaptedPerson(INVALID_PERSON_ID, VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
INVALID_STATUS, VALID_TAGS);
String expectedMessage = Status.MESSAGE_CONSTRAINTS;
// EP: Boundary test (status format)
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand All @@ -135,6 +146,7 @@ public void toModelType_nullStatus_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(INVALID_PERSON_ID, VALID_NAME, VALID_PHONE, VALID_EMAIL,
VALID_ADDRESS, null, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Status.class.getSimpleName());
// EP: Null check for status
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class JsonAddressBookStorageTest {

@Test
public void readAddressBook_nullFilePath_throwsNullPointerException() {
// EP: Null file path input
assertThrows(NullPointerException.class, () -> readAddressBook(null));
}

Expand All @@ -42,26 +43,31 @@ private Path addToTestDataPathIfNotNull(String prefsFileInTestDataFolder) {

@Test
public void read_missingFile_emptyResult() throws Exception {
// EP: File does not exist, expect empty result
assertFalse(readAddressBook("NonExistentFile.json").isPresent());
}

@Test
public void read_notJsonFormat_exceptionThrown() {
// EP: File is not in JSON format
assertThrows(DataLoadingException.class, () -> readAddressBook("notJsonFormatAddressBook.json"));
}

@Test
public void readAddressBook_invalidPersonAddressBook_throwDataLoadingException() {
// EP: JSON file has an invalid person entry
assertThrows(DataLoadingException.class, () -> readAddressBook("invalidPersonAddressBook.json"));
}

@Test
public void readAddressBook_invalidAndValidPersonAddressBook_throwDataLoadingException() {
// EP: JSON file contains both valid and invalid person entries
assertThrows(DataLoadingException.class, () -> readAddressBook("invalidAndValidPersonAddressBook.json"));
}

@Test
public void readAndSaveAddressBook_allInOrder_success() throws Exception {
// EP: Typical address book data saved and read in expected order
Path filePath = testFolder.resolve("TempAddressBook.json");
AddressBook original = getTypicalAddressBook();
JsonAddressBookStorage jsonAddressBookStorage = new JsonAddressBookStorage(filePath);
Expand Down Expand Up @@ -89,6 +95,7 @@ public void readAndSaveAddressBook_allInOrder_success() throws Exception {

@Test
public void saveAddressBook_nullAddressBook_throwsNullPointerException() {
// EP: Null address book input, expect NullPointerException
assertThrows(NullPointerException.class, () -> saveAddressBook(null, "SomeFile.json"));
}

Expand All @@ -106,6 +113,7 @@ private void saveAddressBook(ReadOnlyAddressBook addressBook, String filePath) {

@Test
public void saveAddressBook_nullFilePath_throwsNullPointerException() {
// EP: Null file path input for saving, expect NullPointerException
assertThrows(NullPointerException.class, () -> saveAddressBook(new AddressBook(), null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class JsonAppointmentBookStorageTest {

@Test
public void readAppointmentBook_nullFilePath_throwsNullPointerException() {
// EP: Null file path
assertThrows(NullPointerException.class, () -> readAppointmentBook(null));
}

Expand All @@ -48,16 +49,19 @@ private Path addToTestDataPathIfNotNull(String filePath) {

@Test
public void read_missingFile_emptyResult() throws Exception {
// EP: Missing file, expect empty result
assertFalse(readAppointmentBook("NonExistentFile.json").isPresent());
}

@Test
public void read_notJsonFormat_exceptionThrown() {
// EP: Incorrect format, expect DataLoadingException
assertThrows(DataLoadingException.class, () -> readAppointmentBook("notJsonFormatAppointmentBook.json"));
}

@Test
public void readAppointmentBook_invalidAppointmentBook_throwDataLoadingException() {
// EP: Invalid data in JSON, expect DataLoadingException
assertThrows(DataLoadingException.class, () -> readAppointmentBook("invalidAppointmentBook.json"));
}

Expand All @@ -68,13 +72,15 @@ public void readAppointmentBook_invalidAndValidAppointmentBook_throwDataLoadingE

@Test
public void saveAppointmentBook_nullAppointmentBook_throwsNullPointerException() {
// EP: Null appointment book input
assertThrows(NullPointerException.class, () -> saveAppointmentBook(null, "SomeFile.json"));
}

/**
* Saves {@code appointmentBook} at the specified {@code filePath}.
*/
private void saveAppointmentBook(ReadOnlyAppointmentBook appointmentBook, String filePath) {
// EP: Null file path
try {
new JsonAppointmentBookStorage(Paths.get(filePath))
.saveAppointmentBook(appointmentBook, addToTestDataPathIfNotNull(filePath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class JsonSerializableAddressBookTest {

@Test
public void toModelType_typicalPersonsFile_success() throws Exception {
// EP: Valid file with typical persons
JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(TYPICAL_PERSONS_FILE,
JsonSerializableAddressBook.class).get();
AddressBook addressBookFromFile = dataFromFile.toModelType();
Expand All @@ -31,13 +32,15 @@ public void toModelType_typicalPersonsFile_success() throws Exception {

@Test
public void toModelType_invalidPersonFile_throwsIllegalValueException() throws Exception {
// EP: File with invalid person entry
JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(INVALID_PERSON_FILE,
JsonSerializableAddressBook.class).get();
assertThrows(IllegalValueException.class, dataFromFile::toModelType);
}

@Test
public void toModelType_duplicatePersons_throwsIllegalValueException() throws Exception {
// EP: File with duplicate person entries
JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(DUPLICATE_PERSON_FILE,
JsonSerializableAddressBook.class).get();
assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_PERSON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void toModelType_typicalAppointmentsFile_success() throws Exception {
void toModelType_invalidAppointmentFile_throwsIllegalValueException() throws Exception {
JsonSerializableAppointmentBook dataFromFile = JsonUtil.readJsonFile(INVALID_APPOINTMENT_FILE,
JsonSerializableAppointmentBook.class).get();
// EP: File with invalid appointment entry
assertThrows(IllegalValueException.class, () -> dataFromFile.toModelType(addressBookStub));
}

Expand All @@ -70,6 +71,7 @@ void toModelType_invalidAppointmentFile_throwsIllegalValueException() throws Exc
void toModelType_duplicateAppointments_throwsIllegalValueException() throws Exception {
JsonSerializableAppointmentBook dataFromFile = JsonUtil.readJsonFile(DUPLICATE_APPOINTMENT_FILE,
JsonSerializableAppointmentBook.class).get();
// EP: File with duplicate appointments
assertThrows(IllegalValueException.class,
JsonSerializableAppointmentBook.MESSAGE_DUPLICATE_APPOINTMENT, () -> dataFromFile
.toModelType(addressBookStub));
Expand All @@ -80,6 +82,7 @@ void toModelType_emptyAppointmentList_noExceptionThrown() throws IllegalValueExc
JsonSerializableAppointmentBook jsonSerializableAppointmentBook =
new JsonSerializableAppointmentBook(Collections.emptyList(), 0);
AppointmentBook appointmentBook = jsonSerializableAppointmentBook.toModelType(addressBookStub);
// EP: Empty appointment list
assertEquals(0, appointmentBook.getAppointmentList().size());
}

Expand Down
Loading

0 comments on commit 78f979c

Please sign in to comment.