Skip to content

Commit

Permalink
Merge pull request #228 from tanveersingh10/master
Browse files Browse the repository at this point in the history
Improve code coverage
  • Loading branch information
tanveersingh10 committed Nov 12, 2023
2 parents 8643499 + f95559b commit 80b33bb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
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 class EditCommand extends Command {
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 @@ private Person getEditedPerson(Model model, Person personToEdit) throws CommandE
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");
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}
return editedPerson;
Expand All @@ -144,19 +148,19 @@ private void validatePatient() throws CommandException {
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

0 comments on commit 80b33bb

Please sign in to comment.