Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code coverage #228

Merged
merged 2 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book.";
public static final String MESSAGE_DOESNT_EXIST = "This person hasn't been saved";
public static final String MESSAGE_INVALID_DOCTOR_TAGS = "Please enter valid Doctor tags.";
public static final String MESSAGE_INVALID_PATIENT_TAGS = "Please enter valid Patient tags.";
public static final String MESSAGE_IC_CHANGED = "You can't change a person's IC";
public static final String MESSAGE_EDIT_WRONG_FIELDS =
"Doctors cannot have Condition, BloodType or Emergency Contact fields.";
private static final Logger logger = LogsCenter.getLogger(EditCommand.class.getName());
private final Ic nric;
private final EditPersonDescriptor editPersonDescriptor;
Expand Down Expand Up @@ -135,7 +139,7 @@
editedPerson = createEditedDoctor(doctorToEdit, editPersonDescriptor);
}
if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
logger.warning("Edited Person and orignal person are the same");
logger.warning("Edited Person and original person are the same");

Check warning on line 142 in src/main/java/seedu/address/logic/commands/EditCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/EditCommand.java#L142

Added line #L142 was not covered by tests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

siuuu

throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}
return editedPerson;
Expand All @@ -144,19 +148,19 @@
if (editPersonDescriptor.getTags().isPresent()
&& !editPersonDescriptor.isValidPatientTagList(editPersonDescriptor.getTags().get())) {
logger.warning("Invalid tag for patient");
throw new CommandException("Please enter a valid patient tag.");
throw new CommandException(MESSAGE_INVALID_PATIENT_TAGS);
}
}
private void validateDoctor() throws CommandException {
if (editPersonDescriptor.getCondition().isPresent() || editPersonDescriptor.getBloodType().isPresent()
|| editPersonDescriptor.getEmergencyContact().isPresent()) {
logger.warning("Error thrown - tried to edit condition/blood type/emergency contact of doctor");
throw new CommandException("Doctors cannot have Condition, BloodType or Emergency Contact fields.");
throw new CommandException(MESSAGE_EDIT_WRONG_FIELDS);
}
if (editPersonDescriptor.getTags().isPresent()
&& !editPersonDescriptor.isValidDoctorTagList(editPersonDescriptor.getTags().get())) {
logger.warning(editPersonDescriptor.getTags().toString());
throw new CommandException("Please enter valid Doctor tags.");
throw new CommandException(MESSAGE_INVALID_DOCTOR_TAGS);
}
}

Expand Down
41 changes: 41 additions & 0 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_BLOODTYPE_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_CONDITION_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_CARDIOLOGIST;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_LOW;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
Expand Down Expand Up @@ -155,6 +158,44 @@ public void execute_invalidPersonNricUnfilteredList_failure() {
assertCommandFailure(editCommand, model, "This person hasn't been saved");
}

@Test
public void editDoctor_editBloodType_throwsException() {
Ic nricOfFirstDoctor = model.getFilteredDoctorList().get(0).getIc();
Doctor editedDoctor = new DoctorBuilder(nricOfFirstDoctor).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(nricOfFirstDoctor,
editedDoctor).withBloodType(VALID_BLOODTYPE_AMY).build();
EditCommand editCommand = new EditCommand(nricOfFirstDoctor, descriptor);
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_EDIT_WRONG_FIELDS);
}

@Test
public void editDoctor_editCondition_throwsException() {
Ic nricOfFirstDoctor = model.getFilteredDoctorList().get(0).getIc();
Doctor editedDoctor = new DoctorBuilder(nricOfFirstDoctor).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(nricOfFirstDoctor,
editedDoctor).withCondition(VALID_CONDITION_AMY).build();
EditCommand editCommand = new EditCommand(nricOfFirstDoctor, descriptor);
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_EDIT_WRONG_FIELDS);
}

@Test
public void editDoctor_invalidTags_throwsException() {
Ic nricOfFirstDoctor = model.getFilteredDoctorList().get(0).getIc();
Doctor editedDoctor = new DoctorBuilder(nricOfFirstDoctor).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(nricOfFirstDoctor,
editedDoctor).withTags(VALID_TAG_LOW).build();
EditCommand editCommand = new EditCommand(nricOfFirstDoctor, descriptor);
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_INVALID_DOCTOR_TAGS);
}
@Test
public void editPatient_invalidTags_throwsException() {
Ic nricOfFirstPatient = model.getFilteredPatientList().get(0).getIc();
Doctor editedDoctor = new DoctorBuilder(nricOfFirstPatient).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(nricOfFirstPatient,
editedDoctor).withTags(VALID_TAG_CARDIOLOGIST).build();
EditCommand editCommand = new EditCommand(nricOfFirstPatient, descriptor);
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_INVALID_PATIENT_TAGS);
}
@Test
public void equals() {
final Ic nricOfFirstPerson = model.getFilteredPatientList().get(0).getIc();
Expand Down
Loading