diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index b357a852e39..565fa976e59 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -1,10 +1,16 @@ package seedu.address.logic.commands; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_INVOLVEMENT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; + import java.util.Set; import seedu.address.logic.commands.descriptors.EditPersonDescriptor; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; +import seedu.address.model.person.Gender; import seedu.address.model.person.Involvement; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -16,10 +22,22 @@ */ public abstract class EditCommand extends Command { - public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; + public static final String MESSAGE_DUPLICATE_PERSON = "This %s already exists in the address book."; 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."; + protected static final String MESSAGE_USAGE = ": Edits the details of the %s identified " + + "by the index number used in the displayed person list. " + + "Existing values will be overwritten by the input values.\n" + + "Parameters: INDEX (must be a positive integer) " + + "[" + PREFIX_NAME + "NAME] " + + "[" + PREFIX_PHONE + "PHONE] " + + "[" + PREFIX_EMAIL + "EMAIL] " + + "[" + PREFIX_GENDER + "GENDER] " + + "[" + PREFIX_INVOLVEMENT + "INVOLVEMENT] "; + + protected static final String EXAMPLE_USAGE = " 1 " + + PREFIX_PHONE + "91234567 " + + PREFIX_EMAIL + "johndoe@example.com"; /** * Creates and returns a {@code Person} with the details of {@code personToEdit} @@ -31,10 +49,10 @@ public static Person createEditedPerson(Person personToEdit, EditPersonDescripto Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName()); Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); - Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); + Gender updatedGender = editPersonDescriptor.getGender().orElse(personToEdit.getGender()); Involvement updatedInvolvement = editPersonDescriptor.getInvolvement().orElse(personToEdit.getInvolvement()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedInvolvement, updatedTags); + return new Person(updatedName, updatedPhone, updatedEmail, updatedGender, updatedInvolvement, updatedTags); } } diff --git a/src/main/java/seedu/address/logic/commands/descriptors/EditPersonDescriptor.java b/src/main/java/seedu/address/logic/commands/descriptors/EditPersonDescriptor.java index 81a932fc931..5cf98ba771f 100644 --- a/src/main/java/seedu/address/logic/commands/descriptors/EditPersonDescriptor.java +++ b/src/main/java/seedu/address/logic/commands/descriptors/EditPersonDescriptor.java @@ -6,48 +6,45 @@ import java.util.Set; import seedu.address.commons.util.CollectionUtil; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; +import seedu.address.model.person.Gender; import seedu.address.model.person.Involvement; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; - +/** + * Stores the details to edit the person with. Each non-empty field value will replace the + * corresponding field value of the person. + */ public class EditPersonDescriptor { - /** - * Stores the details to edit the person with. Each non-empty field value will replace the - * corresponding field value of the person. - */ private Name name; private Phone phone; private Email email; - private Address address; + private Gender gender; private Involvement involvement; private Set tags; /** * Copy constructor. + * A defensive copy of {@code tags} is used internally. */ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setName(toCopy.name); setPhone(toCopy.phone); setEmail(toCopy.email); - setAddress(toCopy.address); + setGender(toCopy.gender); setInvolvement(toCopy.involvement); setTags(toCopy.tags); } - public EditPersonDescriptor() { - - } + public EditPersonDescriptor() {} /** * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull( - name, phone, email, address, involvement, tags); + return CollectionUtil.isAnyNonNull(name, phone, email, gender, involvement, tags); } public void setName(Name name) { @@ -74,12 +71,12 @@ public Optional getEmail() { return Optional.ofNullable(email); } - public void setAddress(Address address) { - this.address = address; + public void setGender(Gender gender) { + this.gender = gender; } - public Optional
getAddress() { - return Optional.ofNullable(address); + public Optional getGender() { + return Optional.ofNullable(gender); } public void setInvolvement(Involvement involvement) { @@ -125,7 +122,7 @@ public boolean equals(Object other) { return getName().equals(e.getName()) && getPhone().equals(e.getPhone()) && getEmail().equals(e.getEmail()) - && getAddress().equals(e.getAddress()) + && getGender().equals(e.getGender()) && getInvolvement().equals(e.getInvolvement()) && getTags().equals(e.getTags()); } diff --git a/src/main/java/seedu/address/logic/commands/descriptors/EditStudentDescriptor.java b/src/main/java/seedu/address/logic/commands/descriptors/EditStudentDescriptor.java index 2c6dad8e95a..353d296b7a6 100644 --- a/src/main/java/seedu/address/logic/commands/descriptors/EditStudentDescriptor.java +++ b/src/main/java/seedu/address/logic/commands/descriptors/EditStudentDescriptor.java @@ -3,8 +3,8 @@ import java.util.Optional; import seedu.address.commons.util.CollectionUtil; +import seedu.address.model.person.Address; import seedu.address.model.person.FormClass; -import seedu.address.model.person.Gender; import seedu.address.model.person.Phone; public class EditStudentDescriptor extends EditPersonDescriptor { @@ -14,11 +14,9 @@ public class EditStudentDescriptor extends EditPersonDescriptor { */ private Phone emergencyContact; private FormClass formClass; - private Gender gender; + private Address address; - public EditStudentDescriptor() { - - } + public EditStudentDescriptor() {} /** * Copy constructor @@ -29,7 +27,7 @@ public EditStudentDescriptor(EditStudentDescriptor toCopy) { super(toCopy); setEmergencyContact(toCopy.emergencyContact); setFormClass(toCopy.formClass); - setGender(toCopy.gender); + setAddress(toCopy.address); } public void setEmergencyContact(Phone phone) { @@ -48,17 +46,17 @@ public Optional getFormClass() { return Optional.ofNullable(formClass); } - public void setGender(Gender gender) { - this.gender = gender; + public void setAddress(Address address) { + this.address = address; } - public Optional getGender() { - return Optional.ofNullable(gender); + public Optional
getAddress() { + return Optional.ofNullable(address); } @Override public boolean isAnyFieldEdited() { - return super.isAnyFieldEdited() || CollectionUtil.isAnyNonNull(emergencyContact, formClass, gender); + return super.isAnyFieldEdited() || CollectionUtil.isAnyNonNull(emergencyContact, formClass, address); } @Override @@ -79,7 +77,7 @@ public boolean equals(Object other) { return super.equals(e) && getEmergencyContact().equals(e.getEmergencyContact()) && getFormClass().equals(e.getFormClass()) - && getGender().equals(e.getGender()); + && getAddress().equals(e.getAddress()); } } diff --git a/src/main/java/seedu/address/logic/commands/descriptors/EditTeacherDescriptor.java b/src/main/java/seedu/address/logic/commands/descriptors/EditTeacherDescriptor.java new file mode 100644 index 00000000000..8eee5e95b85 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/descriptors/EditTeacherDescriptor.java @@ -0,0 +1,57 @@ +package seedu.address.logic.commands.descriptors; + +import java.util.Optional; + +import seedu.address.commons.util.CollectionUtil; +import seedu.address.model.person.OfficeTable; + +/** + * Stores the details to edit the teacher with. Each non-empty field value will replace the + * corresponding field value of the teacher. + */ +public class EditTeacherDescriptor extends EditPersonDescriptor { + private OfficeTable tableNumber; + + public EditTeacherDescriptor() {} + + /** + * Copy constructor. + * + * @param toCopy {@code EditTeacherDescriptor to copy from} + */ + public EditTeacherDescriptor(EditTeacherDescriptor toCopy) { + super(toCopy); + setOfficeTable(toCopy.tableNumber); + } + + @Override + public boolean isAnyFieldEdited() { + return super.isAnyFieldEdited() || CollectionUtil.isAnyNonNull(tableNumber); + } + + public void setOfficeTable(OfficeTable tableNumber) { + this.tableNumber = tableNumber; + } + + public Optional getOfficeTable() { + return Optional.ofNullable(tableNumber); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof EditTeacherDescriptor)) { + return false; + } + + // state check + EditTeacherDescriptor e = (EditTeacherDescriptor) other; + + return super.equals(e) && getOfficeTable().equals(e.getOfficeTable()); + } +} diff --git a/src/main/java/seedu/address/logic/commands/student/AddStudentCommand.java b/src/main/java/seedu/address/logic/commands/student/AddStudentCommand.java index 373561b6a3c..d11123335ed 100644 --- a/src/main/java/seedu/address/logic/commands/student/AddStudentCommand.java +++ b/src/main/java/seedu/address/logic/commands/student/AddStudentCommand.java @@ -28,25 +28,25 @@ public class AddStudentCommand extends Command { + PREFIX_NAME + "NAME " + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " - + PREFIX_ADDRESS + "ADDRESS " + PREFIX_GENDER + "GENDER " + + PREFIX_ADDRESS + "ADDRESS " + PREFIX_FORM_CLASS + "FORM CLASS " + + PREFIX_EMERGENCY_CONTACT + "EMERGENCY_CONTACT \n" + PREFIX_INVOLVEMENT + "INVOLVEMENT " + "[" + PREFIX_TAG + "TAG]... " - + PREFIX_EMERGENCY_CONTACT + "EMERGENCY_CONTACT \n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + PREFIX_PHONE + "98765432 " + PREFIX_EMAIL + "johnd@example.com " - + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " + PREFIX_GENDER + "M " - + PREFIX_INVOLVEMENT + "Math class " - + PREFIX_TAG + "naughty " + + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " + + PREFIX_FORM_CLASS + "3E1" + PREFIX_EMERGENCY_CONTACT + "999 " - + PREFIX_FORM_CLASS + "3E1"; + + PREFIX_INVOLVEMENT + "Math class " + + PREFIX_TAG + "naughty "; public static final String MESSAGE_SUCCESS = "New student added: %1$s"; - public static final String MESSAGE_DUPLICATE_PERSON = "This student already exists in the address book"; + public static final String MESSAGE_DUPLICATE_STUDENT = "This student already exists in the address book"; private final Student toAdd; @@ -63,7 +63,7 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); if (model.hasPerson(toAdd)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); + throw new CommandException(MESSAGE_DUPLICATE_STUDENT); } model.addPerson(toAdd); diff --git a/src/main/java/seedu/address/logic/commands/student/EditStudentCommand.java b/src/main/java/seedu/address/logic/commands/student/EditStudentCommand.java index 69767704217..34f1f7dc744 100644 --- a/src/main/java/seedu/address/logic/commands/student/EditStudentCommand.java +++ b/src/main/java/seedu/address/logic/commands/student/EditStudentCommand.java @@ -2,13 +2,8 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; -import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMERGENCY_CONTACT; import static seedu.address.logic.parser.CliSyntax.PREFIX_FORM_CLASS; -import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; -import static seedu.address.logic.parser.CliSyntax.PREFIX_INVOLVEMENT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; @@ -21,8 +16,8 @@ import seedu.address.logic.commands.descriptors.EditStudentDescriptor; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.person.Address; import seedu.address.model.person.FormClass; -import seedu.address.model.person.Gender; import seedu.address.model.person.MedicalHistory; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; @@ -32,35 +27,28 @@ * Edits the fields of an existing student in the New Address Book. */ public class EditStudentCommand extends EditCommand { - + public static final String TARGET = "student"; public static final String COMMAND_WORD = "editStudent"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " - + "by the index number used in the displayed person list. " - + "Existing values will be overwritten by the input values.\n" - + "Parameters: INDEX (must be a positive integer) " - + "[" + PREFIX_NAME + "NAME] " - + "[" + PREFIX_PHONE + "PHONE] " - + "[" + PREFIX_EMAIL + "EMAIL] " - + "[" + PREFIX_ADDRESS + "ADDRESS] " - + "[" + PREFIX_GENDER + "GENDER] " - + "[" + PREFIX_FORM_CLASS + "FORM CLASS] " - + "[" + PREFIX_INVOLVEMENT + "INVOLVEMENT] " - + "[" + PREFIX_TAG + "TAG] " - + "[" + PREFIX_EMERGENCY_CONTACT + "EMERGENCY CONTACT]...\n" - + "Example: " + COMMAND_WORD + " 1 " - + PREFIX_PHONE + "91234567 " - + PREFIX_EMAIL + "johndoe@example.com"; - - public final EditStudentDescriptor editStudentDescriptor; + public static final String MESSAGE_EDIT_STUDENT_SUCCESS = "Edited Student: %1$s"; + public static final String MESSAGE_DUPLICATE_STUDENT = String.format(EditCommand.MESSAGE_DUPLICATE_PERSON, TARGET); + public static final String MESSAGE_USAGE = COMMAND_WORD + String.format(EditCommand.MESSAGE_USAGE, TARGET) + + "[" + PREFIX_ADDRESS + "ADDRESS] " + + "[" + PREFIX_FORM_CLASS + "FORM CLASS] " + + "[" + PREFIX_EMERGENCY_CONTACT + "EMERGENCY CONTACT] " + + "[" + PREFIX_TAG + "TAG]...\n" + + "Example: " + COMMAND_WORD + EditCommand.EXAMPLE_USAGE; + private final Index index; + private final EditStudentDescriptor editStudentDescriptor; /** - * @param index of the person in the filtered person list to edit + * @param index of the student in the filtered person list to edit * @param editStudentDescriptor details to edit the student with */ public EditStudentCommand(Index index, EditStudentDescriptor editStudentDescriptor) { requireNonNull(editStudentDescriptor); requireNonNull(index); + this.index = index; this.editStudentDescriptor = new EditStudentDescriptor(editStudentDescriptor); } @@ -75,9 +63,9 @@ private static Student createdEditedStudent(Student studentToEdit, EditStudentDe Phone updatedEmergencyContact = editStudentDescriptor.getEmergencyContact().orElse(studentToEdit.getEmergencyContact()); FormClass updatedFormClass = editStudentDescriptor.getFormClass().orElse(studentToEdit.getFormClass()); - Gender updatedGender = editStudentDescriptor.getGender().orElse(studentToEdit.getGender()); + Address updatedAddress = editStudentDescriptor.getAddress().orElse(studentToEdit.getAddress()); MedicalHistory updatedMedicalHistory = studentToEdit.getMedicalHistory(); //edit command does not edit medical - return new Student(person, updatedEmergencyContact, updatedFormClass, updatedGender, updatedMedicalHistory); + return new Student(person, updatedEmergencyContact, updatedFormClass, updatedAddress, updatedMedicalHistory); } @Override @@ -89,16 +77,20 @@ public CommandResult execute(Model model) throws CommandException { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } - Student studentToEdit = (Student) lastShownList.get(index.getZeroBased()); + Person personToEdit = lastShownList.get(index.getZeroBased()); + if (!(personToEdit instanceof Student)) { + throw new CommandException("The person you are trying to edit is not a student!"); + } + Student studentToEdit = (Student) personToEdit; Student editedStudent = createdEditedStudent(studentToEdit, editStudentDescriptor); if (!studentToEdit.isSamePerson(editedStudent) && model.hasPerson(editedStudent)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); + throw new CommandException(MESSAGE_DUPLICATE_STUDENT); } model.setPerson(studentToEdit, editedStudent); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedStudent)); + return new CommandResult(String.format(MESSAGE_EDIT_STUDENT_SUCCESS, editedStudent)); } @Override diff --git a/src/main/java/seedu/address/logic/commands/student/MedicalHistoryCommand.java b/src/main/java/seedu/address/logic/commands/student/MedicalHistoryCommand.java index e6c1438a51d..7bfbea45887 100644 --- a/src/main/java/seedu/address/logic/commands/student/MedicalHistoryCommand.java +++ b/src/main/java/seedu/address/logic/commands/student/MedicalHistoryCommand.java @@ -52,19 +52,21 @@ public MedicalHistoryCommand(Index index, MedicalHistory medicalHistory) { public CommandResult execute(Model model) throws CommandException { requireNonNull(model); List lastShownList = model.getFilteredPersonList(); + if (index.getZeroBased() >= lastShownList.size()) { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } - Student studentToEdit = (Student) lastShownList.get(index.getZeroBased()); - Student editedStudent = new Student(studentToEdit.getName(), studentToEdit.getPhone(), studentToEdit.getEmail(), - studentToEdit.getAddress(), studentToEdit.getInvolvement(), studentToEdit.getTags(), - studentToEdit.getEmergencyContact(), studentToEdit.getFormClass(), studentToEdit.getGender(), - medicalHistory); + Person personToEdit = lastShownList.get(index.getZeroBased()); + if (!(personToEdit instanceof Student)) { + throw new CommandException("You cannot add medical history to a teacher!"); + } + Student studentToEdit = (Student) personToEdit; + Student editedStudent = new Student(studentToEdit, studentToEdit.getEmergencyContact(), + studentToEdit.getFormClass(), studentToEdit.getAddress(), medicalHistory); model.setPerson(studentToEdit, editedStudent); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(generateSuccessMessage(editedStudent)); } diff --git a/src/main/java/seedu/address/logic/commands/StudentCommand.java b/src/main/java/seedu/address/logic/commands/teacher/AddTeacherCommand.java similarity index 51% rename from src/main/java/seedu/address/logic/commands/StudentCommand.java rename to src/main/java/seedu/address/logic/commands/teacher/AddTeacherCommand.java index 85f281332c1..47bce412546 100644 --- a/src/main/java/seedu/address/logic/commands/StudentCommand.java +++ b/src/main/java/seedu/address/logic/commands/teacher/AddTeacherCommand.java @@ -1,60 +1,56 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.teacher; import static java.util.Objects.requireNonNull; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -import static seedu.address.logic.parser.CliSyntax.PREFIX_EMERGENCY_CONTACT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_FORM_CLASS; import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; import static seedu.address.logic.parser.CliSyntax.PREFIX_INVOLVEMENT; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_OFFICE_TABLE; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Student; +import seedu.address.model.person.Teacher; /** - * Adds a student to the address book. + * Adds a teacher to the address book. */ -public class StudentCommand extends Command { +public class AddTeacherCommand extends Command { - public static final String COMMAND_WORD = "student"; + public static final String COMMAND_WORD = "teacher"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a student to the address book. " + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a teacher to the address book. " + "Parameters: " + PREFIX_NAME + "NAME " + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " - + PREFIX_ADDRESS + "ADDRESS " + PREFIX_GENDER + "GENDER " - + PREFIX_FORM_CLASS + "FORM CLASS " + + PREFIX_OFFICE_TABLE + "OFFICE TABLE NUMBER " + PREFIX_INVOLVEMENT + "INVOLVEMENT " + "[" + PREFIX_TAG + "TAG]... " - + PREFIX_EMERGENCY_CONTACT + "EMERGENCY_CONTACT \n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + PREFIX_PHONE + "98765432 " + PREFIX_EMAIL + "johnd@example.com " - + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " + PREFIX_GENDER + "M " - + PREFIX_INVOLVEMENT + "Math class " - + PREFIX_TAG + "naughty " - + PREFIX_EMERGENCY_CONTACT + "999 " - + PREFIX_FORM_CLASS + "3E1"; + + PREFIX_OFFICE_TABLE + "7" + + PREFIX_INVOLVEMENT + "Math HOD " + + PREFIX_TAG + "Colleague"; - public static final String MESSAGE_SUCCESS = "New student added: %1$s"; - public static final String MESSAGE_DUPLICATE_PERSON = "This student already exists in the address book"; + public static final String MESSAGE_SUCCESS = "New teacher added: %1$s"; + public static final String MESSAGE_DUPLICATE_TEACHER = "This teacher already exists in the address book"; - private final Student toAdd; + private final Teacher toAdd; /** - * Creates a StudentCommand to add the specified {@code Student} + * Creates an AddTeacherCommand to add the specified {@code Teacher} */ - public StudentCommand(Student student) { - requireNonNull(student); - toAdd = student; + public AddTeacherCommand(Teacher teacher) { + requireNonNull(teacher); + toAdd = teacher; } @Override @@ -62,7 +58,7 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); if (model.hasPerson(toAdd)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); + throw new CommandException(MESSAGE_DUPLICATE_TEACHER); } model.addPerson(toAdd); @@ -72,7 +68,7 @@ public CommandResult execute(Model model) throws CommandException { @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof StudentCommand // instanceof handles nulls - && toAdd.equals(((StudentCommand) other).toAdd)); + || (other instanceof AddTeacherCommand // instanceof handles nulls + && toAdd.equals(((AddTeacherCommand) other).toAdd)); } } diff --git a/src/main/java/seedu/address/logic/commands/teacher/EditTeacherCommand.java b/src/main/java/seedu/address/logic/commands/teacher/EditTeacherCommand.java new file mode 100644 index 00000000000..de608d4bb8d --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/teacher/EditTeacherCommand.java @@ -0,0 +1,106 @@ +package seedu.address.logic.commands.teacher; + + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_OFFICE_TABLE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; + +import java.util.List; + +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.commands.descriptors.EditTeacherDescriptor; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.person.OfficeTable; +import seedu.address.model.person.Person; +import seedu.address.model.person.Teacher; + +/** + * Edits the details of an existing teacher in the address book. + */ +public class EditTeacherCommand extends EditCommand { + + public static final String COMMAND_WORD = "editTeacher"; + + public static final String TARGET = "teacher"; + public static final String MESSAGE_EDIT_TEACHER_SUCCESS = "Edited teacher: %1$s"; + public static final String MESSAGE_USAGE = COMMAND_WORD + String.format(EditCommand.MESSAGE_USAGE, TARGET) + + "[" + PREFIX_OFFICE_TABLE + "OFFICE TABLE NUMBER] " + + "[" + PREFIX_TAG + "TAG]...\n" + + "Example: " + COMMAND_WORD + EditCommand.EXAMPLE_USAGE; + public static final String MESSAGE_DUPLICATE_TEACHER = String.format(EditCommand.MESSAGE_DUPLICATE_PERSON, TARGET); + + + private final Index index; + private final EditTeacherDescriptor editTeacherDescriptor; + + /** + * @param index of the teacher in the filtered person list to edit + * @param editTeacherDescriptor details to edit the teacher with + */ + public EditTeacherCommand(Index index, EditTeacherDescriptor editTeacherDescriptor) { + requireNonNull(index); + requireNonNull(editTeacherDescriptor); + + this.index = index; + this.editTeacherDescriptor = editTeacherDescriptor; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredPersonList(); + + if (index.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + Person personToEdit = lastShownList.get(index.getZeroBased()); + if (!(personToEdit instanceof Teacher)) { + throw new CommandException("The person you are trying to edit is not a teacher!"); + } + Teacher teacherToEdit = (Teacher) personToEdit; + Teacher editedTeacher = createdEditedTeacher(teacherToEdit, editTeacherDescriptor); + + if (!teacherToEdit.isSamePerson(editedTeacher) && model.hasPerson(editedTeacher)) { + throw new CommandException(MESSAGE_DUPLICATE_TEACHER); + } + + model.setPerson(teacherToEdit, editedTeacher); + model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + return new CommandResult(String.format(MESSAGE_EDIT_TEACHER_SUCCESS, editedTeacher)); + } + + /** + * Creates and returns a {@code Teacher} with the details of {@code teacherToEdit} + * edited with {@code editTeacherDescriptor}. + */ + private static Teacher createdEditedTeacher(Teacher teacherToEdit, EditTeacherDescriptor editTeacherDescriptor) { + assert teacherToEdit != null; + + Person person = EditCommand.createEditedPerson(teacherToEdit, editTeacherDescriptor); + OfficeTable updatedOfficeTable = editTeacherDescriptor.getOfficeTable().orElse(teacherToEdit.getOfficeTable()); + return new Teacher(person, updatedOfficeTable); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof EditTeacherCommand)) { + return false; + } + + // state check + EditTeacherCommand e = (EditTeacherCommand) other; + return index.equals(e.index) && editTeacherDescriptor.equals(e.editTeacherDescriptor); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 23eb28685db..a36e1bda060 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -18,10 +18,14 @@ import seedu.address.logic.commands.student.AddStudentCommand; import seedu.address.logic.commands.student.EditStudentCommand; import seedu.address.logic.commands.student.MedicalHistoryCommand; +import seedu.address.logic.commands.teacher.AddTeacherCommand; +import seedu.address.logic.commands.teacher.EditTeacherCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.logic.parser.student.AddStudentCommandParser; import seedu.address.logic.parser.student.EditStudentCommandParser; import seedu.address.logic.parser.student.MedicalHistoryCommandParser; +import seedu.address.logic.parser.teacher.AddTeacherCommandParser; +import seedu.address.logic.parser.teacher.EditTeacherCommandParser; /** * Parses user input. @@ -53,9 +57,15 @@ public Command parseCommand(String userInput) throws ParseException { case AddStudentCommand.COMMAND_WORD: return new AddStudentCommandParser().parse(arguments); + case AddTeacherCommand.COMMAND_WORD: + return new AddTeacherCommandParser().parse(arguments); + case EditStudentCommand.COMMAND_WORD: return new EditStudentCommandParser().parse(arguments); + case EditTeacherCommand.COMMAND_WORD: + return new EditTeacherCommandParser().parse(arguments); + case DeleteCommand.COMMAND_WORD: return new DeleteCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 379932a8f61..b26bf5aa797 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -15,6 +15,7 @@ public class CliSyntax { public static final Prefix PREFIX_INVOLVEMENT = new Prefix("i/"); public static final Prefix PREFIX_FORM_CLASS = new Prefix("f/"); public static final Prefix PREFIX_GENDER = new Prefix("g/"); + public static final Prefix PREFIX_OFFICE_TABLE = new Prefix("o/"); public static final Prefix PREFIX_COPY_FIELD = new Prefix("c/"); public static final Prefix PREFIX_MEDICAL_HISTORY = new Prefix("m/"); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 5fc330a11d9..4b6322bca27 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -15,6 +15,7 @@ import seedu.address.model.person.Gender; import seedu.address.model.person.Involvement; import seedu.address.model.person.Name; +import seedu.address.model.person.OfficeTable; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; @@ -170,4 +171,19 @@ public static Gender parseGender(String gender) throws ParseException { } return new Gender(gender); } + + /** + * Parses a {@code String tableNumber} into a {@code OfficeTable}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code tableNumber} is invalid. + */ + public static OfficeTable parseOfficeTable(String tableNumber) throws ParseException { + requireNonNull(tableNumber); + String trimmedTableNumber = tableNumber.trim(); + if (!OfficeTable.isValidTable(trimmedTableNumber)) { + throw new ParseException(OfficeTable.MESSAGE_CONSTRAINTS); + } + return new OfficeTable(tableNumber); + } } diff --git a/src/main/java/seedu/address/logic/parser/student/AddStudentCommandParser.java b/src/main/java/seedu/address/logic/parser/student/AddStudentCommandParser.java index a403fe76bea..0ee018880db 100644 --- a/src/main/java/seedu/address/logic/parser/student/AddStudentCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/student/AddStudentCommandParser.java @@ -26,7 +26,6 @@ import seedu.address.model.person.FormClass; import seedu.address.model.person.Gender; import seedu.address.model.person.Involvement; -import seedu.address.model.person.MedicalHistory; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; import seedu.address.model.person.Student; @@ -42,15 +41,15 @@ private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Pre } /** - * Parses the given {@code String} of arguments in the context of the StudentCommand - * and returns an StudentCommand object for execution. + * Parses the given {@code String} of arguments in the context of the AddStudentCommand + * and returns an AddStudentCommand object for execution. * * @throws ParseException if the user input does not conform the expected format */ public AddStudentCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_GENDER, - PREFIX_INVOLVEMENT, PREFIX_TAG, PREFIX_EMERGENCY_CONTACT, PREFIX_FORM_CLASS); + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_GENDER, + PREFIX_ADDRESS, PREFIX_EMERGENCY_CONTACT, PREFIX_FORM_CLASS, PREFIX_INVOLVEMENT, PREFIX_TAG); // put all the non-optional arguments here if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, @@ -62,16 +61,14 @@ public AddStudentCommand parse(String args) throws ParseException { Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); + Gender gender = ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Involvement involvement = ParserUtil.parseInvolvement(argMultimap.getValue(PREFIX_INVOLVEMENT).get()); - Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); Phone emergencyContact = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_EMERGENCY_CONTACT).get()); FormClass formClass = ParserUtil.parseFormClass(argMultimap.getValue(PREFIX_FORM_CLASS).get()); - Gender gender = ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get()); - MedicalHistory medicalHistory = new MedicalHistory(""); //add command does not allow medical - Student student = new Student(name, phone, email, address, involvement, tagList, emergencyContact, formClass, - gender, medicalHistory); - + Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + Student student = new Student(name, phone, email, gender, involvement, address, emergencyContact, formClass, + tagList); return new AddStudentCommand(student); } } diff --git a/src/main/java/seedu/address/logic/parser/student/EditStudentCommandParser.java b/src/main/java/seedu/address/logic/parser/student/EditStudentCommandParser.java index 127d038fe09..6e367879eba 100644 --- a/src/main/java/seedu/address/logic/parser/student/EditStudentCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/student/EditStudentCommandParser.java @@ -29,13 +29,13 @@ import seedu.address.model.tag.Tag; /** - * Parses input arguments and creates a new EditCommand object + * Parses input arguments and creates a new EditStudentCommand object */ public class EditStudentCommandParser implements Parser { /** - * Parses the given {@code String} of arguments in the context of the EditCommand - * and returns an EditCommand object for execution. + * Parses the given {@code String} of arguments in the context of the EditStudentCommand + * and returns an EditStudentCommand object for execution. * * @throws ParseException if the user input does not conform the expected format */ @@ -54,41 +54,41 @@ public EditStudentCommand parse(String args) throws ParseException { pe); } - EditStudentDescriptor editPersonDescriptor = new EditStudentDescriptor(); + EditStudentDescriptor editStudentDescriptor = new EditStudentDescriptor(); if (argMultimap.getValue(PREFIX_NAME).isPresent()) { - editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get())); + editStudentDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get())); } if (argMultimap.getValue(PREFIX_PHONE).isPresent()) { - editPersonDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get())); + editStudentDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get())); } if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { - editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get())); + editStudentDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get())); } if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) { - editPersonDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get())); + editStudentDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get())); } if (argMultimap.getValue(PREFIX_INVOLVEMENT).isPresent()) { - editPersonDescriptor.setInvolvement(ParserUtil.parseInvolvement(argMultimap + editStudentDescriptor.setInvolvement(ParserUtil.parseInvolvement(argMultimap .getValue(PREFIX_INVOLVEMENT).get())); } if (argMultimap.getValue(PREFIX_FORM_CLASS).isPresent()) { - editPersonDescriptor.setFormClass(ParserUtil.parseFormClass(argMultimap + editStudentDescriptor.setFormClass(ParserUtil.parseFormClass(argMultimap .getValue(PREFIX_FORM_CLASS).get())); } if (argMultimap.getValue(PREFIX_EMERGENCY_CONTACT).isPresent()) { - editPersonDescriptor.setEmergencyContact( + editStudentDescriptor.setEmergencyContact( ParserUtil.parsePhone(argMultimap.getValue(PREFIX_EMERGENCY_CONTACT).get())); } if (argMultimap.getValue(PREFIX_GENDER).isPresent()) { - editPersonDescriptor.setGender(ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get())); + editStudentDescriptor.setGender(ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get())); } - parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags); + parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editStudentDescriptor::setTags); - if (!editPersonDescriptor.isAnyFieldEdited()) { + if (!editStudentDescriptor.isAnyFieldEdited()) { throw new ParseException(EditCommand.MESSAGE_NOT_EDITED); } - return new EditStudentCommand(index, editPersonDescriptor); + return new EditStudentCommand(index, editStudentDescriptor); } /** diff --git a/src/main/java/seedu/address/logic/parser/StudentCommandParser.java b/src/main/java/seedu/address/logic/parser/teacher/AddTeacherCommandParser.java similarity index 56% rename from src/main/java/seedu/address/logic/parser/StudentCommandParser.java rename to src/main/java/seedu/address/logic/parser/teacher/AddTeacherCommandParser.java index 33e50d57123..b4aca96db33 100644 --- a/src/main/java/seedu/address/logic/parser/StudentCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/teacher/AddTeacherCommandParser.java @@ -1,36 +1,37 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.teacher; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -import static seedu.address.logic.parser.CliSyntax.PREFIX_EMERGENCY_CONTACT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_FORM_CLASS; import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; import static seedu.address.logic.parser.CliSyntax.PREFIX_INVOLVEMENT; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_OFFICE_TABLE; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import java.util.Set; import java.util.stream.Stream; -import seedu.address.logic.commands.StudentCommand; +import seedu.address.logic.commands.teacher.AddTeacherCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.Prefix; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; -import seedu.address.model.person.FormClass; import seedu.address.model.person.Gender; import seedu.address.model.person.Involvement; -import seedu.address.model.person.MedicalHistory; import seedu.address.model.person.Name; +import seedu.address.model.person.OfficeTable; import seedu.address.model.person.Phone; -import seedu.address.model.person.Student; +import seedu.address.model.person.Teacher; import seedu.address.model.tag.Tag; /** - * Parses input arguments and creates a new StudentCommand object + * Parses input arguments and creates a new AddTeacherCommand object */ -public class StudentCommandParser implements Parser { +public class AddTeacherCommandParser implements Parser { /** * Returns true if none of the prefixes contains empty {@code Optional} values in the given @@ -41,36 +42,32 @@ private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Pre } /** - * Parses the given {@code String} of arguments in the context of the StudentCommand - * and returns an StudentCommand object for execution. + * Parses the given {@code String} of arguments in the context of the AddTeacherCommand + * and returns an AddTeacherCommand object for execution. * * @throws ParseException if the user input does not conform the expected format */ - public StudentCommand parse(String args) throws ParseException { + public AddTeacherCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_GENDER, - PREFIX_INVOLVEMENT, PREFIX_TAG, PREFIX_EMERGENCY_CONTACT, PREFIX_FORM_CLASS); + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_GENDER, + PREFIX_OFFICE_TABLE, PREFIX_INVOLVEMENT, PREFIX_TAG); // put all the non-optional arguments here - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, - PREFIX_EMERGENCY_CONTACT, PREFIX_INVOLVEMENT, PREFIX_FORM_CLASS, PREFIX_GENDER) + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_OFFICE_TABLE, PREFIX_INVOLVEMENT, PREFIX_GENDER) || !argMultimap.getPreamble().isEmpty()) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, StudentCommand.MESSAGE_USAGE)); + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTeacherCommand.MESSAGE_USAGE)); } Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); - Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Involvement involvement = ParserUtil.parseInvolvement(argMultimap.getValue(PREFIX_INVOLVEMENT).get()); - Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Phone emergencyContact = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_EMERGENCY_CONTACT).get()); - FormClass formClass = ParserUtil.parseFormClass(argMultimap.getValue(PREFIX_FORM_CLASS).get()); Gender gender = ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get()); - MedicalHistory medicalHistory = new MedicalHistory(""); //adding student does not allow adding medical - Student student = new Student(name, phone, email, address, involvement, tagList, emergencyContact, formClass, - gender, medicalHistory); + OfficeTable tableNumber = ParserUtil.parseOfficeTable(argMultimap.getValue(PREFIX_OFFICE_TABLE).get()); + Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - return new StudentCommand(student); + Teacher teacher = new Teacher(name, phone, email, gender, involvement, tableNumber, tagList); + return new AddTeacherCommand(teacher); } } diff --git a/src/main/java/seedu/address/logic/parser/teacher/EditTeacherCommandParser.java b/src/main/java/seedu/address/logic/parser/teacher/EditTeacherCommandParser.java new file mode 100644 index 00000000000..b754a485249 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/teacher/EditTeacherCommandParser.java @@ -0,0 +1,100 @@ +package seedu.address.logic.parser.teacher; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_INVOLVEMENT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_OFFICE_TABLE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.commands.descriptors.EditTeacherDescriptor; +import seedu.address.logic.commands.teacher.EditTeacherCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new EditTeacherCommand object + */ +public class EditTeacherCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditTeacherCommand + * and returns an EditTeacherCommand object for execution. + * + * @throws ParseException if the user input does not conform the expected format + */ + public EditTeacherCommand parse(String args) throws ParseException { + requireNonNull(args); + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_GENDER, + PREFIX_OFFICE_TABLE, PREFIX_INVOLVEMENT, PREFIX_TAG); + + Index index; + + try { + index = ParserUtil.parseIndex(argMultimap.getPreamble()); + } catch (ParseException pe) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditTeacherCommand.MESSAGE_USAGE), + pe); + } + + EditTeacherDescriptor editTeacherDescriptor = new EditTeacherDescriptor(); + if (argMultimap.getValue(PREFIX_NAME).isPresent()) { + editTeacherDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get())); + } + if (argMultimap.getValue(PREFIX_PHONE).isPresent()) { + editTeacherDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get())); + } + if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { + editTeacherDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get())); + } + if (argMultimap.getValue(PREFIX_GENDER).isPresent()) { + editTeacherDescriptor.setGender(ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get())); + } + if (argMultimap.getValue(PREFIX_OFFICE_TABLE).isPresent()) { + editTeacherDescriptor.setOfficeTable( + ParserUtil.parseOfficeTable(argMultimap.getValue(PREFIX_OFFICE_TABLE).get())); + } + if (argMultimap.getValue(PREFIX_INVOLVEMENT).isPresent()) { + editTeacherDescriptor.setInvolvement(ParserUtil.parseInvolvement(argMultimap + .getValue(PREFIX_INVOLVEMENT).get())); + } + parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editTeacherDescriptor::setTags); + + if (!editTeacherDescriptor.isAnyFieldEdited()) { + throw new ParseException(EditCommand.MESSAGE_NOT_EDITED); + } + + return new EditTeacherCommand(index, editTeacherDescriptor); + } + + /** + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Set} containing zero tags. + */ + private Optional> parseTagsForEdit(Collection tags) throws ParseException { + assert tags != null; + + if (tags.isEmpty()) { + return Optional.empty(); + } + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(ParserUtil.parseTags(tagSet)); + } + +} diff --git a/src/main/java/seedu/address/model/person/FormClass.java b/src/main/java/seedu/address/model/person/FormClass.java index 067ed98ee25..de4b03aeb4a 100644 --- a/src/main/java/seedu/address/model/person/FormClass.java +++ b/src/main/java/seedu/address/model/person/FormClass.java @@ -18,17 +18,17 @@ public class FormClass { */ public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; - public final String formClass; + public final String value; /** * Constructs an {@code FormClass}. * - * @param formClass A valid formClass. + * @param value A valid form class. */ - public FormClass(String formClass) { - requireNonNull(formClass); - checkArgument(isValidFormClass(formClass), MESSAGE_CONSTRAINTS); - this.formClass = formClass; + public FormClass(String value) { + requireNonNull(value); + checkArgument(isValidFormClass(value), MESSAGE_CONSTRAINTS); + this.value = value; } /** @@ -40,18 +40,18 @@ public static boolean isValidFormClass(String test) { @Override public String toString() { - return formClass; + return value; } @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof FormClass // instanceof handles nulls - && formClass.equals(((FormClass) other).formClass)); // state check + && value.equals(((FormClass) other).value)); // state check } @Override public int hashCode() { - return formClass.hashCode(); + return value.hashCode(); } } diff --git a/src/main/java/seedu/address/model/person/Gender.java b/src/main/java/seedu/address/model/person/Gender.java index 592a1ff2a01..492b174cd97 100644 --- a/src/main/java/seedu/address/model/person/Gender.java +++ b/src/main/java/seedu/address/model/person/Gender.java @@ -12,7 +12,7 @@ public class Gender { public static final String MESSAGE_CONSTRAINTS = "Gender class should only contain one of M (male),F (female),N (non binary)"; - public final String gender; + public final String value; /** * Constructs a gender. @@ -22,7 +22,7 @@ public class Gender { public Gender(String gender) { requireNonNull(gender); checkArgument(isValidGender(gender), MESSAGE_CONSTRAINTS); - this.gender = gender; + this.value = gender; } /** @@ -34,18 +34,18 @@ public static boolean isValidGender(String test) { @Override public String toString() { - return gender; + return value; } @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof Gender // instanceof handles nulls - && gender.equals(((Gender) other).gender)); // state check + && value.equals(((Gender) other).value)); // state check } @Override public int hashCode() { - return gender.hashCode(); + return value.hashCode(); } } diff --git a/src/main/java/seedu/address/model/person/OfficeTable.java b/src/main/java/seedu/address/model/person/OfficeTable.java new file mode 100644 index 00000000000..1c69f61c058 --- /dev/null +++ b/src/main/java/seedu/address/model/person/OfficeTable.java @@ -0,0 +1,50 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Teacher's office table number in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidTable(String)} + */ +public class OfficeTable { + public static final String MESSAGE_CONSTRAINTS = + "Office table numbers should only contain numbers, and it should have at least 1 digit"; + public static final String VALIDATION_REGEX = "\\d{1,}"; + public final String value; + + /** + * Constructs a {@code OfficeTable}. + * + * @param tableNumber A valid table number. + */ + public OfficeTable(String tableNumber) { + requireNonNull(tableNumber); + checkArgument(isValidTable(tableNumber), MESSAGE_CONSTRAINTS); + value = tableNumber; + } + + /** + * Returns true if a given string is a valid table number. + */ + public static boolean isValidTable(String test) { + return test.matches(VALIDATION_REGEX); + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof OfficeTable // instanceof handles nulls + && value.equals(((OfficeTable) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); + } +} diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 8eb8979e944..310f3972dff 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -20,20 +20,20 @@ public class Person { private final Phone phone; private final Email email; private final Involvement involvement; + private final Gender gender; // Data fields - private final Address address; private final Set tags = new HashSet<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Involvement involvement, Set tags) { - requireAllNonNull(name, phone, email, address, involvement, tags); + public Person(Name name, Phone phone, Email email, Gender gender, Involvement involvement, Set tags) { + requireAllNonNull(name, phone, email, gender, involvement, tags); this.name = name; this.phone = phone; this.email = email; - this.address = address; + this.gender = gender; this.involvement = involvement; this.tags.addAll(tags); } @@ -50,8 +50,8 @@ public Email getEmail() { return email; } - public Address getAddress() { - return address; + public Gender getGender() { + return gender; } public Involvement getInvolvement() { @@ -97,7 +97,7 @@ public boolean equals(Object other) { return otherPerson.getName().equals(getName()) && otherPerson.getPhone().equals(getPhone()) && otherPerson.getEmail().equals(getEmail()) - && otherPerson.getAddress().equals(getAddress()) + && otherPerson.getGender().equals(getGender()) && otherPerson.getInvolvement().equals(getInvolvement()) && otherPerson.getTags().equals(getTags()); } @@ -105,7 +105,7 @@ public boolean equals(Object other) { @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, tags); + return Objects.hash(name, phone, email, gender, tags); } @Override @@ -116,8 +116,8 @@ public String toString() { .append(getPhone()) .append("; Email: ") .append(getEmail()) - .append("; Address: ") - .append(getAddress()) + .append("; Gender: ") + .append(getGender()) .append("; Involvement: ") .append(getInvolvement()); @@ -128,5 +128,4 @@ public String toString() { } return builder.toString(); } - } diff --git a/src/main/java/seedu/address/model/person/Student.java b/src/main/java/seedu/address/model/person/Student.java index 8912e611b16..753e0d89ba1 100644 --- a/src/main/java/seedu/address/model/person/Student.java +++ b/src/main/java/seedu/address/model/person/Student.java @@ -12,28 +12,28 @@ public class Student extends Person { private Phone emergencyContact; private FormClass formClass; - private Gender gender; + private Address address; private MedicalHistory medicalHistory; /** - * Constructor for {@code Student} + * Constructor for {@code Student} with every fields present * @param name Name of student * @param phone Phone number of student * @param email Email of student - * @param address Address of student + * @param gender Gender of student * @param involvement Involvement of the student - * @param tags Tags associated to student + * @param address Address of student * @param emergencyContact Emergency contact of student - * @param formClass Form Class of Student - * @param gender Gender of student + * @param formClass Form Class of Student + * @param tags Tags associated to student * @param medicalHistory Medical History of student */ - public Student(Name name, Phone phone, Email email, Address address, Involvement involvement, Set tags, - Phone emergencyContact, FormClass formClass, Gender gender, MedicalHistory medicalHistory) { - super(name, phone, email, address, involvement, tags); + public Student(Name name, Phone phone, Email email, Gender gender, Involvement involvement, Address address, + Phone emergencyContact, FormClass formClass, Set tags, MedicalHistory medicalHistory) { + super(name, phone, email, gender, involvement, tags); this.emergencyContact = emergencyContact; this.formClass = formClass; - this.gender = gender; + this.address = address; this.medicalHistory = medicalHistory; } @@ -43,20 +43,29 @@ public Student(Name name, Phone phone, Email email, Address address, Involvement * @param person person to copy the data from * @param emergencyContact Emergency contact of student * @param formClass Form Class of Student - * @param gender Gender of student + * @param address Address of student * @param medicalHistory Medical History of student */ - - public Student(Person person, Phone emergencyContact, FormClass formClass, Gender gender, - MedicalHistory medicalHistory) { - super(person.getName(), person.getPhone(), person.getEmail(), person.getAddress(), person.getInvolvement(), - person.getTags()); + public Student(Person person, Phone emergencyContact, FormClass formClass, + Address address, MedicalHistory medicalHistory) { + super(person.getName(), person.getPhone(), person.getEmail(), person.getGender(), person.getInvolvement(), + person.getTags()); this.emergencyContact = emergencyContact; this.formClass = formClass; - this.gender = gender; + this.address = address; this.medicalHistory = medicalHistory; } + /** + * Constructor for {@code Student} without medical history + * + */ + public Student(Name name, Phone phone, Email email, Gender gender, Involvement involvement, Address address, + Phone emergencyContact, FormClass formClass, Set tags) { + this(name, phone, email, gender, involvement, address, + emergencyContact, formClass, tags, new MedicalHistory("")); + } + public Phone getEmergencyContact() { return emergencyContact; } @@ -65,8 +74,8 @@ public FormClass getFormClass() { return formClass; } - public Gender getGender() { - return this.gender; + public Address getAddress() { + return this.address; } public MedicalHistory getMedicalHistory() { @@ -90,18 +99,19 @@ public boolean equals(Object other) { Student otherStudent = (Student) other; return super.equals(otherStudent) && this.getEmergencyContact().equals(otherStudent.getEmergencyContact()) - && this.getFormClass().equals(otherStudent.getFormClass()); + && this.getFormClass().equals(otherStudent.getFormClass()) + && this.getAddress().equals(otherStudent.getAddress()) + && this.getMedicalHistory().equals(otherStudent.getMedicalHistory()); } @Override public String toString() { - return super.toString() - + "; " + return super.toString() + "; " + String.format("Emergency contact: %s", getEmergencyContact()) + "; " + String.format("Form class: %s", getFormClass()) + "; " - + String.format("Gender: %s", getGender()) + + String.format("Address: %s", getAddress()) + "; " + String.format("Medical History: %s", getMedicalHistory()); } diff --git a/src/main/java/seedu/address/model/person/Teacher.java b/src/main/java/seedu/address/model/person/Teacher.java new file mode 100644 index 00000000000..dd62c25e074 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Teacher.java @@ -0,0 +1,70 @@ +package seedu.address.model.person; + +import java.util.Set; + +import seedu.address.model.tag.Tag; + +/** + * Represents a Teacher in the address book. + * Guarantees: details are present and not null, field values are validated, immutable. + */ +public class Teacher extends Person { + + private final OfficeTable officeTable; + + /** + * Constructor for {@code Teacher} + * @param name Name of the teacher + * @param phone Phone number of the teacher + * @param email Email of the teacher + * @param gender Gender of the teacher + * @param involvement Involvement of the teacher + * @param officeTable Office table number of the teacher + * @param tags Tags associated to the teacher + */ + public Teacher(Name name, Phone phone, Email email, Gender gender, Involvement involvement, + OfficeTable officeTable, Set tags) { + super(name, phone, email, gender, involvement, tags); + this.officeTable = officeTable; + } + + /** + * Constructor for {@code Teacher} from person + * + * @param person person to copy the data from + * @param officeTable office table number of the teacher. + */ + public Teacher(Person person, OfficeTable officeTable) { + super(person.getName(), person.getPhone(), person.getEmail(), person.getGender(), person.getInvolvement(), + person.getTags()); + this.officeTable = officeTable; + } + + public OfficeTable getOfficeTable() { + return this.officeTable; + } + + /** + * Returns true if both person are teachers, and have the same identity and data fields. + * This defines a stronger notion of equality between two teachers. + */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof Teacher)) { + return false; + } + + Teacher otherStudent = (Teacher) other; + return super.equals(otherStudent) + && this.getOfficeTable().equals(otherStudent.getOfficeTable()); + } + + @Override + public String toString() { + return super.toString() + "; " + String.format("Office table number: %s", getOfficeTable()); + } +} diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java index 0fee4fe57e6..9c1814660b7 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/person/UniquePersonList.java @@ -27,6 +27,7 @@ public class UniquePersonList implements Iterable { private final ObservableList internalList = FXCollections.observableArrayList(); private final ObservableList internalUnmodifiableList = FXCollections.unmodifiableObservableList(internalList); + private int lastStudentIndex = 0; /** * Returns true if the list contains an equivalent person as the given argument. @@ -45,7 +46,13 @@ public void add(Person toAdd) { if (contains(toAdd)) { throw new DuplicatePersonException(); } - internalList.add(toAdd); + + if (toAdd instanceof Teacher) { + internalList.add(toAdd); + } else if (toAdd instanceof Student) { + internalList.add(lastStudentIndex, toAdd); + lastStudentIndex++; + } } /** @@ -77,6 +84,12 @@ public void remove(Person toRemove) { if (!internalList.remove(toRemove)) { throw new PersonNotFoundException(); } + + if (toRemove instanceof Student) { + lastStudentIndex--; + } + + internalList.remove(toRemove); } public void setPersons(UniquePersonList replacement) { diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index b786c081d34..97994b693ee 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -11,51 +11,57 @@ import seedu.address.model.person.FormClass; import seedu.address.model.person.Gender; import seedu.address.model.person.Involvement; -import seedu.address.model.person.MedicalHistory; import seedu.address.model.person.Name; -import seedu.address.model.person.Person; +import seedu.address.model.person.OfficeTable; import seedu.address.model.person.Phone; import seedu.address.model.person.Student; +import seedu.address.model.person.Teacher; import seedu.address.model.tag.Tag; /** * Contains utility methods for populating {@code AddressBook} with sample data. */ public class SampleDataUtil { - public static Student[] getSamplePersons() { - MedicalHistory emptyMedicalHistory = new MedicalHistory(""); + public static Student[] getSampleStudents() { return new Student[] { new Student(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Address("Blk 30 Geylang Street 29, #06-40"), new Involvement("Math class"), - getTagSet("friends"), new Phone("91934131"), new FormClass("1E1"), new Gender("M"), - emptyMedicalHistory), + new Gender("M"), new Involvement("Class 4A"), + new Address("Blk 30 Geylang Street 29, #06-40"), + new Phone("91934131"), new FormClass("1E1"), getTagSet("monitor")), new Student(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new Involvement("Badminton CCA"), - getTagSet("colleagues", "friends"), new Phone("95614132"), new FormClass("1E4"), - new Gender("F"), emptyMedicalHistory), + new Gender("F"), new Involvement("Math class"), + new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), + new Phone("95614132"), new FormClass("1E4"), getTagSet("rep")), new Student(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), new Involvement("Bio class"), - getTagSet("neighbours"), new Phone("90234134"), new FormClass("3Bio5"), new Gender("F"), - emptyMedicalHistory), - new Student(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), new Involvement("Math class"), - getTagSet("family"), new Phone("81934910"), new FormClass("2Science2"), new Gender("M"), - emptyMedicalHistory), - new Student(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), new Involvement("Math class"), - getTagSet("classmates"), new Phone("94893113"), new FormClass("Sec 3 Pure Geography"), - new Gender("N"), emptyMedicalHistory), - new Student(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Address("Blk 45 Aljunied Street 85, #11-31"), new Involvement("Math class"), - getTagSet("colleagues"), new Phone("91919301"), new FormClass("3 NORMAL 2"), new Gender("N"), - emptyMedicalHistory) + new Gender("F"), new Involvement("Bio class"), + new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), + new Phone("90234134"), new FormClass("3B5"), getTagSet("rep")) }; } + public static Teacher[] getSampleTeachers() { + return new Teacher[] { + new Teacher(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), + new Gender("M"), new Involvement("class 4A Co-Form"), new OfficeTable("1"), + getTagSet("family")), + new Teacher(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), + new Gender("N"), new Involvement("Math HOD"), new OfficeTable("2"), + getTagSet("Colleague")), + new Teacher(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), + new Gender("M"), new Involvement("Math Department"), new OfficeTable("3"), + getTagSet("lunchbuddy")) + }; + } + + + public static ReadOnlyAddressBook getSampleAddressBook() { AddressBook sampleAb = new AddressBook(); - for (Person samplePerson : getSamplePersons()) { - sampleAb.addPerson(samplePerson); + for (Student sampleStudent : getSampleStudents()) { + sampleAb.addPerson(sampleStudent); + } + for (Teacher sampleTeacher : getSampleTeachers()) { + sampleAb.addPerson(sampleTeacher); } return sampleAb; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index 4d2143490da..97c82cc7b82 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -19,6 +19,7 @@ abstract class JsonAdaptedPerson { protected final String name; protected final String phone; protected final String email; + protected final String gender; protected final String involvement; protected final List tagged = new ArrayList<>(); @@ -27,11 +28,13 @@ abstract class JsonAdaptedPerson { */ @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("involvement") String involvement, + @JsonProperty("email") String email, @JsonProperty("gender") String gender, + @JsonProperty("involvement") String involvement, @JsonProperty("tagged") List tagged) { this.name = name; this.phone = phone; this.email = email; + this.gender = gender; this.involvement = involvement; if (tagged != null) { this.tagged.addAll(tagged); @@ -45,6 +48,7 @@ public JsonAdaptedPerson(Person source) { name = source.getName().fullName; phone = source.getPhone().value; email = source.getEmail().value; + gender = source.getGender().value; involvement = source.getInvolvement().involvement; tagged.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) diff --git a/src/main/java/seedu/address/storage/JsonAdaptedStudent.java b/src/main/java/seedu/address/storage/JsonAdaptedStudent.java index 69e1b6c9a1e..ee6f934a6f1 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedStudent.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedStudent.java @@ -30,26 +30,24 @@ class JsonAdaptedStudent extends JsonAdaptedPerson { private final String address; private final String emergencyContact; private final String formClass; - private final String gender; private final String medicalHistory; /** - * Constructs a {@code JsonAdaptedPerson} with the given student details. + * Constructs a {@code JsonAdaptedStudent} with the given student details. */ @JsonCreator public JsonAdaptedStudent(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("address") String address, + @JsonProperty("email") String email, @JsonProperty("gender") String gender, @JsonProperty("involvement") String involvement, - @JsonProperty("tagged") List tagged, + @JsonProperty("address") String address, @JsonProperty("emergencyContact") String emergencyContact, @JsonProperty("formClass") String formClass, - @JsonProperty("gender") String gender, - @JsonProperty("medicalHistory") String medicalHistory) { - super(name, phone, email, involvement, tagged); + @JsonProperty("medicalHistory") String medicalHistory, + @JsonProperty("tagged") List tagged) { + super(name, phone, email, gender, involvement, tagged); this.address = address; this.emergencyContact = emergencyContact; this.formClass = formClass; - this.gender = gender; this.medicalHistory = medicalHistory; } @@ -60,15 +58,14 @@ public JsonAdaptedStudent(Student source) { super(source); this.address = source.getAddress().value; this.emergencyContact = source.getEmergencyContact().value; - this.formClass = source.getFormClass().formClass; - this.gender = source.getGender().gender; + this.formClass = source.getFormClass().value; this.medicalHistory = source.getMedicalHistory().value; } /** - * Converts this Jackson-friendly adapted person object into the model's {@code Person} object. + * Converts this Jackson-friendly adapted student object into the model's {@code Student} object. * - * @throws IllegalValueException if there were any data constraints violated in the adapted person. + * @throws IllegalValueException if there were any data constraints violated in the adapted student. */ @Override public Student toModelType() throws IllegalValueException { @@ -101,13 +98,14 @@ public Student toModelType() throws IllegalValueException { } final Email modelEmail = new Email(email); - if (address == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); + if (gender == null) { + throw new IllegalValueException(String.format( + MISSING_FIELD_MESSAGE_FORMAT, Gender.class.getSimpleName())); } - if (!Address.isValidAddress(address)) { - throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); + if (!Gender.isValidGender(gender)) { + throw new IllegalValueException(Gender.MESSAGE_CONSTRAINTS); } - final Address modelAddress = new Address(address); + final Gender modelGender = new Gender(gender); if (involvement == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, @@ -118,7 +116,14 @@ public Student toModelType() throws IllegalValueException { } final Involvement modelInvolvement = new Involvement(involvement); - final Set modelTags = new HashSet<>(studentTags); + if (address == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); + } + if (!Address.isValidAddress(address)) { + throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); + } + final Address modelAddress = new Address(address); + if (emergencyContact == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); } @@ -126,6 +131,7 @@ public Student toModelType() throws IllegalValueException { throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); } final Phone modelEmergencyContact = new Phone(emergencyContact); + if (formClass == null) { throw new IllegalValueException(String.format( MISSING_FIELD_MESSAGE_FORMAT, FormClass.class.getSimpleName())); @@ -135,22 +141,15 @@ public Student toModelType() throws IllegalValueException { } final FormClass modelFormClass = new FormClass(formClass); - if (gender == null) { - throw new IllegalValueException(String.format( - MISSING_FIELD_MESSAGE_FORMAT, Gender.class.getSimpleName())); - } - if (!Gender.isValidGender(gender)) { - throw new IllegalValueException(Gender.MESSAGE_CONSTRAINTS); - } - final Gender modelGender = new Gender(gender); - if (medicalHistory == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, - MedicalHistory.class.getSimpleName())); + MedicalHistory.class.getSimpleName())); } final MedicalHistory modelMedicalHistory = new MedicalHistory(medicalHistory); - return new Student(modelName, modelPhone, modelEmail, modelAddress, modelInvolvement, - modelTags, modelEmergencyContact, modelFormClass, modelGender, modelMedicalHistory); + + final Set modelTags = new HashSet<>(studentTags); + return new Student(modelName, modelPhone, modelEmail, modelGender, modelInvolvement, + modelAddress, modelEmergencyContact, modelFormClass, modelTags, modelMedicalHistory); } } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedTeacher.java b/src/main/java/seedu/address/storage/JsonAdaptedTeacher.java new file mode 100644 index 00000000000..8d3e7083b50 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedTeacher.java @@ -0,0 +1,118 @@ +package seedu.address.storage; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.person.Email; +import seedu.address.model.person.Gender; +import seedu.address.model.person.Involvement; +import seedu.address.model.person.Name; +import seedu.address.model.person.OfficeTable; +import seedu.address.model.person.Phone; +import seedu.address.model.person.Teacher; +import seedu.address.model.tag.Tag; + +/** + * Jackson-friendly version of {@link Teacher}. + */ +class JsonAdaptedTeacher extends JsonAdaptedPerson { + + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Teacher's %s field is missing!"; + + private final String officeTable; + + /** + * Constructs a {@code JsonAdaptedTeacher} with the given teacher details. + */ + @JsonCreator + public JsonAdaptedTeacher(@JsonProperty("name") String name, @JsonProperty("phone") String phone, + @JsonProperty("email") String email, @JsonProperty("gender") String gender, + @JsonProperty("involvement") String involvement, + @JsonProperty("officeTable") String officeTable, + @JsonProperty("tagged") List tagged) { + super(name, phone, email, gender, involvement, tagged); + this.officeTable = officeTable; + } + + /** + * Converts a given {@code Teacher} into this class for Jackson use. + */ + public JsonAdaptedTeacher(Teacher source) { + super(source); + this.officeTable = source.getOfficeTable().value; + } + + /** + * Converts this Jackson-friendly adapted teacher object into the model's {@code Teacher} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted teacher. + */ + @Override + public Teacher toModelType() throws IllegalValueException { + final List teacherTags = new ArrayList<>(); + for (JsonAdaptedTag tag : tagged) { + teacherTags.add(tag.toModelType()); + } + + if (name == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); + } + if (!Name.isValidName(name)) { + throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS); + } + final Name modelName = new Name(name); + + if (phone == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); + } + if (!Phone.isValidPhone(phone)) { + throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); + } + final Phone modelPhone = new Phone(phone); + + if (email == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName())); + } + if (!Email.isValidEmail(email)) { + throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); + } + final Email modelEmail = new Email(email); + + if (gender == null) { + throw new IllegalValueException(String.format( + MISSING_FIELD_MESSAGE_FORMAT, Gender.class.getSimpleName())); + } + if (!Gender.isValidGender(gender)) { + throw new IllegalValueException(Gender.MESSAGE_CONSTRAINTS); + } + final Gender modelGender = new Gender(gender); + + if (involvement == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + Involvement.class.getSimpleName())); + } + if (!Involvement.isValidInvolvement(involvement)) { + throw new IllegalValueException(Involvement.MESSAGE_CONSTRAINTS); + } + final Involvement modelInvolvement = new Involvement(involvement); + + if (officeTable == null) { + throw new IllegalValueException(String.format( + MISSING_FIELD_MESSAGE_FORMAT, OfficeTable.class.getSimpleName())); + } + if (!OfficeTable.isValidTable(officeTable)) { + throw new IllegalValueException(OfficeTable.MESSAGE_CONSTRAINTS); + } + final OfficeTable modelOfficeTable = new OfficeTable(officeTable); + + final Set modelTags = new HashSet<>(teacherTags); + return new Teacher(modelName, modelPhone, modelEmail, modelGender, modelInvolvement, + modelOfficeTable, modelTags); + } +} diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index 6e3778feb9d..9c0ac63002f 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -12,6 +12,7 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.person.Student; +import seedu.address.model.person.Teacher; /** * An Immutable AddressBook that is serializable to JSON format. @@ -19,16 +20,20 @@ @JsonRootName(value = "addressbook") class JsonSerializableAddressBook { - public static final String MESSAGE_DUPLICATE_PERSON = "Students list contains duplicate student(s)."; + public static final String MESSAGE_DUPLICATE_STUDENT = "Students list contains duplicate student(s)."; + public static final String MESSAGE_DUPLICATE_TEACHER = "Teachers list contains duplicate teacher(s)."; private final List students = new ArrayList<>(); + private final List teachers = new ArrayList<>(); /** - * Constructs a {@code JsonSerializableAddressBook} with the given students. + * Constructs a {@code JsonSerializableAddressBook} with the given students and teachers. */ @JsonCreator - public JsonSerializableAddressBook(@JsonProperty("students") List persons) { - this.students.addAll(persons); + public JsonSerializableAddressBook(@JsonProperty("students") List students, + @JsonProperty("teachers") List teachers) { + this.students.addAll(students); + this.teachers.addAll(teachers); } /** @@ -38,7 +43,12 @@ public JsonSerializableAddressBook(@JsonProperty("students") List person instanceof Student) .map(person -> new JsonAdaptedStudent((Student) person)).collect(Collectors.toList())); + + teachers.addAll(source.getPersonList().stream() + .filter(person -> person instanceof Teacher) + .map(person -> new JsonAdaptedTeacher((Teacher) person)).collect(Collectors.toList())); } /** @@ -51,11 +61,17 @@ public AddressBook toModelType() throws IllegalValueException { for (JsonAdaptedStudent jsonAdaptedStudent : students) { Student student = jsonAdaptedStudent.toModelType(); if (addressBook.hasPerson(student)) { - throw new IllegalValueException(MESSAGE_DUPLICATE_PERSON); + throw new IllegalValueException(MESSAGE_DUPLICATE_STUDENT); } addressBook.addPerson(student); } + for (JsonAdaptedTeacher jsonAdaptedTeacher : teachers) { + Teacher teacher = jsonAdaptedTeacher.toModelType(); + if (addressBook.hasPerson(teacher)) { + throw new IllegalValueException(MESSAGE_DUPLICATE_TEACHER); + } + addressBook.addPerson(teacher); + } return addressBook; } - } diff --git a/src/main/java/seedu/address/ui/StudentCard.java b/src/main/java/seedu/address/ui/StudentCard.java index 207271ff20d..6f1fe98c362 100644 --- a/src/main/java/seedu/address/ui/StudentCard.java +++ b/src/main/java/seedu/address/ui/StudentCard.java @@ -62,14 +62,14 @@ public StudentCard(Student student, int displayedIndex) { phone.setText(student.getPhone().value); address.setText(student.getAddress().value); email.setText(student.getEmail().value); - formClass.setText(student.getFormClass().formClass); - gender.setText(student.getGender().gender); + formClass.setText(student.getFormClass().value); + gender.setText(student.getGender().value); medicalHistory.setText(student.getMedicalHistory().value); involvement.setText(student.getInvolvement().involvement); - student.getTags().stream() - .sorted(Comparator.comparing(tag -> tag.tagName)) - .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); emergencyContact.setText(student.getEmergencyContact().value); + student.getTags().stream() + .sorted(Comparator.comparing(tag -> tag.tagName)) + .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); } @Override diff --git a/src/test/data/JsonAddressBookStorageTest/invalidAndValidPersonAddressBook.json b/src/test/data/JsonAddressBookStorageTest/invalidAndValidPersonAddressBook.json index 20dc3ae6e2e..bccb9bd2eaf 100644 --- a/src/test/data/JsonAddressBookStorageTest/invalidAndValidPersonAddressBook.json +++ b/src/test/data/JsonAddressBookStorageTest/invalidAndValidPersonAddressBook.json @@ -3,19 +3,36 @@ "name": "Valid Student", "phone": "9482424", "email": "hans@example.com", - "address": "4th street", + "gender" : "M", "involvement": "Math class", + "address": "4th street", "emergencyContact" : "95614132", "formClass" : "4E1", - "gender" : "M" + "medicalHistory" : "" }, { "name": "Student With Invalid Phone Field", "phone": "948asdf2424", "email": "hans@example.com", - "address": "4th street", + "gender" : "N", "involvement": "Math class", + "address": "4th street", "emergencyContact" : "95614132", "formClass" : "4E1", - "gender" : "N" + "medicalHistory" : "" + } ], + "teachers": [ { + "name": "Valid Teacher", + "phone": "9482424", + "email": "hans@example.com", + "gender" : "M", + "involvement": "Math HOD", + "officeTable": "1" + }, { + "name": "Teacher With Invalid Phone Field", + "phone": "948asdf2424", + "email": "hans@example.com", + "gender" : "N", + "involvement": "Math class", + "officeTable": "2" } ] } diff --git a/src/test/data/JsonAddressBookStorageTest/invalidPersonAddressBook.json b/src/test/data/JsonAddressBookStorageTest/invalidPersonAddressBook.json index f06ec550061..b291af6a350 100644 --- a/src/test/data/JsonAddressBookStorageTest/invalidPersonAddressBook.json +++ b/src/test/data/JsonAddressBookStorageTest/invalidPersonAddressBook.json @@ -3,10 +3,19 @@ "name": "Student with invalid name field: Ha!ns Mu@ster", "phone": "9482424", "email": "hans@example.com", - "address": "4th street", + "gender" : "M", "involvement": "Math class", + "address": "4th street", "emergencyContact" : "95614132", "formClass" : "4E1", - "gender" : "M" + "medicalHistory" : "" + } ], + "teachers": [ { + "name": "Teacher with invalid name field: Ha!ns Mu@ster", + "phone": "9482424", + "email": "hans@example.com", + "gender" : "M", + "involvement": "Math class", + "officeTable": "1" } ] } diff --git a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json index 1796b0517e8..c501ab758bc 100644 --- a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json @@ -3,22 +3,38 @@ "name": "Alice Pauline", "phone": "94351253", "email": "alice@example.com", - "address": "123, Jurong West Ave 6, #08-111", + "gender": "F", "involvement": "Math class", - "tagged": [ "friends" ], + "address": "123, Jurong West Ave 6, #08-111", "emergencyContact" : "95614132", "formClass" : "4E1", - "gender": "F", - "medicalHistory": "" + "medicalHistory": "", + "tagged": [ "friends" ] }, { "name": "Alice Pauline", "phone": "94351253", "email": "pauline@example.com", - "address": "123, Jurong West Ave 6, #08-111", + "gender": "F", "involvement": "Math class", + "address": "123, Jurong West Ave 6, #08-111", "emergencyContact" : "95614132", "formClass" : "4E1", + "medicalHistory" : "" + } ], + "teachers": [ { + "name": "Alice Pauline", + "phone": "94351253", + "email": "alice@example.com", + "gender": "F", + "involvement": "Math HOD", + "officeTable": "1", + "tagged": [ "Colleague" ] + }, { + "name": "Alice Pauline", + "phone": "94351253", + "email": "pauline@example.com", "gender": "F", - "medicalHistory": "" + "involvement": "Math HOD", + "officeTable": "1" } ] } diff --git a/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json index f90e4e336d4..496d9542ae1 100644 --- a/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json @@ -3,10 +3,18 @@ "name": "Hans Muster", "phone": "9482424", "email": "invalid@email!3e", - "address": "4th street", + "gender" : "N", "involvement": "Math class", + "address": "4th street", "emergencyContact" : "95614132", - "formClass" : "4E1", - "gender" : "N" + "formClass" : "4E1" + } ], + "teachers": [ { + "name": "Hans Muster", + "phone": "9482424", + "email": "invalid@email!3e", + "gender" : "N", + "involvement": "Math class", + "officeTable": "1" } ] } diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json index 8704f96a82c..8f5140327c8 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json @@ -4,78 +4,135 @@ "name" : "Alice Pauline", "phone" : "94351253", "email" : "alice@example.com", - "address" : "123, Jurong West Ave 6, #08-111", + "gender" : "F", "involvement": "Math class", - "tagged" : [ "friends" ], + "address" : "123, Jurong West Ave 6, #08-111", "emergencyContact" : "95614132", "formClass" : "4N1", - "gender" : "F", - "medicalHistory" : "ADHD" + "medicalHistory" : "ADHD", + "tagged" : [ "friends" ] }, { "name" : "Benson Meier", "phone" : "98765432", "email" : "johnd@example.com", - "address" : "311, Clementi Ave 2, #02-25", + "gender" : "M", "involvement": "Math class", - "tagged" : [ "owesMoney", "friends" ], + "address" : "311, Clementi Ave 2, #02-25", "emergencyContact" : "91939100", "formClass" : "3E3", - "gender" : "M", - "medicalHistory" : "Autistic" + "medicalHistory" : "Autistic", + "tagged" : [ "owesMoney", "friends" ] }, { "name" : "Carl Kurz", "phone" : "95352563", "email" : "heinz@example.com", - "address" : "wall street", + "gender" : "M", "involvement": "Form class", - "tagged" : [ ], + "address" : "wall street", "emergencyContact" : "48190514", "formClass" : "4E2", - "gender" : "M", - "medicalHistory" : "" + "medicalHistory" : "", + "tagged" : [ ] }, { "name" : "Daniel Meier", "phone" : "87652533", "email" : "cornelia@example.com", - "address" : "10th street", + "gender" : "M", "involvement": "Form class", - "tagged" : [ "friends" ], + "address" : "10th street", "emergencyContact" : "58141834", "formClass" : "4E2", - "gender" : "M", - "medicalHistory" : "" + "medicalHistory" : "", + "tagged" : [ "friends" ] }, { "name" : "Elle Meyer", "phone" : "9482224", "email" : "werner@example.com", - "address" : "michegan ave", + "gender" : "F", "involvement": "Form class", - "tagged" : [ ], + "address" : "michegan ave", "emergencyContact" : "92329700", "formClass" : "4E2", - "gender" : "F", - "medicalHistory" : "" + "medicalHistory" : "", + "tagged" : [ ] }, { "name" : "Fiona Kunz", "phone" : "9482427", "email" : "lydia@example.com", - "address" : "little tokyo", + "gender" : "F", "involvement": "English class", - "tagged" : [ ], - "emergencyContact" : "99749087", + "address" : "little tokyo", + "emergencyContact" : "580947918074907019749087", "formClass" : "1T1", - "gender" : "F", - "medicalHistory" : "" + "medicalHistory" : "", + "tagged" : [ ] }, { "name" : "George Best", "phone" : "9482442", "email" : "anna@example.com", - "address" : "4th street", + "gender" : "M", "involvement": "English class", - "tagged" : [ ], + "address" : "4th street", "emergencyContact" : "84041748901", "formClass" : "1T1", + "medicalHistory" : "", + "tagged" : [ ] + } ], + "teachers" : [ { + "name" : "Ali Paula", + "phone" : "94351253", + "email" : "ali@example.com", + "gender" : "F", + "involvement": "Math Dept", + "officeTable": "1", + "tagged" : [ "friends" ] + }, { + "name" : "Ben ten", + "phone" : "98765432", + "email" : "bm1@example.com", + "gender" : "M", + "involvement": "Math Dept", + "officeTable": "2", + "tagged" : [ "owesMoney", "friends" ] + }, { + "name" : "Car goh", + "phone" : "95352563", + "email" : "ck@example.com", + "gender" : "M", + "involvement": "4A Co-Form", + "officeTable": "3", + "tagged" : [ ] + }, { + "name" : "Dan Mei", + "phone" : "87652533", + "email" : "dm2@example.com", + "gender" : "M", + "involvement": "4A Co-Form", + "officeTable": "4", + "tagged" : [ "friends" ] + }, { + "name" : "El Mey", + "phone" : "9482224", + "email" : "em@example.com", + "gender" : "F", + "involvement": "Math Dept", + "officeTable": "5", + "tagged" : [ ] + }, { + "name" : "Fio runz", + "phone" : "9482427", + "email" : "fk@example.com", + "gender" : "F", + "involvement": "Math Dept", + "officeTable": "6", + "tagged" : [ ] + }, { + "name" : "Geo Good", + "phone" : "9482442", + "email" : "best@example.com", "gender" : "M", - "medicalHistory" : "" + "involvement": "Math HOD", + "officeTable": "7", + "tagged" : [ ] } ] } diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index dbb27cd29e0..58b3ed870a4 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -12,7 +12,7 @@ import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalStudents.AMY; +import static seedu.address.testutil.TypicalPersons.AMY; import java.io.IOException; import java.nio.file.Path; diff --git a/src/test/java/seedu/address/logic/commands/ClearCommandTest.java b/src/test/java/seedu/address/logic/commands/ClearCommandTest.java index 2020fcec74b..80d9110c03a 100644 --- a/src/test/java/seedu/address/logic/commands/ClearCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ClearCommandTest.java @@ -1,7 +1,7 @@ package seedu.address.logic.commands; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import org.junit.jupiter.api.Test; diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 52759ddedc7..6eee2569c09 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -9,6 +9,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; import static seedu.address.logic.parser.CliSyntax.PREFIX_INVOLVEMENT; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_OFFICE_TABLE; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.testutil.Assert.assertThrows; @@ -19,79 +20,106 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.descriptors.EditStudentDescriptor; +import seedu.address.logic.commands.descriptors.EditTeacherDescriptor; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.AddressBook; import seedu.address.model.Model; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; import seedu.address.testutil.EditStudentDescriptorBuilder; +import seedu.address.testutil.EditTeacherDescriptorBuilder; /** * Contains helper methods for testing commands. */ public class CommandTestUtil { + // students public static final String VALID_NAME_AMY = "Amy Bee"; public static final String VALID_NAME_BOB = "Bob Choo"; + public static final String VALID_NAME_CHO = "Cho li"; + public static final String VALID_NAME_DEE = "Dee ku"; public static final String VALID_PHONE_AMY = "11111111"; public static final String VALID_PHONE_BOB = "22222222"; + public static final String VALID_PHONE_CHO = "33333333"; + public static final String VALID_PHONE_DEE = "44444444"; public static final String VALID_EMAIL_AMY = "amy@example.com"; public static final String VALID_EMAIL_BOB = "bob@example.com"; + public static final String VALID_EMAIL_CHO = "cho@example.com"; + public static final String VALID_EMAIL_DEE = "dee@example.com"; public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1"; public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3"; - public static final String VALID_TAG_HUSBAND = "husband"; - public static final String VALID_TAG_FRIEND = "friend"; + public static final String VALID_TAG_MONITOR = "monitor"; + public static final String VALID_TAG_REP = "rep"; public static final String VALID_EMERGENCY_CONTACT_AMY = "914134304141"; public static final String VALID_EMERGENCY_CONTACT_BOB = "91304141"; public static final String VALID_INVOLVEMENT_AMY = "Bio class"; - public static final String VALID_INVOLVEMENT_BOB = "Math class"; + public static final String VALID_INVOLVEMENT_BOB = "Dance"; + public static final String VALID_INVOLVEMENT_CHO = "PE Dept"; + public static final String VALID_INVOLVEMENT_DEE = "4A Co-Form"; public static final String VALID_FORM_CLASS_AMY = "4E1"; public static final String VALID_FORM_CLASS_BOB = "2E1"; public static final String VALID_GENDER_AMY = "F"; public static final String VALID_GENDER_BOB = "M"; - public static final String VALID_GENDER_NON_BINARY = "N"; + public static final String VALID_GENDER_CHO = "F"; + public static final String VALID_GENDER_DEE = "N"; + public static final String VALID_OFFICE_TABLE_CHO = "4"; + public static final String VALID_OFFICE_TABLE_DEE = "12"; public static final String VALID_MEDICAL_HISTORY_AMY = "ADHD"; public static final String VALID_MEDICAL_HISTORY_BOB = "Autistic"; - public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY; public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB; + public static final String NAME_DESC_CHO = " " + PREFIX_NAME + VALID_NAME_CHO; + public static final String NAME_DESC_DEE = " " + PREFIX_NAME + VALID_NAME_DEE; public static final String PHONE_DESC_AMY = " " + PREFIX_PHONE + VALID_PHONE_AMY; public static final String PHONE_DESC_BOB = " " + PREFIX_PHONE + VALID_PHONE_BOB; + public static final String PHONE_DESC_CHO = " " + PREFIX_PHONE + VALID_PHONE_CHO; + public static final String PHONE_DESC_DEE = " " + PREFIX_PHONE + VALID_PHONE_DEE; public static final String EMAIL_DESC_AMY = " " + PREFIX_EMAIL + VALID_EMAIL_AMY; public static final String EMAIL_DESC_BOB = " " + PREFIX_EMAIL + VALID_EMAIL_BOB; + public static final String EMAIL_DESC_CHO = " " + PREFIX_EMAIL + VALID_EMAIL_CHO; + public static final String EMAIL_DESC_DEE = " " + PREFIX_EMAIL + VALID_EMAIL_DEE; + public static final String GENDER_DESC_AMY = " " + PREFIX_GENDER + VALID_GENDER_AMY; + public static final String GENDER_DESC_BOB = " " + PREFIX_GENDER + VALID_GENDER_BOB; + public static final String GENDER_DESC_CHO = " " + PREFIX_GENDER + VALID_GENDER_CHO; + public static final String GENDER_DESC_DEE = " " + PREFIX_GENDER + VALID_GENDER_DEE; + public static final String INVOLVEMENT_DESC_AMY = " " + PREFIX_INVOLVEMENT + VALID_INVOLVEMENT_AMY; + public static final String INVOLVEMENT_DESC_BOB = " " + PREFIX_INVOLVEMENT + VALID_INVOLVEMENT_BOB; + public static final String INVOLVEMENT_DESC_CHO = " " + PREFIX_INVOLVEMENT + VALID_INVOLVEMENT_CHO; + public static final String INVOLVEMENT_DESC_DEE = " " + PREFIX_INVOLVEMENT + VALID_INVOLVEMENT_DEE; public static final String ADDRESS_DESC_AMY = " " + PREFIX_ADDRESS + VALID_ADDRESS_AMY; + public static final String ADDRESS_DESC_BOB = " " + PREFIX_ADDRESS + VALID_ADDRESS_BOB; public static final String EMERGENCY_CONTACT_DESC_AMY = " " + PREFIX_EMERGENCY_CONTACT - + VALID_EMERGENCY_CONTACT_AMY; + + VALID_EMERGENCY_CONTACT_AMY; public static final String EMERGENCY_CONTACT_DESC_BOB = - " " + PREFIX_EMERGENCY_CONTACT + VALID_EMERGENCY_CONTACT_BOB; - public static final String ADDRESS_DESC_BOB = " " + PREFIX_ADDRESS + VALID_ADDRESS_BOB; - public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND; - public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND; - public static final String INVOLVEMENT_DESC_AMY = " " + PREFIX_INVOLVEMENT + VALID_INVOLVEMENT_AMY; - public static final String INVOLVEMENT_DESC_BOB = " " + PREFIX_INVOLVEMENT + VALID_INVOLVEMENT_BOB; + " " + PREFIX_EMERGENCY_CONTACT + VALID_EMERGENCY_CONTACT_BOB; + public static final String TAG_DESC_REP = " " + PREFIX_TAG + VALID_TAG_REP; + public static final String TAG_DESC_MONITOR = " " + PREFIX_TAG + VALID_TAG_MONITOR; public static final String FORM_CLASS_DESC_AMY = " " + PREFIX_FORM_CLASS + VALID_FORM_CLASS_AMY; public static final String FORM_CLASS_DESC_BOB = " " + PREFIX_FORM_CLASS + VALID_FORM_CLASS_BOB; - public static final String GENDER_DESC_AMY = " " + PREFIX_GENDER + VALID_GENDER_AMY; - public static final String GENDER_DESC_BOB = " " + PREFIX_GENDER + VALID_GENDER_BOB; - public static final String GENDER_DESC_NON_BINARY = " " + PREFIX_GENDER + VALID_GENDER_NON_BINARY; + public static final String OFFICE_TABLE_DESC_CHO = " " + PREFIX_OFFICE_TABLE + VALID_OFFICE_TABLE_CHO; + public static final String OFFICE_TABLE_DESC_DEE = " " + PREFIX_OFFICE_TABLE + VALID_OFFICE_TABLE_DEE; public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags - public static final String INVALID_EMERGENCY_CONTACT_DESC = " " + PREFIX_PHONE + "911232a"; // 'a' not allowed in - // phones + public static final String INVALID_EMERGENCY_CONTACT_DESC = " " + PREFIX_EMERGENCY_CONTACT + "911232a"; // 'a' not + // allowed in phones public static final String INVALID_INVOLVEMENT_DESC = " " + PREFIX_INVOLVEMENT; // empty string not allowed public static final String INVALID_FORM_CLASS_DESC = " " + PREFIX_FORM_CLASS + "4*1"; // '*' not allowed in form class public static final String INVALID_GENDER_DESC = " " + PREFIX_GENDER + "d"; //Anything other than M/F/N (not allow) - + public static final String INVALID_OFFICE_TABLE_DESC = " " + PREFIX_OFFICE_TABLE + "12a"; // 'a' not allowed in + // office table number public static final String PREAMBLE_WHITESPACE = "\t \r \n"; public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble"; public static final EditStudentDescriptor DESC_AMY; public static final EditStudentDescriptor DESC_BOB; + public static final EditTeacherDescriptor DESC_CHO; + public static final EditTeacherDescriptor DESC_DEE; static { DESC_AMY = new EditStudentDescriptorBuilder() @@ -102,7 +130,7 @@ public class CommandTestUtil { .withEmail(VALID_EMAIL_AMY) .withAddress(VALID_ADDRESS_AMY) .withInvolvement(VALID_INVOLVEMENT_AMY) - .withTags(VALID_TAG_FRIEND) + .withTags(VALID_TAG_REP) .withGender(VALID_GENDER_AMY) .build(); DESC_BOB = new EditStudentDescriptorBuilder() @@ -113,9 +141,27 @@ public class CommandTestUtil { .withEmail(VALID_EMAIL_BOB) .withAddress(VALID_ADDRESS_BOB) .withInvolvement(VALID_INVOLVEMENT_AMY) - .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND) + .withTags(VALID_TAG_MONITOR, VALID_TAG_REP) .withGender(VALID_GENDER_BOB) .build(); + DESC_CHO = new EditTeacherDescriptorBuilder() + .withName(VALID_NAME_CHO) + .withPhone(VALID_PHONE_CHO) + .withEmail(VALID_EMAIL_CHO) + .withGender(VALID_GENDER_CHO) + .withInvolvement(VALID_INVOLVEMENT_CHO) + .withOfficeTable(VALID_OFFICE_TABLE_CHO) + .withTags(VALID_TAG_REP, VALID_TAG_MONITOR) + .build(); + DESC_DEE = new EditTeacherDescriptorBuilder() + .withName(VALID_NAME_DEE) + .withPhone(VALID_PHONE_DEE) + .withEmail(VALID_EMAIL_DEE) + .withGender(VALID_GENDER_DEE) + .withInvolvement(VALID_INVOLVEMENT_DEE) + .withOfficeTable(VALID_OFFICE_TABLE_DEE) + .withTags(VALID_TAG_REP, VALID_TAG_MONITOR) + .build(); } /** diff --git a/src/test/java/seedu/address/logic/commands/CopyCommandTest.java b/src/test/java/seedu/address/logic/commands/CopyCommandTest.java index 74426956916..13acc2727c8 100644 --- a/src/test/java/seedu/address/logic/commands/CopyCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/CopyCommandTest.java @@ -2,7 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.util.ArrayList; import java.util.List; diff --git a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java index cd62e3500df..4c2f6e8caca 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java @@ -5,9 +5,9 @@ import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; -import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_STUDENT; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import org.junit.jupiter.api.Test; @@ -28,8 +28,8 @@ public class DeleteCommandTest { @Test public void execute_validIndexUnfilteredList_success() { - Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON); + Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_STUDENT.getZeroBased()); + DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_STUDENT); String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, personToDelete); @@ -49,10 +49,10 @@ public void execute_invalidIndexUnfilteredList_throwsCommandException() { @Test public void execute_validIndexFilteredList_success() { - showPersonAtIndex(model, INDEX_FIRST_PERSON); + showPersonAtIndex(model, INDEX_FIRST_STUDENT); - Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON); + Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_STUDENT.getZeroBased()); + DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_STUDENT); String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, personToDelete); @@ -65,9 +65,9 @@ public void execute_validIndexFilteredList_success() { @Test public void execute_invalidIndexFilteredList_throwsCommandException() { - showPersonAtIndex(model, INDEX_FIRST_PERSON); + showPersonAtIndex(model, INDEX_FIRST_STUDENT); - Index outOfBoundIndex = INDEX_SECOND_PERSON; + Index outOfBoundIndex = INDEX_SECOND_STUDENT; // ensures that outOfBoundIndex is still in bounds of address book list assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getPersonList().size()); @@ -78,14 +78,14 @@ public void execute_invalidIndexFilteredList_throwsCommandException() { @Test public void equals() { - DeleteCommand deleteFirstCommand = new DeleteCommand(INDEX_FIRST_PERSON); - DeleteCommand deleteSecondCommand = new DeleteCommand(INDEX_SECOND_PERSON); + DeleteCommand deleteFirstCommand = new DeleteCommand(INDEX_FIRST_STUDENT); + DeleteCommand deleteSecondCommand = new DeleteCommand(INDEX_SECOND_STUDENT); // same object -> returns true assertTrue(deleteFirstCommand.equals(deleteFirstCommand)); // same values -> returns true - DeleteCommand deleteFirstCommandCopy = new DeleteCommand(INDEX_FIRST_PERSON); + DeleteCommand deleteFirstCommandCopy = new DeleteCommand(INDEX_FIRST_STUDENT); assertTrue(deleteFirstCommand.equals(deleteFirstCommandCopy)); // different types -> returns false diff --git a/src/test/java/seedu/address/logic/commands/EditStudentCommandTest.java b/src/test/java/seedu/address/logic/commands/EditStudentCommandTest.java deleted file mode 100644 index cea503118b4..00000000000 --- a/src/test/java/seedu/address/logic/commands/EditStudentCommandTest.java +++ /dev/null @@ -1,161 +0,0 @@ -package seedu.address.logic.commands; - -import static org.junit.jupiter.api.Assertions.assertFalse; -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_NAME_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; -import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; -import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; -import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; - -import org.junit.jupiter.api.Test; - -import seedu.address.commons.core.Messages; -import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.descriptors.EditStudentDescriptor; -import seedu.address.logic.commands.student.EditStudentCommand; -import seedu.address.model.AddressBook; -import seedu.address.model.Model; -import seedu.address.model.ModelManager; -import seedu.address.model.UserPrefs; -import seedu.address.model.person.Person; -import seedu.address.model.person.Student; -import seedu.address.testutil.EditStudentDescriptorBuilder; -import seedu.address.testutil.StudentBuilder; - -/** - * Contains integration tests (interaction with the Model) and unit tests for EditCommand. - */ -public class EditStudentCommandTest { - - private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); - - @Test - public void execute_someFieldsSpecifiedUnfilteredList_success() { - Index indexLastPerson = Index.fromOneBased(model.getFilteredPersonList().size()); - Person lastPerson = model.getFilteredPersonList().get(indexLastPerson.getZeroBased()); - - StudentBuilder personInList = new StudentBuilder((Student) lastPerson); - Student editedPerson = personInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB) - .withTags(VALID_TAG_HUSBAND).build(); - - EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB) - .withPhone(VALID_PHONE_BOB).withTags(VALID_TAG_HUSBAND).build(); - EditStudentCommand editCommand = new EditStudentCommand(indexLastPerson, descriptor); - - String expectedMessage = String.format(EditStudentCommand.MESSAGE_EDIT_PERSON_SUCCESS, editedPerson); - - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); - expectedModel.setPerson(lastPerson, editedPerson); - - assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); - } - - @Test - public void execute_noFieldSpecifiedUnfilteredList_success() { - EditStudentCommand editCommand = new EditStudentCommand(INDEX_FIRST_PERSON, new EditStudentDescriptor()); - Person editedPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - - String expectedMessage = String.format(EditStudentCommand.MESSAGE_EDIT_PERSON_SUCCESS, editedPerson); - - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); - - assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); - } - - @Test - public void execute_filteredList_success() { - showPersonAtIndex(model, INDEX_FIRST_PERSON); - - Person personInFilteredList = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - Person editedPerson = new StudentBuilder((Student) personInFilteredList).withName(VALID_NAME_BOB).build(); - EditStudentCommand editCommand = new EditStudentCommand(INDEX_FIRST_PERSON, - new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB).build()); - - String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, editedPerson); - - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); - expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson); - - assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); - } - - @Test - public void execute_duplicatePersonUnfilteredList_failure() { - Student firstPerson = (Student) model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder(firstPerson).build(); - EditStudentCommand editCommand = new EditStudentCommand(INDEX_SECOND_PERSON, descriptor); - - assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON); - } - - @Test - public void execute_duplicatePersonFilteredList_failure() { - showPersonAtIndex(model, INDEX_FIRST_PERSON); - - // edit person in filtered list into a duplicate in address book - Student personInList = (Student) model.getAddressBook().getPersonList().get(INDEX_SECOND_PERSON.getZeroBased()); - EditStudentCommand editCommand = new EditStudentCommand(INDEX_FIRST_PERSON, - new EditStudentDescriptorBuilder(personInList).build()); - - assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON); - } - - @Test - public void execute_invalidPersonIndexUnfilteredList_failure() { - Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); - EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB).build(); - EditStudentCommand editCommand = new EditStudentCommand(outOfBoundIndex, descriptor); - - assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); - } - - /** - * Edit filtered list where index is larger than size of filtered list, - * but smaller than size of address book - */ - @Test - public void execute_invalidPersonIndexFilteredList_failure() { - showPersonAtIndex(model, INDEX_FIRST_PERSON); - Index outOfBoundIndex = INDEX_SECOND_PERSON; - // ensures that outOfBoundIndex is still in bounds of address book list - assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getPersonList().size()); - - EditStudentCommand editCommand = new EditStudentCommand(outOfBoundIndex, - new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB).build()); - - assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); - } - - @Test - public void equals() { - final EditCommand standardCommand = new EditStudentCommand(INDEX_FIRST_PERSON, DESC_AMY); - - // same values -> returns true - EditStudentDescriptor copyDescriptor = new EditStudentDescriptor(DESC_AMY); - EditCommand commandWithSameValues = new EditStudentCommand(INDEX_FIRST_PERSON, copyDescriptor); - assertTrue(standardCommand.equals(commandWithSameValues)); - - // same object -> returns true - assertTrue(standardCommand.equals(standardCommand)); - - // null -> returns false - assertFalse(standardCommand.equals(null)); - - // different types -> returns false - assertFalse(standardCommand.equals(new ClearCommand())); - - // different index -> returns false - assertFalse(standardCommand.equals(new EditStudentCommand(INDEX_SECOND_PERSON, DESC_AMY))); - - // different descriptor -> returns false - assertFalse(standardCommand.equals(new EditStudentCommand(INDEX_FIRST_PERSON, DESC_BOB))); - } - -} diff --git a/src/test/java/seedu/address/logic/commands/FilterCommandTest.java b/src/test/java/seedu/address/logic/commands/FilterCommandTest.java index e72a72e6e3d..2ff1b446c9d 100644 --- a/src/test/java/seedu/address/logic/commands/FilterCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FilterCommandTest.java @@ -5,14 +5,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.commons.core.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.testutil.TypicalStudents.ALICE; -import static seedu.address.testutil.TypicalStudents.BENSON; -import static seedu.address.testutil.TypicalStudents.CARL; -import static seedu.address.testutil.TypicalStudents.DANIEL; -import static seedu.address.testutil.TypicalStudents.ELLE; -import static seedu.address.testutil.TypicalStudents.FIONA; -import static seedu.address.testutil.TypicalStudents.GEORGE; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.BENSON; +import static seedu.address.testutil.TypicalPersons.CARL; +import static seedu.address.testutil.TypicalPersons.DANIEL; +import static seedu.address.testutil.TypicalPersons.ELLE; +import static seedu.address.testutil.TypicalPersons.FIONA; +import static seedu.address.testutil.TypicalPersons.GEORGE; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.util.Arrays; import java.util.Collections; diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index b4181daab6d..9b15db28bbb 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -5,10 +5,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.commons.core.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.testutil.TypicalStudents.CARL; -import static seedu.address.testutil.TypicalStudents.ELLE; -import static seedu.address.testutil.TypicalStudents.FIONA; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalPersons.CARL; +import static seedu.address.testutil.TypicalPersons.ELLE; +import static seedu.address.testutil.TypicalPersons.FIONA; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.util.Arrays; import java.util.Collections; diff --git a/src/test/java/seedu/address/logic/commands/ListCommandTest.java b/src/test/java/seedu/address/logic/commands/ListCommandTest.java index a89176acc3b..322bfade4e8 100644 --- a/src/test/java/seedu/address/logic/commands/ListCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ListCommandTest.java @@ -2,8 +2,8 @@ import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,7 +33,7 @@ public void execute_listIsNotFiltered_showsSameList() { @Test public void execute_listIsFiltered_showsEverything() { - showPersonAtIndex(model, INDEX_FIRST_PERSON); + showPersonAtIndex(model, INDEX_FIRST_STUDENT); assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel); } } diff --git a/src/test/java/seedu/address/logic/commands/CopyCommandDescriptorTest.java b/src/test/java/seedu/address/logic/commands/descriptors/CopyCommandDescriptorTest.java similarity index 91% rename from src/test/java/seedu/address/logic/commands/CopyCommandDescriptorTest.java rename to src/test/java/seedu/address/logic/commands/descriptors/CopyCommandDescriptorTest.java index a3e5573c5ef..3a2b7db890d 100644 --- a/src/test/java/seedu/address/logic/commands/CopyCommandDescriptorTest.java +++ b/src/test/java/seedu/address/logic/commands/descriptors/CopyCommandDescriptorTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.descriptors; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -6,8 +6,6 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.descriptors.CopyCommandDescriptor; - public class CopyCommandDescriptorTest { @Test diff --git a/src/test/java/seedu/address/logic/commands/EditStudentDescriptorTest.java b/src/test/java/seedu/address/logic/commands/descriptors/EditStudentDescriptorTest.java similarity index 80% rename from src/test/java/seedu/address/logic/commands/EditStudentDescriptorTest.java rename to src/test/java/seedu/address/logic/commands/descriptors/EditStudentDescriptorTest.java index a73b23b28d6..66c927921c7 100644 --- a/src/test/java/seedu/address/logic/commands/EditStudentDescriptorTest.java +++ b/src/test/java/seedu/address/logic/commands/descriptors/EditStudentDescriptorTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.descriptors; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -6,15 +6,16 @@ import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMERGENCY_CONTACT_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_FORM_CLASS_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_BOB; 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_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.descriptors.EditStudentDescriptor; import seedu.address.testutil.EditStudentDescriptorBuilder; public class EditStudentDescriptorTest { @@ -49,12 +50,16 @@ public void equals() { editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withEmail(VALID_EMAIL_BOB).build(); assertFalse(DESC_AMY.equals(editedAmy)); + // different gender -> returns false + editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withGender(VALID_GENDER_BOB).build(); + assertFalse(DESC_AMY.equals(editedAmy)); + // different address -> returns false editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withAddress(VALID_ADDRESS_BOB).build(); assertFalse(DESC_AMY.equals(editedAmy)); // different tags -> returns false - editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withTags(VALID_TAG_HUSBAND).build(); + editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withTags(VALID_TAG_MONITOR).build(); assertFalse(DESC_AMY.equals(editedAmy)); // different involvement -> returns false @@ -64,5 +69,10 @@ public void equals() { // different form class -> returns false editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withInvolvement(VALID_FORM_CLASS_BOB).build(); assertFalse(DESC_AMY.equals(editedAmy)); + + // different emergency contact -> returns false + editedAmy = new EditStudentDescriptorBuilder(DESC_AMY) + .withEmergencyContact(VALID_EMERGENCY_CONTACT_BOB).build(); + assertFalse(DESC_AMY.equals(editedAmy)); } } diff --git a/src/test/java/seedu/address/logic/commands/descriptors/EditTeacherDescriptorTest.java b/src/test/java/seedu/address/logic/commands/descriptors/EditTeacherDescriptorTest.java new file mode 100644 index 00000000000..27c5d8f9fd5 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/descriptors/EditTeacherDescriptorTest.java @@ -0,0 +1,67 @@ +package seedu.address.logic.commands.descriptors; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.logic.commands.CommandTestUtil.DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_OFFICE_TABLE_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; + +import org.junit.jupiter.api.Test; + +import seedu.address.testutil.EditTeacherDescriptorBuilder; + +public class EditTeacherDescriptorTest { + + @Test + public void equals() { + // same values -> returns true + EditTeacherDescriptor descriptorWithSameValues = new EditTeacherDescriptor(DESC_CHO); + assertTrue(DESC_CHO.equals(descriptorWithSameValues)); + + // same object -> returns true + assertTrue(DESC_CHO.equals(DESC_CHO)); + + // null -> returns false + assertFalse(DESC_CHO.equals(null)); + + // different types -> returns false + assertFalse(DESC_CHO.equals(5)); + + // different values -> returns false + assertFalse(DESC_CHO.equals(DESC_DEE)); + + // different name -> returns false + EditTeacherDescriptor editedCho = new EditTeacherDescriptorBuilder(DESC_CHO).withName(VALID_NAME_DEE).build(); + assertFalse(DESC_CHO.equals(editedCho)); + + // different phone -> returns false + editedCho = new EditTeacherDescriptorBuilder(DESC_CHO).withPhone(VALID_PHONE_DEE).build(); + assertFalse(DESC_CHO.equals(editedCho)); + + // different email -> returns false + editedCho = new EditTeacherDescriptorBuilder(DESC_CHO).withEmail(VALID_EMAIL_DEE).build(); + assertFalse(DESC_CHO.equals(editedCho)); + + // different gender -> returns false + editedCho = new EditTeacherDescriptorBuilder(DESC_CHO).withGender(VALID_GENDER_DEE).build(); + assertFalse(DESC_CHO.equals(editedCho)); + + // different involvement -> returns false + editedCho = new EditTeacherDescriptorBuilder(DESC_CHO).withInvolvement(VALID_INVOLVEMENT_DEE).build(); + assertFalse(DESC_CHO.equals(editedCho)); + + // different office table number -> returns false + editedCho = new EditTeacherDescriptorBuilder(DESC_CHO).withOfficeTable(VALID_OFFICE_TABLE_DEE).build(); + assertFalse(DESC_CHO.equals(editedCho)); + + // different tags -> returns false + editedCho = new EditTeacherDescriptorBuilder(DESC_CHO).withTags(VALID_TAG_MONITOR).build(); + assertFalse(DESC_CHO.equals(editedCho)); + } +} diff --git a/src/test/java/seedu/address/logic/commands/AddStudentCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/student/AddStudentCommandIntegrationTest.java similarity index 77% rename from src/test/java/seedu/address/logic/commands/AddStudentCommandIntegrationTest.java rename to src/test/java/seedu/address/logic/commands/student/AddStudentCommandIntegrationTest.java index 9b73eeb2a8b..6fa527c9d46 100644 --- a/src/test/java/seedu/address/logic/commands/AddStudentCommandIntegrationTest.java +++ b/src/test/java/seedu/address/logic/commands/student/AddStudentCommandIntegrationTest.java @@ -1,13 +1,12 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.student; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.student.AddStudentCommand; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -15,7 +14,7 @@ import seedu.address.testutil.StudentBuilder; /** - * Contains integration tests (interaction with the Model) for {@code StudentCommand}. + * Contains integration tests (interaction with the Model) for {@code AddStudentCommand}. */ public class AddStudentCommandIntegrationTest { @@ -27,7 +26,7 @@ public void setUp() { } @Test - public void execute_newPerson_success() { + public void execute_newStudent_success() { Student validStudent = new StudentBuilder().build(); Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); @@ -38,9 +37,8 @@ public void execute_newPerson_success() { } @Test - public void execute_duplicatePerson_throwsCommandException() { + public void execute_duplicateStudent_throwsCommandException() { Student studentInList = (Student) model.getAddressBook().getPersonList().get(0); - assertCommandFailure(new AddStudentCommand(studentInList), model, AddStudentCommand.MESSAGE_DUPLICATE_PERSON); + assertCommandFailure(new AddStudentCommand(studentInList), model, AddStudentCommand.MESSAGE_DUPLICATE_STUDENT); } - } diff --git a/src/test/java/seedu/address/logic/commands/AddStudentCommandTest.java b/src/test/java/seedu/address/logic/commands/student/AddStudentCommandTest.java similarity index 96% rename from src/test/java/seedu/address/logic/commands/AddStudentCommandTest.java rename to src/test/java/seedu/address/logic/commands/student/AddStudentCommandTest.java index 621b6c1144e..6b7ad30380d 100644 --- a/src/test/java/seedu/address/logic/commands/AddStudentCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/student/AddStudentCommandTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.student; import static java.util.Objects.requireNonNull; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -15,8 +15,8 @@ import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.logic.commands.student.AddStudentCommand; import seedu.address.model.AddressBook; import seedu.address.model.Model; import seedu.address.model.ReadOnlyAddressBook; @@ -50,7 +50,7 @@ public void execute_duplicateStudent_throwsCommandException() { ModelStub modelStub = new ModelStubWithPerson(validStudent); assertThrows(CommandException.class, - AddStudentCommand.MESSAGE_DUPLICATE_PERSON, () -> addStudentCommand.execute(modelStub)); + AddStudentCommand.MESSAGE_DUPLICATE_STUDENT, () -> addStudentCommand.execute(modelStub)); } @Test @@ -73,7 +73,7 @@ public void equals() { // null -> returns false assertFalse(addAliceCommand.equals(null)); - // different person -> returns false + // different student -> returns false assertFalse(addAliceCommand.equals(addBobCommand)); } diff --git a/src/test/java/seedu/address/logic/commands/student/EditStudentCommandTest.java b/src/test/java/seedu/address/logic/commands/student/EditStudentCommandTest.java new file mode 100644 index 00000000000..d1ac0ca446c --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/student/EditStudentCommandTest.java @@ -0,0 +1,178 @@ +package seedu.address.logic.commands.student; + +import static org.junit.jupiter.api.Assertions.assertFalse; +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_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_STUDENT; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.Test; + +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.descriptors.EditStudentDescriptor; +import seedu.address.model.AddressBook; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.Person; +import seedu.address.model.person.Student; +import seedu.address.testutil.EditStudentDescriptorBuilder; +import seedu.address.testutil.StudentBuilder; + +/** + * Contains integration tests (interaction with the Model) and unit tests for EditStudentCommand. + */ +public class EditStudentCommandTest { + + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void execute_allFieldsSpecifiedUnfilteredList_success() { + // check if all fields can be edited + Student editedStudent = new StudentBuilder().buildForEdit(); + EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder(editedStudent).build(); + EditStudentCommand editStudentCommand = new EditStudentCommand(INDEX_FIRST_STUDENT, descriptor); + + String expectedMessage = String.format(EditStudentCommand.MESSAGE_EDIT_STUDENT_SUCCESS, editedStudent); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + System.out.println(model.getFilteredPersonList().get(0)); + expectedModel.setPerson(model.getFilteredPersonList().get(0), editedStudent); + assertCommandSuccess(editStudentCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_someFieldsSpecifiedUnfilteredList_success() { + Index indexLastStudent = Index.fromOneBased(7); + Person lastStudent = model.getFilteredPersonList().get(indexLastStudent.getZeroBased()); + + StudentBuilder studentInList = new StudentBuilder((Student) lastStudent); + Student editedStudent = studentInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB) + .withTags(VALID_TAG_MONITOR).build(); + + EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB) + .withPhone(VALID_PHONE_BOB).withTags(VALID_TAG_MONITOR).build(); + EditStudentCommand editStudentCommand = new EditStudentCommand(indexLastStudent, descriptor); + + String expectedMessage = String.format(EditStudentCommand.MESSAGE_EDIT_STUDENT_SUCCESS, editedStudent); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.setPerson(lastStudent, editedStudent); + + assertCommandSuccess(editStudentCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_noFieldSpecifiedUnfilteredList_success() { + EditStudentCommand editStudentCommand = new EditStudentCommand(INDEX_FIRST_STUDENT, + new EditStudentDescriptor()); + Person editedStudent = model.getFilteredPersonList().get(INDEX_FIRST_STUDENT.getZeroBased()); + + String expectedMessage = String.format(EditStudentCommand.MESSAGE_EDIT_STUDENT_SUCCESS, editedStudent); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + + assertCommandSuccess(editStudentCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_filteredList_success() { + showPersonAtIndex(model, INDEX_FIRST_STUDENT); + + Person studentInFilteredList = model.getFilteredPersonList().get(INDEX_FIRST_STUDENT.getZeroBased()); + Person editedStudent = new StudentBuilder((Student) studentInFilteredList).withName(VALID_NAME_BOB).build(); + EditStudentCommand editStudentCommand = new EditStudentCommand(INDEX_FIRST_STUDENT, + new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB).build()); + + String expectedMessage = String.format(EditStudentCommand.MESSAGE_EDIT_STUDENT_SUCCESS, editedStudent); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.setPerson(model.getFilteredPersonList().get(0), editedStudent); + + assertCommandSuccess(editStudentCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_duplicateStudentUnfilteredList_failure() { + Student firstStudent = (Student) model.getFilteredPersonList().get(INDEX_FIRST_STUDENT.getZeroBased()); + EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder(firstStudent).build(); + EditStudentCommand editStudentCommand = new EditStudentCommand(INDEX_SECOND_STUDENT, descriptor); + + assertCommandFailure(editStudentCommand, model, EditStudentCommand.MESSAGE_DUPLICATE_STUDENT); + } + + @Test + public void execute_duplicateStudentFilteredList_failure() { + showPersonAtIndex(model, INDEX_FIRST_STUDENT); + + // edit student in filtered list into a duplicate in address book + Student studentInList = (Student) model.getAddressBook() + .getPersonList().get(INDEX_SECOND_STUDENT.getZeroBased()); + EditStudentCommand editStudentCommand = new EditStudentCommand(INDEX_FIRST_STUDENT, + new EditStudentDescriptorBuilder(studentInList).build()); + + assertCommandFailure(editStudentCommand, model, EditStudentCommand.MESSAGE_DUPLICATE_STUDENT); + } + + @Test + public void execute_invalidStudentIndexUnfilteredList_failure() { + Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); + EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB).build(); + EditStudentCommand editCommand = new EditStudentCommand(outOfBoundIndex, descriptor); + + assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + /** + * Edit filtered list where index is larger than size of filtered list, + * but smaller than size of address book + */ + @Test + public void execute_invalidStudentIndexFilteredList_failure() { + showPersonAtIndex(model, INDEX_FIRST_STUDENT); + Index outOfBoundIndex = INDEX_SECOND_STUDENT; + // ensures that outOfBoundIndex is still in bounds of address book list + assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getPersonList().size()); + + EditStudentCommand editStudentCommand = new EditStudentCommand(outOfBoundIndex, + new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB).build()); + + assertCommandFailure(editStudentCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + @Test + public void equals() { + final EditStudentCommand standardCommand = new EditStudentCommand(INDEX_FIRST_STUDENT, DESC_AMY); + + // same values -> returns true + EditStudentDescriptor copyDescriptor = new EditStudentDescriptor(DESC_AMY); + EditStudentCommand commandWithSameValues = new EditStudentCommand(INDEX_FIRST_STUDENT, copyDescriptor); + assertTrue(standardCommand.equals(commandWithSameValues)); + + // same object -> returns true + assertTrue(standardCommand.equals(standardCommand)); + + // null -> returns false + assertFalse(standardCommand.equals(null)); + + // different types -> returns false + assertFalse(standardCommand.equals(new ClearCommand())); + + // different index -> returns false + assertFalse(standardCommand.equals(new EditStudentCommand(INDEX_SECOND_STUDENT, DESC_AMY))); + + // different descriptor -> returns false + assertFalse(standardCommand.equals(new EditStudentCommand(INDEX_FIRST_STUDENT, DESC_BOB))); + } + +} diff --git a/src/test/java/seedu/address/logic/commands/student/MedicalHistoryCommandTest.java b/src/test/java/seedu/address/logic/commands/student/MedicalHistoryCommandTest.java index e8377e51842..98c1e88f24a 100644 --- a/src/test/java/seedu/address/logic/commands/student/MedicalHistoryCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/student/MedicalHistoryCommandTest.java @@ -7,9 +7,9 @@ import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; -import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_STUDENT; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import org.junit.jupiter.api.Test; @@ -31,10 +31,10 @@ class MedicalHistoryCommandTest { @Test public void execute_addMedicalHistoryUnfilteredList_success() { - Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_STUDENT.getZeroBased()); StudentBuilder personInList = new StudentBuilder((Student) firstPerson); Student editedStudent = personInList.withMedicalHistory(MEDICAL_HISTORY_STUB).build(); - MedicalHistoryCommand medicalHistoryCommand = new MedicalHistoryCommand(INDEX_FIRST_PERSON, + MedicalHistoryCommand medicalHistoryCommand = new MedicalHistoryCommand(INDEX_FIRST_STUDENT, new MedicalHistory(editedStudent.getMedicalHistory().value)); String expectedMessage = String.format(MedicalHistoryCommand.MESSAGE_ADD_MEDICAL_HISTORY_SUCCESS, @@ -48,11 +48,10 @@ public void execute_addMedicalHistoryUnfilteredList_success() { @Test public void execute_deleteMedicalHistoryUnfilteredList_success() { - Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - StudentBuilder personInList = new StudentBuilder((Student) firstPerson); + Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_STUDENT.getZeroBased()); Student editedStudent = new StudentBuilder((Student) firstPerson).withMedicalHistory("").build(); - MedicalHistoryCommand medicalHistoryCommand = new MedicalHistoryCommand(INDEX_FIRST_PERSON, + MedicalHistoryCommand medicalHistoryCommand = new MedicalHistoryCommand(INDEX_FIRST_STUDENT, new MedicalHistory(editedStudent.getMedicalHistory().toString())); String expectedMessage = String.format(MedicalHistoryCommand.MESSAGE_DELETE_MEDICAL_HISTORY_SUCCESS, @@ -66,13 +65,13 @@ public void execute_deleteMedicalHistoryUnfilteredList_success() { @Test public void execute_filteredList_success() { - showPersonAtIndex(model, INDEX_FIRST_PERSON); + showPersonAtIndex(model, INDEX_FIRST_STUDENT); - Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - Student editedStudent = new StudentBuilder((Student) model.getFilteredPersonList().get(INDEX_FIRST_PERSON + Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_STUDENT.getZeroBased()); + Student editedStudent = new StudentBuilder((Student) model.getFilteredPersonList().get(INDEX_FIRST_STUDENT .getZeroBased())).withMedicalHistory(MEDICAL_HISTORY_STUB).build(); - MedicalHistoryCommand medicalHistoryCommand = new MedicalHistoryCommand(INDEX_FIRST_PERSON, + MedicalHistoryCommand medicalHistoryCommand = new MedicalHistoryCommand(INDEX_FIRST_STUDENT, new MedicalHistory(editedStudent.getMedicalHistory().value)); String expectedMessage = String.format(MedicalHistoryCommand.MESSAGE_ADD_MEDICAL_HISTORY_SUCCESS, @@ -99,8 +98,8 @@ public void execute_invalidPersonIndexUnfilteredList_failure() { */ @Test public void execute_invalidPersonIndexFilteredList_failure() { - showPersonAtIndex(model, INDEX_FIRST_PERSON); - Index outOfBoundIndex = INDEX_SECOND_PERSON; + showPersonAtIndex(model, INDEX_FIRST_STUDENT); + Index outOfBoundIndex = INDEX_SECOND_STUDENT; // ensures that outOfBoundIndex is still in bounds of address book list assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getPersonList().size()); @@ -112,11 +111,11 @@ public void execute_invalidPersonIndexFilteredList_failure() { @Test public void equals() { - final MedicalHistoryCommand standardCommand = new MedicalHistoryCommand(INDEX_FIRST_PERSON, + final MedicalHistoryCommand standardCommand = new MedicalHistoryCommand(INDEX_FIRST_STUDENT, new MedicalHistory(VALID_MEDICAL_HISTORY_AMY)); // same values -> returns true - MedicalHistoryCommand commandWithSameValues = new MedicalHistoryCommand(INDEX_FIRST_PERSON, + MedicalHistoryCommand commandWithSameValues = new MedicalHistoryCommand(INDEX_FIRST_STUDENT, new MedicalHistory(VALID_MEDICAL_HISTORY_AMY)); assertTrue(standardCommand.equals(commandWithSameValues)); @@ -130,11 +129,11 @@ public void equals() { assertFalse(standardCommand.equals(new ClearCommand())); // different index -> returns false - assertFalse(standardCommand.equals(new MedicalHistoryCommand(INDEX_SECOND_PERSON, + assertFalse(standardCommand.equals(new MedicalHistoryCommand(INDEX_SECOND_STUDENT, new MedicalHistory(VALID_MEDICAL_HISTORY_AMY)))); // different MedicalHistory -> returns false - assertFalse(standardCommand.equals(new MedicalHistoryCommand(INDEX_FIRST_PERSON, + assertFalse(standardCommand.equals(new MedicalHistoryCommand(INDEX_FIRST_STUDENT, new MedicalHistory(VALID_MEDICAL_HISTORY_BOB)))); } } diff --git a/src/test/java/seedu/address/logic/commands/teacher/AddTeacherCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/teacher/AddTeacherCommandIntegrationTest.java new file mode 100644 index 00000000000..9e41d7a9d05 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/teacher/AddTeacherCommandIntegrationTest.java @@ -0,0 +1,44 @@ +package seedu.address.logic.commands.teacher; + +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.Teacher; +import seedu.address.testutil.TeacherBuilder; + +/** + * Contains integration tests (interaction with the Model) for {@code AddTeacherCommand}. + */ +public class AddTeacherCommandIntegrationTest { + + private Model model; + + @BeforeEach + public void setUp() { + model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + } + + @Test + public void execute_newTeacher_success() { + Teacher validTeacher = new TeacherBuilder().build(); + + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + expectedModel.addPerson(validTeacher); + + assertCommandSuccess(new AddTeacherCommand(validTeacher), model, + String.format(AddTeacherCommand.MESSAGE_SUCCESS, validTeacher), expectedModel); + } + + @Test + public void execute_duplicateTeacher_throwsCommandException() { + Teacher teacherInList = (Teacher) model.getAddressBook().getPersonList().get(8); + assertCommandFailure(new AddTeacherCommand(teacherInList), model, AddTeacherCommand.MESSAGE_DUPLICATE_TEACHER); + } +} diff --git a/src/test/java/seedu/address/logic/commands/teacher/AddTeacherCommandTest.java b/src/test/java/seedu/address/logic/commands/teacher/AddTeacherCommandTest.java new file mode 100644 index 00000000000..9056d47aaac --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/teacher/AddTeacherCommandTest.java @@ -0,0 +1,196 @@ +package seedu.address.logic.commands.teacher; + +import static java.util.Objects.requireNonNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.function.Predicate; + +import org.junit.jupiter.api.Test; + +import javafx.collections.ObservableList; +import seedu.address.commons.core.GuiSettings; +import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.AddressBook; +import seedu.address.model.Model; +import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyUserPrefs; +import seedu.address.model.person.Person; +import seedu.address.model.person.Teacher; +import seedu.address.testutil.TeacherBuilder; + +public class AddTeacherCommandTest { + + @Test + public void constructor_nullTeacher_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new AddTeacherCommand(null)); + } + + @Test + public void execute_teacherAcceptedByModel_addSuccessful() throws Exception { + ModelStubAcceptingPersonAdded modelStub = new ModelStubAcceptingPersonAdded(); + Teacher validTeacher = new TeacherBuilder().build(); + + CommandResult commandResult = new AddTeacherCommand(validTeacher).execute(modelStub); + + assertEquals(String.format(AddTeacherCommand.MESSAGE_SUCCESS, validTeacher), commandResult.getFeedbackToUser()); + assertEquals(Arrays.asList(validTeacher), modelStub.personsAdded); + } + + @Test + public void execute_duplicateTeacher_throwsCommandException() { + Teacher validTeacher = new TeacherBuilder().build(); + AddTeacherCommand addTeacherCommand = new AddTeacherCommand(validTeacher); + ModelStub modelStub = new ModelStubWithPerson(validTeacher); + + assertThrows(CommandException.class, + AddTeacherCommand.MESSAGE_DUPLICATE_TEACHER, () -> addTeacherCommand.execute(modelStub)); + } + + @Test + public void equals() { + Teacher cho = new TeacherBuilder().withName("Cho").build(); + Teacher dee = new TeacherBuilder().withName("Dee").build(); + AddTeacherCommand addChoCommand = new AddTeacherCommand(cho); + AddTeacherCommand addDeeCommand = new AddTeacherCommand(dee); + + // same object -> returns true + assertTrue(addChoCommand.equals(addChoCommand)); + + // same values -> returns true + AddTeacherCommand addChoCommandCopy = new AddTeacherCommand(cho); + assertTrue(addChoCommand.equals(addChoCommandCopy)); + + // different types -> returns false + assertFalse(addChoCommand.equals(1)); + + // null -> returns false + assertFalse(addChoCommand.equals(null)); + + // different teacher -> returns false + assertFalse(addChoCommand.equals(addDeeCommand)); + } + + /** + * A default model stub that have all of the methods failing. + */ + private class ModelStub implements Model { + @Override + public void setUserPrefs(ReadOnlyUserPrefs userPrefs) { + throw new AssertionError("This method should not be called."); + } + + @Override + public ReadOnlyUserPrefs getUserPrefs() { + throw new AssertionError("This method should not be called."); + } + + @Override + public GuiSettings getGuiSettings() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setGuiSettings(GuiSettings guiSettings) { + throw new AssertionError("This method should not be called."); + } + + @Override + public Path getAddressBookFilePath() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setAddressBookFilePath(Path addressBookFilePath) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void addPerson(Person person) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setAddressBook(ReadOnlyAddressBook newData) { + throw new AssertionError("This method should not be called."); + } + + @Override + public ReadOnlyAddressBook getAddressBook() { + throw new AssertionError("This method should not be called."); + } + + @Override + public boolean hasPerson(Person person) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void deletePerson(Person target) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setPerson(Person target, Person editedPerson) { + throw new AssertionError("This method should not be called."); + } + + @Override + public ObservableList getFilteredPersonList() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void updateFilteredPersonList(Predicate predicate) { + throw new AssertionError("This method should not be called."); + } + } + + /** + * A Model stub that contains a single person. + */ + private class ModelStubWithPerson extends ModelStub { + private final Person person; + + ModelStubWithPerson(Person person) { + requireNonNull(person); + this.person = person; + } + + @Override + public boolean hasPerson(Person person) { + requireNonNull(person); + return this.person.isSamePerson(person); + } + } + + /** + * A Model stub that always accept the person being added. + */ + private class ModelStubAcceptingPersonAdded extends ModelStub { + final ArrayList personsAdded = new ArrayList<>(); + + @Override + public boolean hasPerson(Person person) { + requireNonNull(person); + return personsAdded.stream().anyMatch(person::isSamePerson); + } + + @Override + public void addPerson(Person person) { + requireNonNull(person); + personsAdded.add(person); + } + + @Override + public ReadOnlyAddressBook getAddressBook() { + return new AddressBook(); + } + } +} diff --git a/src/test/java/seedu/address/logic/commands/teacher/EditTeacherCommandTest.java b/src/test/java/seedu/address/logic/commands/teacher/EditTeacherCommandTest.java new file mode 100644 index 00000000000..22d51f00b88 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/teacher/EditTeacherCommandTest.java @@ -0,0 +1,178 @@ +package seedu.address.logic.commands.teacher; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.logic.commands.CommandTestUtil.DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_TEACHER; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_TEACHER; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.Test; + +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.descriptors.EditTeacherDescriptor; +import seedu.address.model.AddressBook; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.Person; +import seedu.address.model.person.Teacher; +import seedu.address.testutil.EditTeacherDescriptorBuilder; +import seedu.address.testutil.TeacherBuilder; + +/** + * Contains integration tests (interaction with the Model) and unit tests for EditTeacherCommand. + */ +public class EditTeacherCommandTest { + + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void execute_allFieldsSpecifiedUnfilteredList_success() { + // check if all fields can be edited + Teacher editedTeacher = new TeacherBuilder().build(); + EditTeacherDescriptor descriptor = new EditTeacherDescriptorBuilder(editedTeacher).build(); + EditTeacherCommand editTeacherCommand = new EditTeacherCommand(INDEX_FIRST_TEACHER, descriptor); + + String expectedMessage = String.format(EditTeacherCommand.MESSAGE_EDIT_TEACHER_SUCCESS, editedTeacher); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.setPerson(model.getFilteredPersonList().get(7), editedTeacher); + + assertCommandSuccess(editTeacherCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_someFieldsSpecifiedUnfilteredList_success() { + Index indexLastTeacher = Index.fromOneBased(14); + Person lastTeacher = model.getFilteredPersonList().get(indexLastTeacher.getZeroBased()); + + TeacherBuilder teacherInList = new TeacherBuilder((Teacher) lastTeacher); + Teacher editedTeacher = teacherInList.withName(VALID_NAME_DEE).withPhone(VALID_PHONE_DEE) + .withTags(VALID_TAG_MONITOR).build(); + + EditTeacherDescriptor descriptor = new EditTeacherDescriptorBuilder().withName(VALID_NAME_DEE) + .withPhone(VALID_PHONE_DEE).withTags(VALID_TAG_MONITOR).build(); + EditTeacherCommand editTeacherCommand = new EditTeacherCommand(indexLastTeacher, descriptor); + + String expectedMessage = String.format(EditTeacherCommand.MESSAGE_EDIT_TEACHER_SUCCESS, editedTeacher); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.setPerson(lastTeacher, editedTeacher); + + assertCommandSuccess(editTeacherCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_noFieldSpecifiedUnfilteredList_success() { + EditTeacherCommand editTeacherCommand = new EditTeacherCommand(INDEX_FIRST_TEACHER, + new EditTeacherDescriptor()); + Person editedTeacher = model.getFilteredPersonList().get(INDEX_FIRST_TEACHER.getZeroBased()); + + String expectedMessage = String.format(EditTeacherCommand.MESSAGE_EDIT_TEACHER_SUCCESS, editedTeacher); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + + assertCommandSuccess(editTeacherCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_filteredList_success() { + showPersonAtIndex(model, INDEX_FIRST_TEACHER); + + Person teacherInFilteredList = model.getFilteredPersonList().get(0); + Teacher editedTeacher = new TeacherBuilder((Teacher) teacherInFilteredList).withName(VALID_NAME_DEE).build(); + EditTeacherCommand editTeacherCommand = new EditTeacherCommand(INDEX_FIRST_STUDENT, + new EditTeacherDescriptorBuilder().withName(VALID_NAME_DEE).build()); + + String expectedMessage = String.format(EditTeacherCommand.MESSAGE_EDIT_TEACHER_SUCCESS, editedTeacher); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.setPerson(model.getFilteredPersonList().get(0), editedTeacher); + + assertCommandSuccess(editTeacherCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_duplicateTeacherUnfilteredList_failure() { + Teacher firstTeacher = (Teacher) model.getFilteredPersonList().get(INDEX_FIRST_TEACHER.getZeroBased()); + EditTeacherDescriptor descriptor = new EditTeacherDescriptorBuilder(firstTeacher).build(); + EditTeacherCommand editTeacherCommand = new EditTeacherCommand(INDEX_SECOND_TEACHER, descriptor); + + assertCommandFailure(editTeacherCommand, model, EditTeacherCommand.MESSAGE_DUPLICATE_TEACHER); + } + + @Test + public void execute_duplicateTeacherFilteredList_failure() { + showPersonAtIndex(model, INDEX_FIRST_TEACHER); + + // edit teacher in filtered list into a duplicate in address book + Teacher teacherInList = (Teacher) model.getAddressBook() + .getPersonList().get(INDEX_SECOND_TEACHER.getZeroBased()); + EditTeacherCommand editTeacherCommand = new EditTeacherCommand(INDEX_FIRST_STUDENT, + new EditTeacherDescriptorBuilder(teacherInList).build()); + + assertCommandFailure(editTeacherCommand, model, EditTeacherCommand.MESSAGE_DUPLICATE_TEACHER); + } + + @Test + public void execute_invalidTeacherIndexUnfilteredList_failure() { + Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); + EditTeacherDescriptor descriptor = new EditTeacherDescriptorBuilder().withName(VALID_NAME_DEE).build(); + EditTeacherCommand editCommand = new EditTeacherCommand(outOfBoundIndex, descriptor); + + assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + /** + * Edit filtered list where index is larger than size of filtered list, + * but smaller than size of address book + */ + @Test + public void execute_invalidTeacherIndexFilteredList_failure() { + showPersonAtIndex(model, INDEX_FIRST_TEACHER); + Index outOfBoundIndex = INDEX_SECOND_TEACHER; + // ensures that outOfBoundIndex is still in bounds of address book list + assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getPersonList().size()); + + EditTeacherCommand editTeacherCommand = new EditTeacherCommand(outOfBoundIndex, + new EditTeacherDescriptorBuilder().withName(VALID_NAME_DEE).build()); + + assertCommandFailure(editTeacherCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + @Test + public void equals() { + final EditTeacherCommand standardCommand = new EditTeacherCommand(INDEX_FIRST_TEACHER, DESC_DEE); + + // same values -> returns true + EditTeacherDescriptor copyDescriptor = new EditTeacherDescriptor(DESC_DEE); + EditTeacherCommand commandWithSameValues = new EditTeacherCommand(INDEX_FIRST_TEACHER, copyDescriptor); + assertTrue(standardCommand.equals(commandWithSameValues)); + + // same object -> returns true + assertTrue(standardCommand.equals(standardCommand)); + + // null -> returns false + assertFalse(standardCommand.equals(null)); + + // different types -> returns false + assertFalse(standardCommand.equals(new ClearCommand())); + + // different index -> returns false + assertFalse(standardCommand.equals(new EditTeacherCommand(INDEX_SECOND_TEACHER, DESC_DEE))); + + // different descriptor -> returns false + assertFalse(standardCommand.equals(new EditTeacherCommand(INDEX_FIRST_TEACHER, DESC_CHO))); + } +} diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index ef75545312e..47a6d5c8c7d 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -6,7 +6,7 @@ import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; import static seedu.address.logic.parser.CliSyntax.PREFIX_MEDICAL_HISTORY; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; import java.util.Arrays; import java.util.List; @@ -37,7 +37,7 @@ public class AddressBookParserTest { private final AddressBookParser parser = new AddressBookParser(); @Test - public void parseCommand_student() throws Exception { + public void parseCommand_addStudent() throws Exception { Student student = new StudentBuilder().build(); AddStudentCommand command = (AddStudentCommand) parser.parseCommand(StudentUtil.getStudentCommand(student)); assertEquals(new AddStudentCommand(student), command); @@ -52,8 +52,8 @@ public void parseCommand_clear() throws Exception { @Test public void parseCommand_delete() throws Exception { DeleteCommand command = (DeleteCommand) parser.parseCommand( - DeleteCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); - assertEquals(new DeleteCommand(INDEX_FIRST_PERSON), command); + DeleteCommand.COMMAND_WORD + " " + INDEX_FIRST_STUDENT.getOneBased()); + assertEquals(new DeleteCommand(INDEX_FIRST_STUDENT), command); } @Test @@ -61,8 +61,8 @@ public void parseCommand_edit() throws Exception { Student person = new StudentBuilder().build(); EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder(person).build(); EditStudentCommand command = (EditStudentCommand) parser.parseCommand(EditStudentCommand.COMMAND_WORD + " " - + INDEX_FIRST_PERSON.getOneBased() + " " + StudentUtil.getEditStudentDescriptorDetails(descriptor)); - assertEquals(new EditStudentCommand(INDEX_FIRST_PERSON, descriptor), command); + + INDEX_FIRST_STUDENT.getOneBased() + " " + StudentUtil.getEditStudentDescriptorDetails(descriptor)); + assertEquals(new EditStudentCommand(INDEX_FIRST_STUDENT, descriptor), command); } @Test @@ -96,8 +96,8 @@ public void parseCommand_medical() throws Exception { final MedicalHistory medicalHistory = new MedicalHistory("ADHD"); MedicalHistoryCommand command = (MedicalHistoryCommand) parser.parseCommand( MedicalHistoryCommand.COMMAND_WORD + " " - + INDEX_FIRST_PERSON.getOneBased() + " " + PREFIX_MEDICAL_HISTORY + medicalHistory.value); - assertEquals(new MedicalHistoryCommand(INDEX_FIRST_PERSON, medicalHistory), command); + + INDEX_FIRST_STUDENT.getOneBased() + " " + PREFIX_MEDICAL_HISTORY + medicalHistory.value); + assertEquals(new MedicalHistoryCommand(INDEX_FIRST_STUDENT, medicalHistory), command); } @Test diff --git a/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java b/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java index 27eaec84450..01ad5de4319 100644 --- a/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java @@ -3,7 +3,7 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; import org.junit.jupiter.api.Test; @@ -22,7 +22,7 @@ public class DeleteCommandParserTest { @Test public void parse_validArgs_returnsDeleteCommand() { - assertParseSuccess(parser, "1", new DeleteCommand(INDEX_FIRST_PERSON)); + assertParseSuccess(parser, "1", new DeleteCommand(INDEX_FIRST_STUDENT)); } @Test diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index 8492934be66..7ef06e32a82 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -4,7 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.parser.ParserUtil.MESSAGE_INVALID_INDEX; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; import java.util.Arrays; import java.util.Collections; @@ -56,10 +56,10 @@ public void parseIndex_outOfRangeInput_throwsParseException() { @Test public void parseIndex_validInput_success() throws Exception { // No whitespaces - assertEquals(INDEX_FIRST_PERSON, ParserUtil.parseIndex("1")); + assertEquals(INDEX_FIRST_STUDENT, ParserUtil.parseIndex("1")); // Leading and trailing whitespaces - assertEquals(INDEX_FIRST_PERSON, ParserUtil.parseIndex(" 1 ")); + assertEquals(INDEX_FIRST_STUDENT, ParserUtil.parseIndex(" 1 ")); } @Test diff --git a/src/test/java/seedu/address/logic/parser/AddStudentCommandParserTest.java b/src/test/java/seedu/address/logic/parser/student/AddStudentCommandParserTest.java similarity index 67% rename from src/test/java/seedu/address/logic/parser/AddStudentCommandParserTest.java rename to src/test/java/seedu/address/logic/parser/student/AddStudentCommandParserTest.java index 83d2774d779..9aa40f777c3 100644 --- a/src/test/java/seedu/address/logic/parser/AddStudentCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/student/AddStudentCommandParserTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.student; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY; @@ -13,6 +13,7 @@ import static seedu.address.logic.commands.CommandTestUtil.GENDER_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.INVALID_ADDRESS_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMERGENCY_CONTACT_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_FORM_CLASS_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_GENDER_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_INVOLVEMENT_DESC; @@ -27,25 +28,26 @@ import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY; import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_WHITESPACE; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_REP; import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMERGENCY_CONTACT_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_FORM_CLASS_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_BOB; 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_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_REP; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; -import static seedu.address.testutil.TypicalStudents.AMY; -import static seedu.address.testutil.TypicalStudents.BOB; +import static seedu.address.testutil.TypicalPersons.AMY; +import static seedu.address.testutil.TypicalPersons.BOB; import org.junit.jupiter.api.Test; import seedu.address.logic.commands.student.AddStudentCommand; -import seedu.address.logic.parser.student.AddStudentCommandParser; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.FormClass; @@ -62,43 +64,61 @@ public class AddStudentCommandParserTest { @Test public void parse_allFieldsPresent_success() { - Student expectedPerson = new StudentBuilder(BOB).withTags(VALID_TAG_FRIEND).build(); + Student expectedPerson = new StudentBuilder(BOB).withTags(VALID_TAG_REP).build(); // whitespace only preamble assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_FRIEND + + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, new AddStudentCommand(expectedPerson)); // multiple names - last name accepted assertParseSuccess(parser, NAME_DESC_AMY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_FRIEND + + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, new AddStudentCommand(expectedPerson)); // multiple phones - last phone accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_AMY + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_FRIEND + + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, new AddStudentCommand(expectedPerson)); // multiple emails - last email accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_AMY + EMAIL_DESC_BOB - + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_FRIEND + + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, new AddStudentCommand(expectedPerson)); + // multiple genders - last gender accepted + assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_REP + + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_AMY + GENDER_DESC_BOB, + new AddStudentCommand(expectedPerson)); + + // multiple emergency contact numbers - last emergency contact number accepted + assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_AMY + + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, + new AddStudentCommand(expectedPerson)); + + // multiple form classes - last form class accepted + assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + + FORM_CLASS_DESC_AMY + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, + new AddStudentCommand(expectedPerson)); + // multiple addresses - last address accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_AMY - + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_FRIEND + + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, new AddStudentCommand(expectedPerson)); // multiple tags - all accepted - Student expectedStudentMultipleTags = new StudentBuilder(BOB).withTags(VALID_TAG_FRIEND, VALID_TAG_HUSBAND) + Student expectedStudentMultipleTags = new StudentBuilder(BOB).withTags(VALID_TAG_REP, VALID_TAG_MONITOR) .build(); assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND + EMERGENCY_CONTACT_DESC_BOB + + INVOLVEMENT_DESC_BOB + TAG_DESC_MONITOR + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, new AddStudentCommand(expectedStudentMultipleTags)); } @@ -119,91 +139,106 @@ public void parse_compulsoryFieldMissing_failure() { // missing name prefix assertParseFailure(parser, - VALID_NAME_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB, + VALID_NAME_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + GENDER_DESC_BOB + + INVOLVEMENT_DESC_BOB + ADDRESS_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB, expectedMessage); // missing phone prefix assertParseFailure(parser, - NAME_DESC_BOB + VALID_PHONE_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB, + NAME_DESC_BOB + VALID_PHONE_BOB + EMAIL_DESC_BOB + GENDER_DESC_BOB + + INVOLVEMENT_DESC_BOB + ADDRESS_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB, expectedMessage); // missing email prefix assertParseFailure(parser, - NAME_DESC_BOB + PHONE_DESC_BOB + VALID_EMAIL_BOB + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB, + NAME_DESC_BOB + PHONE_DESC_BOB + VALID_EMAIL_BOB + GENDER_DESC_BOB + + INVOLVEMENT_DESC_BOB + ADDRESS_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB, expectedMessage); + // missing gender prefix + assertParseFailure(parser, + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VALID_GENDER_BOB + + INVOLVEMENT_DESC_BOB + ADDRESS_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB, + expectedMessage); + + // missing involvement prefix + assertParseFailure(parser, + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + GENDER_DESC_BOB + + VALID_INVOLVEMENT_BOB + ADDRESS_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB, + expectedMessage); + // missing address prefix assertParseFailure(parser, - NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VALID_ADDRESS_BOB - + INVOLVEMENT_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB, + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + GENDER_DESC_BOB + + INVOLVEMENT_DESC_BOB + VALID_ADDRESS_BOB + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB, expectedMessage); // missing emergency contact prefix assertParseFailure(parser, - NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + VALID_EMERGENCY_CONTACT_BOB, + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + GENDER_DESC_BOB + + INVOLVEMENT_DESC_BOB + ADDRESS_DESC_BOB + VALID_EMERGENCY_CONTACT_BOB + FORM_CLASS_DESC_BOB, expectedMessage); - // missing emergency contact prefix + // missing form class prefix assertParseFailure(parser, - NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + VALID_INVOLVEMENT_BOB + VALID_EMERGENCY_CONTACT_BOB, - expectedMessage); + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + GENDER_DESC_BOB + + INVOLVEMENT_DESC_BOB + ADDRESS_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB + VALID_FORM_CLASS_BOB, + expectedMessage); // all prefixes missing assertParseFailure(parser, - VALID_NAME_BOB + VALID_PHONE_BOB + VALID_EMAIL_BOB + VALID_ADDRESS_BOB - + VALID_INVOLVEMENT_BOB + EMERGENCY_CONTACT_DESC_BOB, + VALID_NAME_BOB + VALID_PHONE_BOB + VALID_EMAIL_BOB + VALID_GENDER_BOB + + VALID_INVOLVEMENT_BOB + VALID_ADDRESS_BOB + VALID_EMERGENCY_CONTACT_BOB + VALID_FORM_CLASS_BOB , expectedMessage); - - } @Test public void parse_invalidValue_failure() { // invalid name - assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND - + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, Name.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + GENDER_DESC_BOB + + INVOLVEMENT_DESC_BOB + ADDRESS_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + + TAG_DESC_MONITOR + TAG_DESC_REP, Name.MESSAGE_CONSTRAINTS); // invalid phone - assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND - + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, Phone.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB + GENDER_DESC_BOB + + INVOLVEMENT_DESC_BOB + ADDRESS_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + + TAG_DESC_MONITOR + TAG_DESC_REP, Phone.MESSAGE_CONSTRAINTS); // invalid email - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND - + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, Email.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + GENDER_DESC_BOB + + INVOLVEMENT_DESC_BOB + ADDRESS_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + + TAG_DESC_MONITOR + TAG_DESC_REP, Email.MESSAGE_CONSTRAINTS); + + // invalid gender + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_GENDER_DESC + + INVOLVEMENT_DESC_BOB + ADDRESS_DESC_BOB + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + + TAG_DESC_MONITOR + TAG_DESC_REP, Gender.MESSAGE_CONSTRAINTS); // invalid address assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ADDRESS_DESC - + INVOLVEMENT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND + + INVOLVEMENT_DESC_BOB + TAG_DESC_MONITOR + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, Address.MESSAGE_CONSTRAINTS); // invalid tag assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + INVALID_TAG_DESC + VALID_TAG_FRIEND + + INVOLVEMENT_DESC_BOB + INVALID_TAG_DESC + VALID_TAG_REP + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, Tag.MESSAGE_CONSTRAINTS); // invalid involvement assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVALID_INVOLVEMENT_DESC + TAG_DESC_HUSBAND + TAG_DESC_FRIEND + + INVALID_INVOLVEMENT_DESC + TAG_DESC_MONITOR + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, Involvement.MESSAGE_CONSTRAINTS); // invalid form class assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND + + INVOLVEMENT_DESC_BOB + TAG_DESC_MONITOR + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + INVALID_FORM_CLASS_DESC + GENDER_DESC_BOB, FormClass.MESSAGE_CONSTRAINTS); - // invalid Gender + // invalid emergency contact assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVOLVEMENT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND - + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + INVALID_GENDER_DESC, Gender.MESSAGE_CONSTRAINTS); + + INVOLVEMENT_DESC_BOB + TAG_DESC_MONITOR + TAG_DESC_REP + + INVALID_EMERGENCY_CONTACT_DESC + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, Phone.MESSAGE_CONSTRAINTS); // two invalid values, only first invalid value reported assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB @@ -212,8 +247,8 @@ public void parse_invalidValue_failure() { // non-empty preamble assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_HUSBAND - + TAG_DESC_FRIEND + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, + + ADDRESS_DESC_BOB + INVOLVEMENT_DESC_BOB + TAG_DESC_MONITOR + + TAG_DESC_REP + EMERGENCY_CONTACT_DESC_BOB + FORM_CLASS_DESC_BOB + GENDER_DESC_BOB, String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddStudentCommand.MESSAGE_USAGE)); } } diff --git a/src/test/java/seedu/address/logic/parser/EditStudentCommandParserTest.java b/src/test/java/seedu/address/logic/parser/student/EditStudentCommandParserTest.java similarity index 85% rename from src/test/java/seedu/address/logic/parser/EditStudentCommandParserTest.java rename to src/test/java/seedu/address/logic/parser/student/EditStudentCommandParserTest.java index add26be78a5..e3471d70c7d 100644 --- a/src/test/java/seedu/address/logic/parser/EditStudentCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/student/EditStudentCommandParserTest.java @@ -1,10 +1,11 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.student; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.EMERGENCY_CONTACT_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.FORM_CLASS_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.GENDER_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.INVALID_ADDRESS_DESC; @@ -19,26 +20,27 @@ import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_BOB; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_REP; import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMERGENCY_CONTACT_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_FORM_CLASS_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_REP; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; -import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; -import static seedu.address.testutil.TypicalIndexes.INDEX_THIRD_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_STUDENT; +import static seedu.address.testutil.TypicalIndexes.INDEX_THIRD_STUDENT; import org.junit.jupiter.api.Test; @@ -46,7 +48,6 @@ import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.descriptors.EditStudentDescriptor; import seedu.address.logic.commands.student.EditStudentCommand; -import seedu.address.logic.parser.student.EditStudentCommandParser; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.FormClass; @@ -102,8 +103,9 @@ public void parse_invalidValue_failure() { assertParseFailure(parser, "1" + INVALID_TAG_DESC, Tag.MESSAGE_CONSTRAINTS); // invalid tag assertParseFailure(parser, "1" + INVALID_INVOLVEMENT_DESC, Involvement.MESSAGE_CONSTRAINTS); //invalid involvement - assertParseFailure(parser, "1" + INVALID_FORM_CLASS_DESC, FormClass.MESSAGE_CONSTRAINTS); //invalid form class - assertParseFailure(parser, "1" + INVALID_GENDER_DESC, Gender.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + INVALID_FORM_CLASS_DESC, + FormClass.MESSAGE_CONSTRAINTS); //invalid form class + assertParseFailure(parser, "1" + INVALID_GENDER_DESC, Gender.MESSAGE_CONSTRAINTS); // invalid gender // invalid phone followed by valid email @@ -115,11 +117,11 @@ public void parse_invalidValue_failure() { // while parsing {@code PREFIX_TAG} alone will reset the tags of the {@code Person} being edited, // parsing it together with a valid tag results in error - assertParseFailure(parser, "1" + TAG_DESC_FRIEND + TAG_DESC_HUSBAND + TAG_EMPTY, + assertParseFailure(parser, "1" + TAG_DESC_REP + TAG_DESC_MONITOR + TAG_EMPTY, Tag.MESSAGE_CONSTRAINTS); - assertParseFailure(parser, "1" + TAG_DESC_FRIEND + TAG_EMPTY + TAG_DESC_HUSBAND, + assertParseFailure(parser, "1" + TAG_DESC_REP + TAG_EMPTY + TAG_DESC_MONITOR, Tag.MESSAGE_CONSTRAINTS); - assertParseFailure(parser, "1" + TAG_EMPTY + TAG_DESC_FRIEND + TAG_DESC_HUSBAND, + assertParseFailure(parser, "1" + TAG_EMPTY + TAG_DESC_REP + TAG_DESC_MONITOR, Tag.MESSAGE_CONSTRAINTS); // multiple invalid values, but only the first invalid value is captured @@ -129,13 +131,16 @@ public void parse_invalidValue_failure() { @Test public void parse_allFieldsSpecified_success() { - Index targetIndex = INDEX_SECOND_PERSON; - String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + TAG_DESC_HUSBAND - + EMAIL_DESC_AMY + ADDRESS_DESC_AMY + NAME_DESC_AMY + TAG_DESC_FRIEND; + Index targetIndex = INDEX_SECOND_STUDENT; + String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + TAG_DESC_MONITOR + + EMAIL_DESC_AMY + ADDRESS_DESC_AMY + NAME_DESC_AMY + TAG_DESC_REP + INVOLVEMENT_DESC_AMY + + GENDER_DESC_AMY + FORM_CLASS_DESC_AMY + EMERGENCY_CONTACT_DESC_AMY; EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_AMY) .withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY) - .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build(); + .withGender(VALID_GENDER_AMY).withInvolvement(VALID_INVOLVEMENT_AMY) + .withEmergencyContact(VALID_EMERGENCY_CONTACT_AMY).withFormClass(VALID_FORM_CLASS_AMY) + .withTags(VALID_TAG_MONITOR, VALID_TAG_REP).build(); EditStudentCommand expectedCommand = new EditStudentCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); @@ -143,7 +148,7 @@ public void parse_allFieldsSpecified_success() { @Test public void parse_someFieldsSpecified_success() { - Index targetIndex = INDEX_FIRST_PERSON; + Index targetIndex = INDEX_FIRST_STUDENT; String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + EMAIL_DESC_AMY; EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withPhone(VALID_PHONE_BOB) @@ -156,7 +161,7 @@ public void parse_someFieldsSpecified_success() { @Test public void parse_oneFieldSpecified_success() { // name - Index targetIndex = INDEX_THIRD_PERSON; + Index targetIndex = INDEX_THIRD_STUDENT; String userInput = targetIndex.getOneBased() + NAME_DESC_AMY; EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_AMY).build(); EditStudentCommand expectedCommand = new EditStudentCommand(targetIndex, descriptor); @@ -198,24 +203,30 @@ public void parse_oneFieldSpecified_success() { expectedCommand = new EditStudentCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); + // emergency contact + userInput = targetIndex.getOneBased() + EMERGENCY_CONTACT_DESC_AMY; + descriptor = new EditStudentDescriptorBuilder().withEmergencyContact(VALID_EMERGENCY_CONTACT_AMY).build(); + expectedCommand = new EditStudentCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + // tags - userInput = targetIndex.getOneBased() + TAG_DESC_FRIEND; - descriptor = new EditStudentDescriptorBuilder().withTags(VALID_TAG_FRIEND).build(); + userInput = targetIndex.getOneBased() + TAG_DESC_REP; + descriptor = new EditStudentDescriptorBuilder().withTags(VALID_TAG_REP).build(); expectedCommand = new EditStudentCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @Test public void parse_multipleRepeatedFields_acceptsLast() { - Index targetIndex = INDEX_FIRST_PERSON; + Index targetIndex = INDEX_FIRST_STUDENT; String userInput = targetIndex.getOneBased() + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY - + TAG_DESC_FRIEND + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY + TAG_DESC_FRIEND - + PHONE_DESC_BOB + ADDRESS_DESC_BOB + EMAIL_DESC_BOB + TAG_DESC_HUSBAND; + + TAG_DESC_REP + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY + TAG_DESC_REP + + PHONE_DESC_BOB + ADDRESS_DESC_BOB + EMAIL_DESC_BOB + TAG_DESC_MONITOR; EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withPhone(VALID_PHONE_BOB) - .withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_FRIEND, VALID_TAG_HUSBAND) + .withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_REP, VALID_TAG_MONITOR) .build(); - EditCommand expectedCommand = new EditStudentCommand(targetIndex, descriptor); + EditStudentCommand expectedCommand = new EditStudentCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @@ -223,7 +234,7 @@ public void parse_multipleRepeatedFields_acceptsLast() { @Test public void parse_invalidValueFollowedByValidValue_success() { // no other valid values specified - Index targetIndex = INDEX_FIRST_PERSON; + Index targetIndex = INDEX_FIRST_STUDENT; String userInput = targetIndex.getOneBased() + INVALID_PHONE_DESC + PHONE_DESC_BOB; EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withPhone(VALID_PHONE_BOB).build(); EditCommand expectedCommand = new EditStudentCommand(targetIndex, descriptor); @@ -240,7 +251,7 @@ public void parse_invalidValueFollowedByValidValue_success() { @Test public void parse_resetTags_success() { - Index targetIndex = INDEX_THIRD_PERSON; + Index targetIndex = INDEX_THIRD_STUDENT; String userInput = targetIndex.getOneBased() + TAG_EMPTY; EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withTags().build(); diff --git a/src/test/java/seedu/address/logic/parser/student/MedicalHistoryCommandParserTest.java b/src/test/java/seedu/address/logic/parser/student/MedicalHistoryCommandParserTest.java index 1b48280602f..c477890ac2f 100644 --- a/src/test/java/seedu/address/logic/parser/student/MedicalHistoryCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/student/MedicalHistoryCommandParserTest.java @@ -4,7 +4,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_MEDICAL_HISTORY; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; import org.junit.jupiter.api.Test; @@ -19,15 +19,15 @@ public class MedicalHistoryCommandParserTest { @Test public void parse_indexSpecified_success() { // have MedicalHistory - Index targetIndex = INDEX_FIRST_PERSON; + Index targetIndex = INDEX_FIRST_STUDENT; String userInput = targetIndex.getOneBased() + " " + PREFIX_MEDICAL_HISTORY + nonEmptyMedicalHistory; - MedicalHistoryCommand expectedCommand = new MedicalHistoryCommand(INDEX_FIRST_PERSON, + MedicalHistoryCommand expectedCommand = new MedicalHistoryCommand(INDEX_FIRST_STUDENT, new MedicalHistory(nonEmptyMedicalHistory)); assertParseSuccess(parser, userInput, expectedCommand); // no MedicalHistory userInput = targetIndex.getOneBased() + " " + PREFIX_MEDICAL_HISTORY; - expectedCommand = new MedicalHistoryCommand(INDEX_FIRST_PERSON, new MedicalHistory("")); + expectedCommand = new MedicalHistoryCommand(INDEX_FIRST_STUDENT, new MedicalHistory("")); assertParseSuccess(parser, userInput, expectedCommand); } diff --git a/src/test/java/seedu/address/logic/parser/teacher/AddTeacherCommandParserTest.java b/src/test/java/seedu/address/logic/parser/teacher/AddTeacherCommandParserTest.java new file mode 100644 index 00000000000..26eef5c7a2e --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/teacher/AddTeacherCommandParserTest.java @@ -0,0 +1,196 @@ +package seedu.address.logic.parser.teacher; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.GENDER_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.GENDER_DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_GENDER_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_INVOLVEMENT_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_OFFICE_TABLE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_PHONE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVOLVEMENT_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.INVOLVEMENT_DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.OFFICE_TABLE_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.OFFICE_TABLE_DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY; +import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_WHITESPACE; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_REP; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_OFFICE_TABLE_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_REP; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; +import static seedu.address.testutil.TypicalPersons.CHO; +import static seedu.address.testutil.TypicalPersons.DEE; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.teacher.AddTeacherCommand; +import seedu.address.model.person.Email; +import seedu.address.model.person.Gender; +import seedu.address.model.person.Involvement; +import seedu.address.model.person.Name; +import seedu.address.model.person.OfficeTable; +import seedu.address.model.person.Phone; +import seedu.address.model.person.Teacher; +import seedu.address.model.tag.Tag; +import seedu.address.testutil.TeacherBuilder; + +public class AddTeacherCommandParserTest { + private AddTeacherCommandParser parser = new AddTeacherCommandParser(); + + @Test + public void parse_allFieldsPresent_success() { + Teacher expectedTeacher = new TeacherBuilder(DEE).withTags(VALID_TAG_REP).build(); + + // whitespace only preamble + assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + + GENDER_DESC_DEE + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + TAG_DESC_REP, + new AddTeacherCommand(expectedTeacher)); + + // multiple names - last name accepted + assertParseSuccess(parser, NAME_DESC_CHO + NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + + GENDER_DESC_DEE + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + TAG_DESC_REP, + new AddTeacherCommand(expectedTeacher)); + + // multiple phones - last phone accepted + assertParseSuccess(parser, NAME_DESC_DEE + PHONE_DESC_CHO + PHONE_DESC_DEE + EMAIL_DESC_DEE + + GENDER_DESC_DEE + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + TAG_DESC_REP, + new AddTeacherCommand(expectedTeacher)); + + // multiple emails - last email accepted + assertParseSuccess(parser, NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_CHO + + EMAIL_DESC_DEE + GENDER_DESC_DEE + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + TAG_DESC_REP, + new AddTeacherCommand(expectedTeacher)); + + // multiple genders - last address accepted + assertParseSuccess(parser, NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + GENDER_DESC_CHO + + GENDER_DESC_DEE + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + TAG_DESC_REP, + new AddTeacherCommand(expectedTeacher)); + + // multiple tags - all accepted + Teacher expectedTeacherMultipleTags = new TeacherBuilder(DEE).withTags(VALID_TAG_REP, VALID_TAG_MONITOR) + .build(); + assertParseSuccess(parser, NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + GENDER_DESC_DEE + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + TAG_DESC_MONITOR + TAG_DESC_REP, + new AddTeacherCommand(expectedTeacherMultipleTags)); + } + + @Test + public void parse_optionalFieldsMissing_success() { + // zero tags + Teacher expectedTeacher = new TeacherBuilder(CHO).withTags().build(); + assertParseSuccess(parser, + NAME_DESC_CHO + PHONE_DESC_CHO + EMAIL_DESC_CHO + GENDER_DESC_CHO + + INVOLVEMENT_DESC_CHO + OFFICE_TABLE_DESC_CHO, new AddTeacherCommand(expectedTeacher)); + } + + @Test + public void parse_compulsoryFieldMissing_failure() { + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTeacherCommand.MESSAGE_USAGE); + + // missing name prefix + assertParseFailure(parser, + VALID_NAME_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + GENDER_DESC_DEE + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE, + expectedMessage); + + // missing phone prefix + assertParseFailure(parser, + NAME_DESC_DEE + VALID_PHONE_DEE + EMAIL_DESC_DEE + GENDER_DESC_DEE + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE, + expectedMessage); + + // missing email prefix + assertParseFailure(parser, + NAME_DESC_DEE + PHONE_DESC_DEE + VALID_EMAIL_DEE + GENDER_DESC_DEE + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE, + expectedMessage); + + // missing gender prefix + assertParseFailure(parser, + NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + VALID_GENDER_DEE + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE, + expectedMessage); + + // missing involvement prefix + assertParseFailure(parser, + NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + GENDER_DESC_DEE + + VALID_INVOLVEMENT_DEE + OFFICE_TABLE_DESC_DEE, + expectedMessage); + + // missing office table prefix + assertParseFailure(parser, + NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + GENDER_DESC_DEE + + INVOLVEMENT_DESC_DEE + VALID_OFFICE_TABLE_DEE, + expectedMessage); + + // all prefixes missing + assertParseFailure(parser, + VALID_NAME_DEE + VALID_PHONE_DEE + VALID_EMAIL_DEE + VALID_GENDER_DEE + + VALID_INVOLVEMENT_DEE + VALID_OFFICE_TABLE_DEE, + expectedMessage); + } + + @Test + public void parse_invalidValue_failure() { + // invalid name + assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_DEE + EMAIL_DESC_DEE + GENDER_DESC_DEE + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + + TAG_DESC_MONITOR + TAG_DESC_REP, Name.MESSAGE_CONSTRAINTS); + + // invalid phone + assertParseFailure(parser, NAME_DESC_DEE + INVALID_PHONE_DESC + EMAIL_DESC_DEE + GENDER_DESC_DEE + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + + TAG_DESC_MONITOR + TAG_DESC_REP, Phone.MESSAGE_CONSTRAINTS); + + // invalid email + assertParseFailure(parser, NAME_DESC_DEE + PHONE_DESC_DEE + INVALID_EMAIL_DESC + GENDER_DESC_DEE + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + + TAG_DESC_MONITOR + TAG_DESC_REP, Email.MESSAGE_CONSTRAINTS); + + // invalid gender + assertParseFailure(parser, NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + INVALID_GENDER_DESC + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + + TAG_DESC_MONITOR + TAG_DESC_REP, Gender.MESSAGE_CONSTRAINTS); + + // invalid involvement + assertParseFailure(parser, NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + GENDER_DESC_DEE + + INVALID_INVOLVEMENT_DESC + OFFICE_TABLE_DESC_DEE + + TAG_DESC_MONITOR + TAG_DESC_REP, Involvement.MESSAGE_CONSTRAINTS); + + // invalid office table number + assertParseFailure(parser, NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + GENDER_DESC_DEE + + INVOLVEMENT_DESC_DEE + INVALID_OFFICE_TABLE_DESC + + TAG_DESC_MONITOR + TAG_DESC_REP, OfficeTable.MESSAGE_CONSTRAINTS); + + // invalid tag + assertParseFailure(parser, NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + GENDER_DESC_DEE + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + + INVALID_TAG_DESC + TAG_DESC_REP, Tag.MESSAGE_CONSTRAINTS); + + // two invalid values, only first invalid value reported + assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_DEE + EMAIL_DESC_DEE + INVALID_GENDER_DESC + + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + + TAG_DESC_MONITOR + TAG_DESC_REP, Name.MESSAGE_CONSTRAINTS); + + // non-empty preamble + assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_DEE + PHONE_DESC_DEE + EMAIL_DESC_DEE + + GENDER_DESC_DEE + INVOLVEMENT_DESC_DEE + OFFICE_TABLE_DESC_DEE + TAG_DESC_MONITOR + TAG_DESC_REP, + String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTeacherCommand.MESSAGE_USAGE)); + } +} diff --git a/src/test/java/seedu/address/logic/parser/teacher/EditTeacherCommandParserTest.java b/src/test/java/seedu/address/logic/parser/teacher/EditTeacherCommandParserTest.java new file mode 100644 index 00000000000..e086b781cdc --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/teacher/EditTeacherCommandParserTest.java @@ -0,0 +1,241 @@ +package seedu.address.logic.parser.teacher; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.GENDER_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_GENDER_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_INVOLVEMENT_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_OFFICE_TABLE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_PHONE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVOLVEMENT_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.OFFICE_TABLE_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.OFFICE_TABLE_DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_CHO; +import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_DEE; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_REP; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_OFFICE_TABLE_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_OFFICE_TABLE_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_REP; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_TEACHER; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_TEACHER; +import static seedu.address.testutil.TypicalIndexes.INDEX_THIRD_TEACHER; + +import org.junit.jupiter.api.Test; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.commands.descriptors.EditTeacherDescriptor; +import seedu.address.logic.commands.teacher.EditTeacherCommand; +import seedu.address.model.person.Email; +import seedu.address.model.person.Gender; +import seedu.address.model.person.Involvement; +import seedu.address.model.person.Name; +import seedu.address.model.person.OfficeTable; +import seedu.address.model.person.Phone; +import seedu.address.model.tag.Tag; +import seedu.address.testutil.EditTeacherDescriptorBuilder; + +public class EditTeacherCommandParserTest { + + private static final String TAG_EMPTY = " " + PREFIX_TAG; + + private static final String MESSAGE_INVALID_FORMAT = + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditTeacherCommand.MESSAGE_USAGE); + + private EditTeacherCommandParser parser = new EditTeacherCommandParser(); + + @Test + public void parse_missingParts_failure() { + // no index specified + assertParseFailure(parser, VALID_NAME_CHO, MESSAGE_INVALID_FORMAT); + + // no field specified + assertParseFailure(parser, "1", EditCommand.MESSAGE_NOT_EDITED); + + // no index and no field specified + assertParseFailure(parser, "", MESSAGE_INVALID_FORMAT); + } + + @Test + public void parse_invalidPreamble_failure() { + // negative index + assertParseFailure(parser, "-5" + NAME_DESC_CHO, MESSAGE_INVALID_FORMAT); + + // zero index + assertParseFailure(parser, "0" + NAME_DESC_CHO, MESSAGE_INVALID_FORMAT); + + // invalid arguments being parsed as preamble + assertParseFailure(parser, "1 some random string", MESSAGE_INVALID_FORMAT); + + // invalid prefix being parsed as preamble + assertParseFailure(parser, "1 b/ string", MESSAGE_INVALID_FORMAT); + } + + @Test + public void parse_invalidValue_failure() { + assertParseFailure(parser, "1" + INVALID_NAME_DESC, Name.MESSAGE_CONSTRAINTS); // invalid name + assertParseFailure(parser, "1" + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); // invalid phone + assertParseFailure(parser, "1" + INVALID_EMAIL_DESC, Email.MESSAGE_CONSTRAINTS); // invalid email + assertParseFailure(parser, "1" + INVALID_GENDER_DESC, Gender.MESSAGE_CONSTRAINTS); // invalid gender + assertParseFailure(parser, "1" + INVALID_TAG_DESC, Tag.MESSAGE_CONSTRAINTS); // invalid tag + assertParseFailure(parser, "1" + INVALID_OFFICE_TABLE_DESC, + OfficeTable.MESSAGE_CONSTRAINTS); // invalid office table number + assertParseFailure(parser, "1" + INVALID_INVOLVEMENT_DESC, + Involvement.MESSAGE_CONSTRAINTS); //invalid involvement + + // invalid phone followed by valid email + assertParseFailure(parser, "1" + INVALID_PHONE_DESC + EMAIL_DESC_CHO, Phone.MESSAGE_CONSTRAINTS); + + // valid phone followed by invalid phone. The test case for invalid phone followed by valid phone + // is tested at {@code parse_invalidValueFollowedByValidValue_success()} + assertParseFailure(parser, "1" + PHONE_DESC_DEE + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); + + // while parsing {@code PREFIX_TAG} alone will reset the tags of the {@code Person} being edited, + // parsing it together with a valid tag results in error + assertParseFailure(parser, "1" + TAG_DESC_REP + TAG_DESC_MONITOR + TAG_EMPTY, + Tag.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + TAG_DESC_REP + TAG_EMPTY + TAG_DESC_MONITOR, + Tag.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + TAG_EMPTY + TAG_DESC_REP + TAG_DESC_MONITOR, + Tag.MESSAGE_CONSTRAINTS); + + // multiple invalid values, but only the first invalid value is captured + assertParseFailure(parser, "1" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_OFFICE_TABLE_CHO + + VALID_PHONE_CHO, Name.MESSAGE_CONSTRAINTS); + } + + @Test + public void parse_allFieldsSpecified_success() { + Index targetIndex = INDEX_SECOND_TEACHER; + String userInput = targetIndex.getOneBased() + PHONE_DESC_DEE + TAG_DESC_MONITOR + + EMAIL_DESC_CHO + NAME_DESC_CHO + TAG_DESC_REP + OFFICE_TABLE_DESC_CHO + + INVOLVEMENT_DESC_CHO + GENDER_DESC_CHO; + + EditTeacherDescriptor descriptor = new EditTeacherDescriptorBuilder().withName(VALID_NAME_CHO) + .withPhone(VALID_PHONE_DEE).withEmail(VALID_EMAIL_CHO).withGender(VALID_GENDER_CHO) + .withInvolvement(VALID_INVOLVEMENT_CHO).withOfficeTable(VALID_OFFICE_TABLE_CHO) + .withTags(VALID_TAG_MONITOR, VALID_TAG_REP).build(); + EditTeacherCommand expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_someFieldsSpecified_success() { + Index targetIndex = INDEX_FIRST_TEACHER; + String userInput = targetIndex.getOneBased() + PHONE_DESC_DEE + EMAIL_DESC_CHO; + + EditTeacherDescriptor descriptor = new EditTeacherDescriptorBuilder().withPhone(VALID_PHONE_DEE) + .withEmail(VALID_EMAIL_CHO).build(); + EditTeacherCommand expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_oneFieldSpecified_success() { + // name + Index targetIndex = INDEX_THIRD_TEACHER; + String userInput = targetIndex.getOneBased() + NAME_DESC_CHO; + EditTeacherDescriptor descriptor = new EditTeacherDescriptorBuilder().withName(VALID_NAME_CHO).build(); + EditTeacherCommand expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + + // phone + userInput = targetIndex.getOneBased() + PHONE_DESC_CHO; + descriptor = new EditTeacherDescriptorBuilder().withPhone(VALID_PHONE_CHO).build(); + expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + + // email + userInput = targetIndex.getOneBased() + EMAIL_DESC_CHO; + descriptor = new EditTeacherDescriptorBuilder().withEmail(VALID_EMAIL_CHO).build(); + expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + + // involvement + userInput = targetIndex.getOneBased() + INVOLVEMENT_DESC_CHO; + descriptor = new EditTeacherDescriptorBuilder().withInvolvement(VALID_INVOLVEMENT_CHO).build(); + expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + + // office table number + userInput = targetIndex.getOneBased() + OFFICE_TABLE_DESC_CHO; + descriptor = new EditTeacherDescriptorBuilder().withOfficeTable(VALID_OFFICE_TABLE_CHO).build(); + expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + + // gender + userInput = targetIndex.getOneBased() + GENDER_DESC_CHO; + descriptor = new EditTeacherDescriptorBuilder().withGender(VALID_GENDER_CHO).build(); + expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + + // tags + userInput = targetIndex.getOneBased() + TAG_DESC_REP; + descriptor = new EditTeacherDescriptorBuilder().withTags(VALID_TAG_REP).build(); + expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_multipleRepeatedFields_acceptsLast() { + Index targetIndex = INDEX_FIRST_TEACHER; + String userInput = targetIndex.getOneBased() + PHONE_DESC_CHO + EMAIL_DESC_CHO + OFFICE_TABLE_DESC_CHO + + TAG_DESC_REP + PHONE_DESC_CHO + OFFICE_TABLE_DESC_CHO + EMAIL_DESC_CHO + TAG_DESC_REP + + PHONE_DESC_CHO + EMAIL_DESC_CHO + TAG_DESC_MONITOR; + + EditTeacherDescriptor descriptor = new EditTeacherDescriptorBuilder().withPhone(VALID_PHONE_CHO) + .withEmail(VALID_EMAIL_CHO).withOfficeTable(VALID_OFFICE_TABLE_CHO) + .withTags(VALID_TAG_REP, VALID_TAG_MONITOR).build(); + EditCommand expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_invalidValueFollowedByValidValue_success() { + // no other valid values specified + Index targetIndex = INDEX_FIRST_TEACHER; + String userInput = targetIndex.getOneBased() + INVALID_PHONE_DESC + PHONE_DESC_DEE; + EditTeacherDescriptor descriptor = new EditTeacherDescriptorBuilder().withPhone(VALID_PHONE_DEE).build(); + EditTeacherCommand expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + + // other valid values specified + userInput = targetIndex.getOneBased() + EMAIL_DESC_DEE + INVALID_PHONE_DESC + OFFICE_TABLE_DESC_DEE + + PHONE_DESC_DEE; + descriptor = new EditTeacherDescriptorBuilder().withPhone(VALID_PHONE_DEE).withEmail(VALID_EMAIL_DEE) + .withOfficeTable(VALID_OFFICE_TABLE_DEE).build(); + expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_resetTags_success() { + Index targetIndex = INDEX_THIRD_TEACHER; + String userInput = targetIndex.getOneBased() + TAG_EMPTY; + + EditTeacherDescriptor descriptor = new EditTeacherDescriptorBuilder().withTags().build(); + EditTeacherCommand expectedCommand = new EditTeacherCommand(targetIndex, descriptor); + + assertParseSuccess(parser, userInput, expectedCommand); + } +} diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index 8c23de72397..b76c60e4df5 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -3,10 +3,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalStudents.ALICE; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.util.Arrays; import java.util.Collection; @@ -46,7 +46,7 @@ public void resetData_withValidReadOnlyAddressBook_replacesData() { public void resetData_withDuplicatePersons_throwsDuplicatePersonException() { // Two persons with the same identity fields //same name and address = same person - Person editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_HUSBAND) + Person editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_MONITOR) .build(); List newPersons = Arrays.asList(ALICE, editedAlice); AddressBookStub newData = new AddressBookStub(newPersons); @@ -74,7 +74,7 @@ public void hasPerson_personInAddressBook_returnsTrue() { public void hasPerson_personWithSameIdentityFieldsInAddressBook_returnsTrue() { //same name and address = same person addressBook.addPerson(ALICE); - Person editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_HUSBAND) + Person editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_MONITOR) .build(); assertTrue(addressBook.hasPerson(editedAlice)); } diff --git a/src/test/java/seedu/address/model/ModelManagerTest.java b/src/test/java/seedu/address/model/ModelManagerTest.java index 22032b8c630..2cf1418d116 100644 --- a/src/test/java/seedu/address/model/ModelManagerTest.java +++ b/src/test/java/seedu/address/model/ModelManagerTest.java @@ -5,8 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalStudents.ALICE; -import static seedu.address.testutil.TypicalStudents.BENSON; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.BENSON; import java.nio.file.Path; import java.nio.file.Paths; diff --git a/src/test/java/seedu/address/model/person/OfficeTableTest.java b/src/test/java/seedu/address/model/person/OfficeTableTest.java new file mode 100644 index 00000000000..c8306f9b88b --- /dev/null +++ b/src/test/java/seedu/address/model/person/OfficeTableTest.java @@ -0,0 +1,38 @@ +package seedu.address.model.person; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + +public class OfficeTableTest { + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new OfficeTable(null)); + } + + @Test + public void constructor_invalidOfficeTable_throwsIllegalArgumentException() { + String invalidOfficeTable = ""; + assertThrows(IllegalArgumentException.class, () -> new OfficeTable(invalidOfficeTable)); + } + + @Test + public void isValidOfficeTable() { + // null office table number + assertThrows(NullPointerException.class, () -> OfficeTable.isValidTable(null)); + + // invalid office table numbers + assertFalse(OfficeTable.isValidTable("")); // empty string + assertFalse(OfficeTable.isValidTable(" ")); // spaces only + assertFalse(OfficeTable.isValidTable("table")); // non-numeric + assertFalse(OfficeTable.isValidTable("12d")); // alphabets within digits + assertFalse(OfficeTable.isValidTable("1 2")); // spaces within digits + + // valid office table numbers + assertTrue(OfficeTable.isValidTable("2")); // short table numbers + assertTrue(OfficeTable.isValidTable("124293842033123")); // long table numbers + } +} diff --git a/src/test/java/seedu/address/model/person/StudentTest.java b/src/test/java/seedu/address/model/person/StudentTest.java index aff466421a4..e5b4a708c95 100644 --- a/src/test/java/seedu/address/model/person/StudentTest.java +++ b/src/test/java/seedu/address/model/person/StudentTest.java @@ -4,12 +4,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMERGENCY_CONTACT_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_FORM_CLASS_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_BOB; 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_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalStudents.ALICE; -import static seedu.address.testutil.TypicalStudents.BOB; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.BOB; import org.junit.jupiter.api.Test; @@ -33,7 +37,9 @@ public void isSameStudent() { // same name, all other attributes different -> returns true Student editedAlice = new StudentBuilder(ALICE).withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB) - .withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND).build(); + .withGender(VALID_GENDER_BOB).withInvolvement(VALID_INVOLVEMENT_BOB) + .withFormClass(VALID_FORM_CLASS_BOB).withAddress(VALID_ADDRESS_BOB) + .withEmergencyContact(VALID_EMERGENCY_CONTACT_BOB).withTags(VALID_TAG_MONITOR).build(); assertTrue(ALICE.isSamePerson(editedAlice)); // different name, all other attributes same -> returns true @@ -80,12 +86,28 @@ public void equals() { editedAlice = new StudentBuilder(ALICE).withEmail(VALID_EMAIL_BOB).build(); assertFalse(ALICE.equals(editedAlice)); + // different gender -> returns false + editedAlice = new StudentBuilder(ALICE).withGender(VALID_GENDER_BOB).build(); + assertFalse(ALICE.equals(editedAlice)); + + // different involvement -> returns false + editedAlice = new StudentBuilder(ALICE).withInvolvement(VALID_INVOLVEMENT_BOB).build(); + assertFalse(ALICE.equals(editedAlice)); + // different address -> returns false editedAlice = new StudentBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).build(); assertFalse(ALICE.equals(editedAlice)); + // different form class -> returns false + editedAlice = new StudentBuilder(ALICE).withFormClass(VALID_FORM_CLASS_BOB).build(); + assertFalse(ALICE.equals(editedAlice)); + + //different emergency contact -> returns false + editedAlice = new StudentBuilder(ALICE).withEmergencyContact(VALID_EMERGENCY_CONTACT_BOB).build(); + assertFalse(ALICE.equals(editedAlice)); + // different tags -> returns false - editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_HUSBAND).build(); + editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_MONITOR).build(); assertFalse(ALICE.equals(editedAlice)); } } diff --git a/src/test/java/seedu/address/model/person/TeacherTest.java b/src/test/java/seedu/address/model/person/TeacherTest.java new file mode 100644 index 00000000000..95420e519e2 --- /dev/null +++ b/src/test/java/seedu/address/model/person/TeacherTest.java @@ -0,0 +1,102 @@ +package seedu.address.model.person; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_OFFICE_TABLE_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_REP; +import static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalPersons.ALI; +import static seedu.address.testutil.TypicalPersons.DEE; + +import org.junit.jupiter.api.Test; + +import seedu.address.testutil.TeacherBuilder; + +public class TeacherTest { + + @Test + public void asObservableList_modifyList_throwsUnsupportedOperationException() { + Teacher teacher = new TeacherBuilder().build(); + assertThrows(UnsupportedOperationException.class, () -> teacher.getTags().remove(0)); + } + + @Test + public void isSameTeacher() { + // same object -> returns true + assertTrue(ALI.isSamePerson(ALI)); + + // null -> returns false + assertFalse(ALI.isSamePerson(null)); + + // same name, all other attributes different -> returns true + Teacher editedAli = new TeacherBuilder(ALI).withPhone(VALID_PHONE_DEE).withEmail(VALID_EMAIL_DEE) + .withGender(VALID_GENDER_DEE).withInvolvement(VALID_INVOLVEMENT_DEE) + .withTags(VALID_TAG_REP).build(); + assertTrue(ALI.isSamePerson(editedAli)); + + // different name, all other attributes same -> returns true + editedAli = new TeacherBuilder(ALI).withName(VALID_NAME_DEE).build(); + assertFalse(ALI.isSamePerson(editedAli)); + + // name differs in case, all other attributes same -> returns false + Teacher editedDee = new TeacherBuilder(DEE).withName(VALID_NAME_DEE.toLowerCase()).build(); + assertFalse(DEE.isSamePerson(editedDee)); + + // name has trailing spaces, all other attributes same -> returns false + String nameWithTrailingSpaces = VALID_NAME_DEE + " "; + editedDee = new TeacherBuilder(DEE).withName(nameWithTrailingSpaces).build(); + assertFalse(DEE.isSamePerson(editedDee)); + } + + @Test + public void equals() { + // same values -> returns true + Teacher aliCopy = new TeacherBuilder(ALI).build(); + assertTrue(ALI.equals(aliCopy)); + + // same object -> returns true + assertTrue(ALI.equals(ALI)); + + // null -> returns false + assertFalse(ALI.equals(null)); + + // different type -> returns false + assertFalse(ALI.equals(5)); + + // different person -> returns false + assertFalse(ALI.equals(DEE)); + + // different name -> returns false + Teacher editedAli = new TeacherBuilder(ALI).withName(VALID_NAME_DEE).build(); + assertFalse(ALI.equals(editedAli)); + + // different phone -> returns false + editedAli = new TeacherBuilder(ALI).withPhone(VALID_PHONE_DEE).build(); + assertFalse(ALI.equals(editedAli)); + + // different email -> returns false + editedAli = new TeacherBuilder(ALI).withEmail(VALID_EMAIL_DEE).build(); + assertFalse(ALI.equals(editedAli)); + + // different gender -> returns false + editedAli = new TeacherBuilder(ALI).withGender(VALID_GENDER_DEE).build(); + assertFalse(ALI.equals(editedAli)); + + // different involvement -> returns false + editedAli = new TeacherBuilder(ALI).withInvolvement(VALID_INVOLVEMENT_DEE).build(); + assertFalse(ALI.equals(editedAli)); + + // different office table number -> returns false + editedAli = new TeacherBuilder(ALI).withOfficeTable(VALID_OFFICE_TABLE_DEE).build(); + assertFalse(ALI.equals(editedAli)); + + // different tags -> returns false + editedAli = new TeacherBuilder(ALI).withTags(VALID_TAG_REP).build(); + assertFalse(ALI.equals(editedAli)); + } +} diff --git a/src/test/java/seedu/address/model/person/UniquePersonListTest.java b/src/test/java/seedu/address/model/person/UniquePersonListTest.java index 22281ef1877..294de64b276 100644 --- a/src/test/java/seedu/address/model/person/UniquePersonListTest.java +++ b/src/test/java/seedu/address/model/person/UniquePersonListTest.java @@ -4,10 +4,10 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalStudents.ALICE; -import static seedu.address.testutil.TypicalStudents.BOB; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.BOB; import java.util.Arrays; import java.util.Collections; @@ -42,7 +42,7 @@ public void contains_personInList_returnsTrue() { @Test public void contains_personWithSameIdentityFieldsInList_returnsTrue() { uniquePersonList.add(ALICE); - Person editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_HUSBAND) + Person editedAlice = new StudentBuilder(ALICE).withTags(VALID_TAG_MONITOR) .build(); assertTrue(uniquePersonList.contains(editedAlice)); } @@ -85,7 +85,7 @@ public void setPerson_editedPersonIsSamePerson_success() { @Test public void setPerson_editedPersonHasSameIdentity_success() { uniquePersonList.add(ALICE); - Person editedAlice = new StudentBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND) + Person editedAlice = new StudentBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_MONITOR) .build(); uniquePersonList.setPerson(ALICE, editedAlice); UniquePersonList expectedUniquePersonList = new UniquePersonList(); diff --git a/src/test/java/seedu/address/storage/JsonAdaptedStudentTest.java b/src/test/java/seedu/address/storage/JsonAdaptedStudentTest.java index b096036f58d..1f5f4823777 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedStudentTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedStudentTest.java @@ -3,7 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static seedu.address.storage.JsonAdaptedStudent.MISSING_FIELD_MESSAGE_FORMAT; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalStudents.BENSON; +import static seedu.address.testutil.TypicalPersons.BENSON; import java.util.ArrayList; import java.util.List; @@ -27,9 +27,9 @@ public class JsonAdaptedStudentTest { private static final String INVALID_ADDRESS = " "; private static final String INVALID_EMAIL = "example.com"; private static final String INVALID_INVOLVEMENT = " "; - private static final String INVALID_TAG = "#friend"; private static final String INVALID_FORM_CLASS = " 4E1"; private static final String INVALID_GENDER = "WASD"; + private static final String INVALID_TAG = "#friend"; private static final String VALID_NAME = BENSON.getName().toString(); private static final String VALID_PHONE = BENSON.getPhone().toString(); @@ -37,104 +37,105 @@ public class JsonAdaptedStudentTest { private static final String VALID_ADDRESS = BENSON.getAddress().toString(); private static final String VALID_INVOLVEMENT = BENSON.getInvolvement().toString(); private static final String VALID_FORM_CLASS = BENSON.getFormClass().toString(); - private static final List VALID_TAGS = BENSON.getTags().stream() - .map(JsonAdaptedTag::new) - .collect(Collectors.toList()); private static final String VALID_GENDER = BENSON.getGender().toString(); private static final String VALID_MEDICAL_HISTORY = BENSON.getMedicalHistory().toString(); + private static final List VALID_TAGS = BENSON.getTags().stream() + .map(JsonAdaptedTag::new) + .collect(Collectors.toList()); + @Test public void toModelType_validStudentDetails_returnsStudent() throws Exception { - JsonAdaptedStudent person = new JsonAdaptedStudent(BENSON); - assertEquals(BENSON, person.toModelType()); + JsonAdaptedStudent student = new JsonAdaptedStudent(BENSON); + assertEquals(BENSON, student.toModelType()); } @Test public void toModelType_invalidName_throwsIllegalValueException() { - JsonAdaptedStudent student = - new JsonAdaptedStudent(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, - VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = Name.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_nullName_throwsIllegalValueException() { - JsonAdaptedStudent student = new JsonAdaptedStudent(null, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(null, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_invalidPhone_throwsIllegalValueException() { - JsonAdaptedStudent student = - new JsonAdaptedStudent(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, - VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = Phone.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_nullPhone_throwsIllegalValueException() { - JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, null, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_invalidEmail_throwsIllegalValueException() { - JsonAdaptedStudent student = - new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, - VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = Email.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_nullEmail_throwsIllegalValueException() { - JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, null, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_invalidAddress_throwsIllegalValueException() { - JsonAdaptedStudent student = - new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, - VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, INVALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = Address.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_nullAddress_throwsIllegalValueException() { - JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, null, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_invalidInvolvement_throwsIllegalValueException() { - JsonAdaptedStudent student = - new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - INVALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, - VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + INVALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = Involvement.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_nullInvolvement_throwsIllegalValueException() { - JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - null, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + null, VALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Involvement.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @@ -143,75 +144,69 @@ public void toModelType_nullInvolvement_throwsIllegalValueException() { public void toModelType_invalidTags_throwsIllegalValueException() { List invalidTags = new ArrayList<>(VALID_TAGS); invalidTags.add(new JsonAdaptedTag(INVALID_TAG)); - JsonAdaptedStudent student = - new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, INVALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, - VALID_MEDICAL_HISTORY); + + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, invalidTags); assertThrows(IllegalValueException.class, student::toModelType); } @Test public void toModelType_invalidEmergencyContact_throwsIllegalValueException() { - List invalidTags = new ArrayList<>(VALID_TAGS); - invalidTags.add(new JsonAdaptedTag(INVALID_TAG)); - JsonAdaptedStudent student = - new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, INVALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, - VALID_MEDICAL_HISTORY); - assertThrows(IllegalValueException.class, student::toModelType); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, INVALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = Phone.MESSAGE_CONSTRAINTS; + assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_nullEmergencyContact_throwsIllegalValueException() { - List invalidTags = new ArrayList<>(VALID_TAGS); - invalidTags.add(new JsonAdaptedTag(INVALID_TAG)); - JsonAdaptedStudent student = - new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, null, VALID_FORM_CLASS, VALID_GENDER, - VALID_MEDICAL_HISTORY); - assertThrows(IllegalValueException.class, student::toModelType); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, null, + VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); + assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_invalidFormClass_throwsIllegalValueException() { - JsonAdaptedStudent student = - new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, INVALID_FORM_CLASS, VALID_GENDER, - VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, INVALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = FormClass.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_nullFormClass_throwsIllegalValueException() { - JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, null, VALID_GENDER, VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, null, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, FormClass.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_invalidGender_throwsIllegalValueException() { - JsonAdaptedStudent student = - new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, INVALID_GENDER, - VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, INVALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = Gender.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_nullGender_throwsIllegalValueException() { - JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, null, VALID_MEDICAL_HISTORY); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, + VALID_INVOLVEMENT, VALID_ADDRESS, INVALID_PHONE, VALID_FORM_CLASS, VALID_MEDICAL_HISTORY, VALID_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Gender.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } @Test public void toModelType_nullMedicalHistory_throwsIllegalValueException() { - JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_INVOLVEMENT, VALID_TAGS, VALID_PHONE, VALID_FORM_CLASS, VALID_GENDER, null); + JsonAdaptedStudent student = new JsonAdaptedStudent(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_INVOLVEMENT, VALID_ADDRESS, VALID_PHONE, VALID_FORM_CLASS, null, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, MedicalHistory.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, student::toModelType); } diff --git a/src/test/java/seedu/address/storage/JsonAddressBookStorageTest.java b/src/test/java/seedu/address/storage/JsonAddressBookStorageTest.java index 44cdd37d172..00caa247b98 100644 --- a/src/test/java/seedu/address/storage/JsonAddressBookStorageTest.java +++ b/src/test/java/seedu/address/storage/JsonAddressBookStorageTest.java @@ -3,10 +3,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalStudents.ALICE; -import static seedu.address.testutil.TypicalStudents.HOON; -import static seedu.address.testutil.TypicalStudents.IDA; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.HOON; +import static seedu.address.testutil.TypicalPersons.IDA; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.io.IOException; import java.nio.file.Path; @@ -72,10 +72,16 @@ public void readAndSaveAddressBook_allInOrder_success() throws Exception { assertEquals(original, new AddressBook(readBack)); // Modify data, overwrite exiting file, and read back + System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); original.addPerson(HOON); original.removePerson(ALICE); + original.getPersonList().forEach(person -> System.out.println(person.getName())); + System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); jsonAddressBookStorage.saveAddressBook(original, filePath); readBack = jsonAddressBookStorage.readAddressBook(filePath).get(); + System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); + readBack.getPersonList().forEach(person -> System.out.println(person.getName())); + System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); assertEquals(original, new AddressBook(readBack)); // Save and read without specifying file path diff --git a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java index b1f108f1943..b7f7ad84451 100644 --- a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java +++ b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java @@ -11,11 +11,12 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.commons.util.JsonUtil; import seedu.address.model.AddressBook; -import seedu.address.testutil.TypicalStudents; +import seedu.address.testutil.TypicalPersons; public class JsonSerializableAddressBookTest { - private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "JsonSerializableAddressBookTest"); + private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", + "JsonSerializableAddressBookTest"); private static final Path TYPICAL_PERSONS_FILE = TEST_DATA_FOLDER.resolve("typicalPersonsAddressBook.json"); private static final Path INVALID_PERSON_FILE = TEST_DATA_FOLDER.resolve("invalidPersonAddressBook.json"); private static final Path DUPLICATE_PERSON_FILE = TEST_DATA_FOLDER.resolve("duplicatePersonAddressBook.json"); @@ -25,9 +26,7 @@ public void toModelType_typicalPersonsFile_success() throws Exception { JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(TYPICAL_PERSONS_FILE, JsonSerializableAddressBook.class).get(); AddressBook addressBookFromFile = dataFromFile.toModelType(); - AddressBook typicalPersonsAddressBook = TypicalStudents.getTypicalAddressBook(); - System.out.println(addressBookFromFile.getPersonList()); - System.out.println(typicalPersonsAddressBook.getPersonList()); + AddressBook typicalPersonsAddressBook = TypicalPersons.getTypicalAddressBook(); assertEquals(addressBookFromFile, typicalPersonsAddressBook); } @@ -42,7 +41,7 @@ public void toModelType_invalidPersonFile_throwsIllegalValueException() throws E public void toModelType_duplicatePersons_throwsIllegalValueException() throws Exception { JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(DUPLICATE_PERSON_FILE, JsonSerializableAddressBook.class).get(); - assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_PERSON, + assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_STUDENT, dataFromFile::toModelType); } diff --git a/src/test/java/seedu/address/storage/StorageManagerTest.java b/src/test/java/seedu/address/storage/StorageManagerTest.java index ad0db49f6d9..99a16548970 100644 --- a/src/test/java/seedu/address/storage/StorageManagerTest.java +++ b/src/test/java/seedu/address/storage/StorageManagerTest.java @@ -2,7 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static seedu.address.testutil.TypicalStudents.getTypicalAddressBook; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.nio.file.Path; diff --git a/src/test/java/seedu/address/testutil/EditStudentDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditStudentDescriptorBuilder.java index 6d931d93edf..55d1f463d41 100644 --- a/src/test/java/seedu/address/testutil/EditStudentDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditStudentDescriptorBuilder.java @@ -16,7 +16,7 @@ import seedu.address.model.tag.Tag; /** - * A utility class to help with building EditPersonDescriptor objects. + * A utility class to help with building EditStudentDescriptor objects. */ public class EditStudentDescriptorBuilder { @@ -39,6 +39,7 @@ public EditStudentDescriptorBuilder(Student student) { descriptor.setPhone(student.getPhone()); descriptor.setEmail(student.getEmail()); descriptor.setAddress(student.getAddress()); + descriptor.setGender(student.getGender()); descriptor.setInvolvement(student.getInvolvement()); descriptor.setTags(student.getTags()); descriptor.setEmergencyContact(student.getEmergencyContact()); @@ -78,7 +79,7 @@ public EditStudentDescriptorBuilder withAddress(String address) { } /** - * Parses the {@code tags} into a {@code Set} and set it to the {@code EditPersonDescriptor} + * Parses the {@code tags} into a {@code Set} and set it to the {@code EditStudentDescriptor} * that we are building. */ public EditStudentDescriptorBuilder withTags(String... tags) { @@ -88,10 +89,11 @@ public EditStudentDescriptorBuilder withTags(String... tags) { } /** - * Sets the Emergency Contact of the {@code EditStudentDescriptor} that we are building. + * Parses the {@code emergencyContact} into a {@code Phone} of the {@code EditStudentDescriptor} + * that we are building. */ - public EditStudentDescriptorBuilder withEmergencyContact(String phone) { - descriptor.setEmergencyContact(new Phone(phone)); + public EditStudentDescriptorBuilder withEmergencyContact(String emergencyContact) { + descriptor.setEmergencyContact(new Phone(emergencyContact)); return this; } @@ -112,7 +114,7 @@ public EditStudentDescriptorBuilder withFormClass(String formClass) { } /** - * Sets the {@code Gender} of the {@code EditPersonDescriptor} that we are building. + * Sets the {@code Gender} of the {@code EditStudentDescriptor} that we are building. */ public EditStudentDescriptorBuilder withGender(String gender) { descriptor.setGender(new Gender(gender)); diff --git a/src/test/java/seedu/address/testutil/EditTeacherDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditTeacherDescriptorBuilder.java new file mode 100644 index 00000000000..c78f9308c82 --- /dev/null +++ b/src/test/java/seedu/address/testutil/EditTeacherDescriptorBuilder.java @@ -0,0 +1,107 @@ +package seedu.address.testutil; + +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import seedu.address.logic.commands.descriptors.EditTeacherDescriptor; +import seedu.address.model.person.Email; +import seedu.address.model.person.Gender; +import seedu.address.model.person.Involvement; +import seedu.address.model.person.Name; +import seedu.address.model.person.OfficeTable; +import seedu.address.model.person.Phone; +import seedu.address.model.person.Teacher; +import seedu.address.model.tag.Tag; + +/** + * A utility class to help with building EditTeacherDescriptor objects. + */ +public class EditTeacherDescriptorBuilder { + + private EditTeacherDescriptor descriptor; + + public EditTeacherDescriptorBuilder() { + descriptor = new EditTeacherDescriptor(); + } + + public EditTeacherDescriptorBuilder(EditTeacherDescriptor descriptor) { + this.descriptor = new EditTeacherDescriptor(descriptor); + } + + /** + * Returns an {@code EditTeacherDescriptor} with fields containing {@code teacher}'s details + */ + public EditTeacherDescriptorBuilder(Teacher teacher) { + descriptor = new EditTeacherDescriptor(); + descriptor.setName(teacher.getName()); + descriptor.setPhone(teacher.getPhone()); + descriptor.setEmail(teacher.getEmail()); + descriptor.setGender(teacher.getGender()); + descriptor.setInvolvement(teacher.getInvolvement()); + descriptor.setOfficeTable(teacher.getOfficeTable()); + descriptor.setTags(teacher.getTags()); + } + + /** + * Sets the {@code Name} of the {@code EditTeacherDescriptor} that we are building. + */ + public EditTeacherDescriptorBuilder withName(String name) { + descriptor.setName(new Name(name)); + return this; + } + + /** + * Sets the {@code Phone} of the {@code EditTeacherDescriptor} that we are building. + */ + public EditTeacherDescriptorBuilder withPhone(String phone) { + descriptor.setPhone(new Phone(phone)); + return this; + } + + /** + * Sets the {@code Email} of the {@code EditTeacherDescriptor} that we are building. + */ + public EditTeacherDescriptorBuilder withEmail(String email) { + descriptor.setEmail(new Email(email)); + return this; + } + + /** + * Sets the {@code Gender} of the {@code EditTeacherDescriptor} that we are building. + */ + public EditTeacherDescriptorBuilder withGender(String gender) { + descriptor.setGender(new Gender(gender)); + return this; + } + + /** + * Sets the {@code Involvement} of the {@code EditTeacherDescriptor} that we are building. + */ + public EditTeacherDescriptorBuilder withInvolvement(String involvement) { + descriptor.setInvolvement(new Involvement(involvement)); + return this; + } + + /** + * Sets the {@code OfficeTable} of the {@code EditTeacherDescriptor} that we are building. + */ + public EditTeacherDescriptorBuilder withOfficeTable(String officeTable) { + descriptor.setOfficeTable(new OfficeTable(officeTable)); + return this; + } + + /** + * Parses the {@code tags} into a {@code Set} and set it to the {@code EditTeacherDescriptor} + * that we are building. + */ + public EditTeacherDescriptorBuilder withTags(String... tags) { + Set tagSet = Stream.of(tags).map(Tag::new).collect(Collectors.toSet()); + descriptor.setTags(tagSet); + return this; + } + + public EditTeacherDescriptor build() { + return descriptor; + } +} diff --git a/src/test/java/seedu/address/testutil/StudentBuilder.java b/src/test/java/seedu/address/testutil/StudentBuilder.java index 50af6f1b52a..addff7ec9a7 100644 --- a/src/test/java/seedu/address/testutil/StudentBuilder.java +++ b/src/test/java/seedu/address/testutil/StudentBuilder.java @@ -28,7 +28,7 @@ public class StudentBuilder { public static final String DEFAULT_INVOLVEMENT = "Math class"; public static final String DEFAULT_FORM_CLASS = "4E1"; public static final String DEFAULT_GENDER = "M"; - public static final String DEFAULT_MEDICAL_HISTORY = "ADHD"; + public static final String DEFAULT_MEDICAL_HISTORY = ""; private Name name; private Phone phone; @@ -160,8 +160,17 @@ public StudentBuilder withMedicalHistory(String medicalHistory) { * @return the student. */ public Student build() { - return new Student(name, phone, email, address, involvement, tags, emergencyContact, formClass, gender, - medicalHistory); + return new Student(name, phone, email, gender, involvement, address, + emergencyContact, formClass, tags, medicalHistory); + } + + /** + * Builds the {@code Student} for edit tests. + * @return the student. + */ + public Student buildForEdit() { + return new Student(name, phone, email, gender, involvement, address, + emergencyContact, formClass, tags, new MedicalHistory("ADHD")); } } diff --git a/src/test/java/seedu/address/testutil/StudentUtil.java b/src/test/java/seedu/address/testutil/StudentUtil.java index c7d2e7c95f4..a27e4a84b21 100644 --- a/src/test/java/seedu/address/testutil/StudentUtil.java +++ b/src/test/java/seedu/address/testutil/StudentUtil.java @@ -26,25 +26,25 @@ public class StudentUtil { * Returns an add command string for adding the {@code student}. */ public static String getStudentCommand(Student student) { - return AddStudentCommand.COMMAND_WORD + " " + getPersonDetails(student); + return AddStudentCommand.COMMAND_WORD + " " + getStudentDetails(student); } /** * Returns the part of command string for the given {@code person}'s details. */ - public static String getPersonDetails(Student student) { + public static String getStudentDetails(Student student) { StringBuilder sb = new StringBuilder(); sb.append(PREFIX_NAME + student.getName().fullName + " "); sb.append(PREFIX_PHONE + student.getPhone().value + " "); sb.append(PREFIX_EMAIL + student.getEmail().value + " "); - sb.append(PREFIX_ADDRESS + student.getAddress().value + " "); + sb.append(PREFIX_GENDER + student.getGender().value + " "); sb.append(PREFIX_INVOLVEMENT + student.getInvolvement().involvement + " "); + sb.append(PREFIX_ADDRESS + student.getAddress().value + " "); + sb.append(PREFIX_EMERGENCY_CONTACT + student.getEmergencyContact().value + " "); + sb.append(PREFIX_FORM_CLASS + student.getFormClass().value + " "); student.getTags().stream().forEach( s -> sb.append(PREFIX_TAG + s.tagName + " ") ); - sb.append(PREFIX_EMERGENCY_CONTACT + student.getEmergencyContact().value + " "); - sb.append(PREFIX_FORM_CLASS + student.getFormClass().formClass + " "); - sb.append(PREFIX_GENDER + student.getGender().gender + " "); return sb.toString(); } @@ -56,15 +56,15 @@ public static String getEditStudentDescriptorDetails(EditStudentDescriptor descr descriptor.getName().ifPresent(name -> sb.append(PREFIX_NAME).append(name.fullName).append(" ")); descriptor.getPhone().ifPresent(phone -> sb.append(PREFIX_PHONE).append(phone.value).append(" ")); descriptor.getEmail().ifPresent(email -> sb.append(PREFIX_EMAIL).append(email.value).append(" ")); - descriptor.getAddress().ifPresent(address -> sb.append(PREFIX_ADDRESS).append(address.value).append(" ")); + descriptor.getGender().ifPresent(genders -> sb.append(PREFIX_GENDER).append(genders.value).append(" ")); descriptor.getInvolvement().ifPresent(involvement -> sb.append(PREFIX_INVOLVEMENT) .append(involvement.involvement).append(" ")); + descriptor.getAddress().ifPresent(address -> sb.append(PREFIX_ADDRESS).append(address.value).append(" ")); descriptor.getEmergencyContact().ifPresent(emergencyContact -> sb.append(PREFIX_EMERGENCY_CONTACT).append(emergencyContact.value).append(" ")); descriptor.getFormClass().ifPresent(formClass -> - sb.append(PREFIX_FORM_CLASS).append(formClass.formClass).append(" ")); - descriptor.getGender().ifPresent(genders -> - sb.append(PREFIX_GENDER).append(genders.gender).append(" ")); + sb.append(PREFIX_FORM_CLASS).append(formClass.value).append(" ")); + // tags should be the last, else bug if (descriptor.getTags().isPresent()) { Set tags = descriptor.getTags().get(); diff --git a/src/test/java/seedu/address/testutil/TeacherBuilder.java b/src/test/java/seedu/address/testutil/TeacherBuilder.java new file mode 100644 index 00000000000..e59e92d928b --- /dev/null +++ b/src/test/java/seedu/address/testutil/TeacherBuilder.java @@ -0,0 +1,122 @@ +package seedu.address.testutil; + +import java.util.HashSet; +import java.util.Set; + +import seedu.address.model.person.Email; +import seedu.address.model.person.Gender; +import seedu.address.model.person.Involvement; +import seedu.address.model.person.Name; +import seedu.address.model.person.OfficeTable; +import seedu.address.model.person.Phone; +import seedu.address.model.person.Teacher; +import seedu.address.model.tag.Tag; +import seedu.address.model.util.SampleDataUtil; + +/** + * A utility class to help with building Teacher objects. + */ +public class TeacherBuilder { + + public static final String DEFAULT_NAME = "Dee ku"; + public static final String DEFAULT_PHONE = "44444444"; + public static final String DEFAULT_EMAIL = "dee@example.com"; + public static final String DEFAULT_GENDER = "N"; + public static final String DEFAULT_INVOLVEMENT = "4A Co-Form"; + public static final String DEFAULT_OFFICE_TABLE = "12"; + + private Name name; + private Phone phone; + private Email email; + private Gender gender; + private Involvement involvement; + private OfficeTable officeTable; + private Set tags; + + /** + * Creates a {@code TeacherBuilder} with the default details. + */ + public TeacherBuilder() { + name = new Name(DEFAULT_NAME); + phone = new Phone(DEFAULT_PHONE); + email = new Email(DEFAULT_EMAIL); + gender = new Gender(DEFAULT_GENDER); + involvement = new Involvement(DEFAULT_INVOLVEMENT); + officeTable = new OfficeTable(DEFAULT_OFFICE_TABLE); + tags = new HashSet<>(); + } + + /** + * Initializes the TeacherBuilder with the data of {@code teacherToCopy}. + */ + public TeacherBuilder(Teacher teacherToCopy) { + name = teacherToCopy.getName(); + phone = teacherToCopy.getPhone(); + email = teacherToCopy.getEmail(); + gender = teacherToCopy.getGender(); + involvement = teacherToCopy.getInvolvement(); + officeTable = teacherToCopy.getOfficeTable(); + tags = new HashSet<>(teacherToCopy.getTags()); + } + + /** + * Sets the {@code Name} of the {@code Teacher} that we are building. + */ + public TeacherBuilder withName(String name) { + this.name = new Name(name); + return this; + } + + /** + * Sets the {@code Phone} of the {@code Teacher} that we are building. + */ + public TeacherBuilder withPhone(String phone) { + this.phone = new Phone(phone); + return this; + } + + /** + * Sets the {@code Email} of the {@code Teacher} that we are building. + */ + public TeacherBuilder withEmail(String email) { + this.email = new Email(email); + return this; + } + + /** + * Sets the {@code Gender} of the {@code Teacher} that we are building. + */ + public TeacherBuilder withGender(String gender) { + this.gender = new Gender(gender); + return this; + } + + /** + * Sets the {@code Involvement} of the {@code Teacher} that we are building. + */ + public TeacherBuilder withInvolvement(String involvement) { + this.involvement = new Involvement(involvement); + return this; + } + + /** + * Sets the {@code OfficeTable} of the {@code Teacher} that we are building. + */ + public TeacherBuilder withOfficeTable(String officeTable) { + this.officeTable = new OfficeTable(officeTable); + return this; + } + + /** + * Parses the {@code tags} into a {@code Set} and set it to the {@code Teacher} that we are building. + */ + public TeacherBuilder withTags(String ... tags) { + this.tags = SampleDataUtil.getTagSet(tags); + return this; + } + + public Teacher build() { + return new Teacher(name, phone, email, gender, involvement, officeTable, tags); + } + +} diff --git a/src/test/java/seedu/address/testutil/TypicalIndexes.java b/src/test/java/seedu/address/testutil/TypicalIndexes.java index 1e613937657..78166fabce9 100644 --- a/src/test/java/seedu/address/testutil/TypicalIndexes.java +++ b/src/test/java/seedu/address/testutil/TypicalIndexes.java @@ -6,7 +6,10 @@ * A utility class containing a list of {@code Index} objects to be used in tests. */ public class TypicalIndexes { - public static final Index INDEX_FIRST_PERSON = Index.fromOneBased(1); - public static final Index INDEX_SECOND_PERSON = Index.fromOneBased(2); - public static final Index INDEX_THIRD_PERSON = Index.fromOneBased(3); + public static final Index INDEX_FIRST_STUDENT = Index.fromOneBased(1); + public static final Index INDEX_SECOND_STUDENT = Index.fromOneBased(2); + public static final Index INDEX_THIRD_STUDENT = Index.fromOneBased(3); + public static final Index INDEX_FIRST_TEACHER = Index.fromOneBased(8); + public static final Index INDEX_SECOND_TEACHER = Index.fromOneBased(9); + public static final Index INDEX_THIRD_TEACHER = Index.fromOneBased(10); } diff --git a/src/test/java/seedu/address/testutil/TypicalStudents.java b/src/test/java/seedu/address/testutil/TypicalPersons.java similarity index 62% rename from src/test/java/seedu/address/testutil/TypicalStudents.java rename to src/test/java/seedu/address/testutil/TypicalPersons.java index 074b35c80f5..e19f6d147b7 100644 --- a/src/test/java/seedu/address/testutil/TypicalStudents.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -4,20 +4,32 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_DEE; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMERGENCY_CONTACT_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_EMERGENCY_CONTACT_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_FORM_CLASS_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_FORM_CLASS_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_DEE; import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_INVOLVEMENT_DEE; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_OFFICE_TABLE_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_OFFICE_TABLE_DEE; import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_CHO; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_DEE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MONITOR; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_REP; import java.util.ArrayList; import java.util.Arrays; @@ -25,11 +37,12 @@ import seedu.address.model.AddressBook; import seedu.address.model.person.Student; +import seedu.address.model.person.Teacher; /** * A utility class containing a list of {@code Student} objects to be used in tests. */ -public class TypicalStudents { +public class TypicalPersons { public static final Student ALICE = new StudentBuilder() .withName("Alice Pauline") @@ -94,7 +107,7 @@ public class TypicalStudents { .withPhone("9482427") .withEmail("lydia@example.com") .withAddress("little tokyo") - .withEmergencyContact("99749087") + .withEmergencyContact("580947918074907019749087") .withInvolvement("English class") .withFormClass("1T1") .withGender("F") @@ -112,6 +125,72 @@ public class TypicalStudents { .withMedicalHistory("") .build(); + public static final Teacher ALI = new TeacherBuilder() + .withName("Ali Paula") + .withPhone("94351253") + .withEmail("ali@example.com") + .withGender("F") + .withInvolvement("Math Dept") + .withOfficeTable("1") + .withTags("friends") + .build(); + + public static final Teacher BEN = new TeacherBuilder() + .withName("Ben ten") + .withPhone("98765432") + .withEmail("bm1@example.com") + .withGender("M") + .withInvolvement("Math Dept") + .withOfficeTable("2") + .withTags("owesMoney", "friends") + .build(); + + public static final Teacher CAR = new TeacherBuilder() + .withName("Car goh") + .withPhone("95352563") + .withEmail("ck@example.com") + .withGender("M") + .withInvolvement("4A Co-Form") + .withOfficeTable("3") + .build(); + + public static final Teacher DAN = new TeacherBuilder() + .withName("Dan Mei") + .withPhone("87652533") + .withEmail("dm2@example.com") + .withGender("M") + .withInvolvement("4A Co-Form") + .withOfficeTable("4") + .withTags("friends") + .build(); + + public static final Teacher EL = new TeacherBuilder() + .withName("El Mey") + .withPhone("9482224") + .withEmail("em@example.com") + .withGender("F") + .withInvolvement("Math Dept") + .withOfficeTable("5") + .build(); + + public static final Teacher FIO = new TeacherBuilder() + .withName("Fio runz") + .withPhone("9482427") + .withEmail("fk@example.com") + .withGender("F") + .withInvolvement("Math Dept") + .withOfficeTable("6") + .build(); + + public static final Teacher GEO = new TeacherBuilder() + .withName("Geo Good") + .withPhone("9482442") + .withEmail("best@example.com") + .withGender("M") + .withInvolvement("Math HOD") + .withOfficeTable("7") + .build(); + // Manually added public static final Student HOON = new StudentBuilder() .withName("Hoon Meier") @@ -144,7 +223,7 @@ public class TypicalStudents { .withEmail(VALID_EMAIL_AMY) .withAddress(VALID_ADDRESS_AMY) .withInvolvement(VALID_INVOLVEMENT_AMY) - .withTags(VALID_TAG_FRIEND) + .withTags(VALID_TAG_REP) .withEmergencyContact(VALID_EMERGENCY_CONTACT_AMY) .withFormClass(VALID_FORM_CLASS_AMY) .withGender(VALID_GENDER_AMY) @@ -157,16 +236,36 @@ public class TypicalStudents { .withEmail(VALID_EMAIL_BOB) .withAddress(VALID_ADDRESS_BOB) .withInvolvement(VALID_INVOLVEMENT_BOB) - .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND) + .withTags(VALID_TAG_MONITOR, VALID_TAG_REP) .withEmergencyContact(VALID_EMERGENCY_CONTACT_BOB) .withFormClass(VALID_FORM_CLASS_BOB) .withGender(VALID_GENDER_BOB) .withMedicalHistory("") .build(); + public static final Teacher CHO = new TeacherBuilder() + .withName(VALID_NAME_CHO) + .withPhone(VALID_PHONE_CHO) + .withEmail(VALID_EMAIL_CHO) + .withGender(VALID_GENDER_CHO) + .withInvolvement(VALID_INVOLVEMENT_CHO) + .withOfficeTable(VALID_OFFICE_TABLE_CHO) + .withTags(VALID_TAG_REP) + .build(); + + public static final Teacher DEE = new TeacherBuilder() + .withName(VALID_NAME_DEE) + .withPhone(VALID_PHONE_DEE) + .withEmail(VALID_EMAIL_DEE) + .withGender(VALID_GENDER_DEE) + .withInvolvement(VALID_INVOLVEMENT_DEE) + .withOfficeTable(VALID_OFFICE_TABLE_DEE) + .withTags(VALID_TAG_MONITOR, VALID_TAG_REP) + .build(); + public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER - private TypicalStudents() {} // prevents instantiation + private TypicalPersons() {} // prevents instantiation /** * Returns an {@code AddressBook} with all the typical students. @@ -176,10 +275,17 @@ public static AddressBook getTypicalAddressBook() { for (Student student : getTypicalStudents()) { ab.addPerson(student); } + for (Teacher teacher: getTypicalTeachers()) { + ab.addPerson(teacher); + } return ab; } public static List getTypicalStudents() { return new ArrayList<>(Arrays.asList(ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE)); } + + public static List getTypicalTeachers() { + return new ArrayList<>(Arrays.asList(ALI, BEN, CAR, DAN, EL, FIO, GEO)); + } }