From a59aa87181f6419dea32958b5cf6181306c93c4a Mon Sep 17 00:00:00 2001 From: wynonaK <35650845+wynonaK@users.noreply.github.com> Date: Mon, 26 Mar 2018 14:50:57 +0800 Subject: [PATCH 1/4] Made unique appointment tag field. Edited XmlAdaptedAppointment and all relevant tests. --- .../java/seedu/address/model/AddressBook.java | 31 ++++- .../address/model/ReadOnlyAddressBook.java | 7 ++ .../model/appointment/Appointment.java | 39 ++----- .../storage/XmlAdaptedAppointment.java | 60 ++++++---- .../seedu/address/model/AddressBookTest.java | 20 +++- .../storage/XmlAdaptedAppointmentTest.java | 110 ++++++++++++++---- .../address/testutil/AppointmentBuilder.java | 44 +++---- .../address/testutil/AppointmentUtil.java | 22 +--- .../address/testutil/TypicalAppointments.java | 18 ++- 9 files changed, 223 insertions(+), 128 deletions(-) diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 340d447d2a16..da05602b59c0 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -33,6 +33,7 @@ public class AddressBook implements ReadOnlyAddressBook { private final UniquePersonList persons; private final UniqueTagList tags; private final UniqueAppointmentList appointments; + private final UniqueTagList appointmentTags; private final UniquePetPatientList petPatients; private final UniqueTagList petPatientTags; @@ -46,6 +47,7 @@ public class AddressBook implements ReadOnlyAddressBook { persons = new UniquePersonList(); tags = new UniqueTagList(); appointments = new UniqueAppointmentList(); + appointmentTags = new UniqueTagList(); petPatients = new UniquePetPatientList(); petPatientTags = new UniqueTagList(); } @@ -75,6 +77,10 @@ public void setAppointments(List appointments) throws DuplicateAppo this.appointments.setAppointments(appointments); } + public void setAppointmentTags(Set appointmentTags) { + this.appointmentTags.setTags(appointmentTags); + } + public void setPetPatients(List petPatients) throws DuplicatePetPatientException { this.petPatients.setPetPatients(petPatients); } @@ -99,6 +105,7 @@ public void resetData(ReadOnlyAddressBook newData) { throw new AssertionError("AddressBooks should not have duplicate persons"); } + setAppointmentTags(new HashSet<>(newData.getAppointmentTagList())); List syncedAppointmentList = newData.getAppointmentList().stream() .map(this::syncWithAppointmentMasterTagList) .collect(Collectors.toList()); @@ -245,7 +252,7 @@ private PetPatient syncWithMasterTagList (PetPatient petPatient) { * points to a Tag object in the master list. */ private Appointment syncWithAppointmentMasterTagList(Appointment appointment) { - final UniqueTagList appointmentTags = new UniqueTagList(appointment.getType()); + final UniqueTagList appointmentTags = new UniqueTagList(appointment.getAppointmentTags()); tags.mergeFrom(appointmentTags); // Create map with values = tag object references in the master list @@ -257,8 +264,11 @@ private Appointment syncWithAppointmentMasterTagList(Appointment appointment) { final Set correctTagReferences = new HashSet<>(); appointmentTags.forEach(tag -> correctTagReferences.add(masterTagObjects.get(tag))); return new Appointment( - appointment.getOwnerNric(), appointment.getPetPatientName(), appointment.getRemark(), - appointment.getDateTime(), correctTagReferences); + appointment.getOwnerNric(), + appointment.getPetPatientName(), + appointment.getRemark(), + appointment.getDateTime(), + correctTagReferences); } /** * Removes {@code key} from this {@code AddressBook}. @@ -297,6 +307,10 @@ public void addPetPatientTag(Tag t) throws UniqueTagList.DuplicateTagException { petPatientTags.add(t); } + public void addAppointmentTag(Tag t) throws UniqueTagList.DuplicateTagException { + appointmentTags.add(t); + } + /** * Removes {@code tag} from {@code person} with that tag this {@code AddressBook}. * @@ -342,7 +356,8 @@ public void removeTag(Tag tag) { public String toString() { return persons.asObservableList().size() + " persons, " + tags.asObservableList().size() + " tags, " - + appointments.asObservableList().size() + " appointments" + + appointments.asObservableList().size() + " appointments, " + + appointmentTags.asObservableList().size() + " appointment tags, " + petPatients.asObservableList().size() + " pet patients, " + petPatientTags.asObservableList().size() + " pet patient tags"; // TODO: refine later @@ -363,6 +378,11 @@ public ObservableList getAppointmentList() { return appointments.asObservableList(); } + @Override + public ObservableList getAppointmentTagList() { + return appointmentTags.asObservableList(); + } + @Override public ObservableList getPetPatientList() { return petPatients.asObservableList(); @@ -380,6 +400,7 @@ public boolean equals(Object other) { && this.persons.equals(((AddressBook) other).persons) && this.tags.equalsOrderInsensitive(((AddressBook) other).tags)) && this.appointments.equals(((AddressBook) other).appointments) + && this.appointmentTags.equals(((AddressBook) other).appointmentTags) && this.petPatients.equals(((AddressBook) other).petPatients) && this.petPatientTags.equalsOrderInsensitive(((AddressBook) other).petPatientTags); } @@ -387,6 +408,6 @@ public boolean equals(Object other) { @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(persons, tags, appointments, petPatients, petPatientTags); + return Objects.hash(persons, tags, appointments, appointmentTags, petPatients, petPatientTags); } } diff --git a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java index ab6c2baacde9..d1f7f6a23700 100644 --- a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java +++ b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java @@ -30,6 +30,13 @@ public interface ReadOnlyAddressBook { */ ObservableList getAppointmentList(); + /** + + * Returns an unmodifiable view of the appointment tag list. + * This list will not contain any duplicate appointment tags. + */ + ObservableList getAppointmentTagList(); + /** * Returns an unmodifiable view of the pet patient list. diff --git a/src/main/java/seedu/address/model/appointment/Appointment.java b/src/main/java/seedu/address/model/appointment/Appointment.java index bfa85063e6aa..eb3162820d3d 100644 --- a/src/main/java/seedu/address/model/appointment/Appointment.java +++ b/src/main/java/seedu/address/model/appointment/Appointment.java @@ -20,25 +20,24 @@ */ public class Appointment { private Nric ownerNric; - private Name ownerName = null; private PetPatientName petPatientName; private Remark remark; //remarks private LocalDateTime localDateTime; //date of appointment - private final UniqueTagList type; //type of appointment + private UniqueTagList appointmentTags; //type of appointment /** * Every field must be present and not null. */ public Appointment(Nric ownerNric, PetPatientName petPatientName, Remark remark, - LocalDateTime localDateTime, Set type) { - requireAllNonNull(ownerNric, petPatientName, remark, localDateTime, type); + LocalDateTime localDateTime, Set appointmentTags) { + requireAllNonNull(ownerNric, petPatientName, remark, localDateTime, appointmentTags); this.ownerNric = ownerNric; this.petPatientName = petPatientName; this.remark = remark; this.localDateTime = localDateTime; // protect internal tags from changes in the arg list - this.type = new UniqueTagList(type); + this.appointmentTags = new UniqueTagList(appointmentTags); } /** @@ -49,17 +48,7 @@ public Appointment(Remark remark, LocalDateTime localDateTime, Set type) { this.remark = remark; this.localDateTime = localDateTime; // protect internal tags from changes in the arg list - this.type = new UniqueTagList(type); - } - - //Please remove this constructor if it is no longer in use - public Appointment(Name owner, Remark remark, LocalDateTime localDateTime, Set type) { - requireAllNonNull(owner, remark, localDateTime, type); - this.ownerName = owner; - this.remark = remark; - this.localDateTime = localDateTime; - // protect internal tags from changes in the arg list - this.type = new UniqueTagList(type); + this.appointmentTags = new UniqueTagList(type); } public Nric getOwnerNric() { @@ -70,10 +59,6 @@ public void setOwnerNric(Nric ownerNric) { this.ownerNric = ownerNric; } - public Name getOwnerName() { - return ownerName; - } - public PetPatientName getPetPatientName() { return petPatientName; } @@ -87,7 +72,6 @@ public Remark getRemark() { } public LocalDateTime getDateTime() { - return localDateTime; } @@ -95,12 +79,13 @@ public String getFormattedLocalDateTime() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); return localDateTime.format(formatter); } + /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. */ - public Set getType() { - return Collections.unmodifiableSet(type.toSet()); + public Set getAppointmentTags() { + return Collections.unmodifiableSet(appointmentTags.toSet()); } @Override @@ -123,7 +108,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(ownerNric, petPatientName, remark, localDateTime, type); + return Objects.hash(ownerNric, petPatientName, remark, localDateTime, appointmentTags); } @Override @@ -131,14 +116,10 @@ public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("\t") .append(getFormattedLocalDateTime()) - //.append("\tOwner: ") - //.append(getOwnerNric().toString()) - //.append("\tPet Patient: ") - //.append(getPetPatientName().toString()) .append("\tRemarks: ") .append(getRemark()) .append("\tType(s): "); - getType().forEach(builder::append); + getAppointmentTags().forEach(builder::append); return builder.toString(); } diff --git a/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java b/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java index 2032d7450ab2..dc0b0cb06e6b 100644 --- a/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java +++ b/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java @@ -15,6 +15,8 @@ import seedu.address.model.appointment.Appointment; import seedu.address.model.appointment.Remark; import seedu.address.model.person.Name; +import seedu.address.model.person.Nric; +import seedu.address.model.petpatient.PetPatientName; import seedu.address.model.tag.Tag; /** @@ -25,16 +27,16 @@ public class XmlAdaptedAppointment { public static final String MISSING_FIELD_MESSAGE_FORMAT = "Appointment %s field is missing!"; @XmlElement(required = true) - private String owner; + private String ownerNric; @XmlElement(required = true) - private String petPatient; + private String petPatientName; @XmlElement(required = true) private String remark; @XmlElement(required = true) private String dateTime; @XmlElement - private List tagged = new ArrayList<>(); + private List appointmentTagged = new ArrayList<>(); /** * Constructs an XmlAdaptedAppointment. @@ -45,12 +47,14 @@ public XmlAdaptedAppointment() {} /** * Constructs an {@code XmlAdaptedAppointment} with the given appointment details. */ - public XmlAdaptedAppointment(String owner, String remark, String dateTime, List tagged) { - this.owner = owner; + public XmlAdaptedAppointment(String ownerNric, String petPatientName, String remark, + String dateTime, List appointmentTagged) { + this.ownerNric = ownerNric; + this.petPatientName = petPatientName; this.remark = remark; this.dateTime = dateTime; - if (tagged != null) { - this.tagged = new ArrayList<>(tagged); + if (appointmentTagged != null) { + this.appointmentTagged = new ArrayList<>(appointmentTagged); } } @@ -60,13 +64,13 @@ public XmlAdaptedAppointment(String owner, String remark, String dateTime, List< * @param source future changes to this will not affect the created XmlAdaptedAppointment */ public XmlAdaptedAppointment(Appointment source) { - owner = source.getOwnerNric().toString(); - petPatient = source.getPetPatientName().toString(); + ownerNric = source.getOwnerNric().toString(); + petPatientName = source.getPetPatientName().toString(); remark = source.getRemark().value; dateTime = source.getFormattedLocalDateTime(); - tagged = new ArrayList<>(); - for (Tag tag : source.getType()) { - tagged.add(new XmlAdaptedTag(tag)); + appointmentTagged = new ArrayList<>(); + for (Tag tag : source.getAppointmentTags()) { + appointmentTagged.add(new XmlAdaptedTag(tag)); } } @@ -77,17 +81,26 @@ public XmlAdaptedAppointment(Appointment source) { */ public Appointment toModelType() throws IllegalValueException { final List appointmentTags = new ArrayList<>(); - for (XmlAdaptedTag tag : tagged) { + for (XmlAdaptedTag tag : appointmentTagged) { appointmentTags.add(tag.toModelType()); } - if (this.owner == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); + if (this.ownerNric == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Nric.class.getSimpleName())); } - if (!Name.isValidName(this.owner)) { - throw new IllegalValueException(Name.MESSAGE_NAME_CONSTRAINTS); + if (!Nric.isValidNric(this.ownerNric)) { + throw new IllegalValueException(Nric.MESSAGE_NRIC_CONSTRAINTS); } - final Name owner = new Name(this.owner); + final Nric ownerNric = new Nric(this.ownerNric); + + if (this.petPatientName == null) { + throw new IllegalValueException( + String.format(MISSING_FIELD_MESSAGE_FORMAT, PetPatientName.class.getSimpleName())); + } + if (!PetPatientName.isValidName(this.petPatientName)) { + throw new IllegalValueException(PetPatientName.MESSAGE_PET_NAME_CONSTRAINTS); + } + final PetPatientName petPatientName = new PetPatientName(this.petPatientName); if (this.remark == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Remark.class.getSimpleName())); @@ -95,6 +108,7 @@ public Appointment toModelType() throws IllegalValueException { if (!Remark.isValidRemark(this.remark)) { throw new IllegalValueException(Remark.MESSAGE_REMARK_CONSTRAINTS); } + final Remark remark = new Remark(this.remark); if (this.dateTime == null) { @@ -114,8 +128,8 @@ public Appointment toModelType() throws IllegalValueException { final LocalDateTime dateTime = localDateTime; - final Set tags = new HashSet<>(appointmentTags); - return new Appointment(owner, remark, dateTime, tags); + final Set thisAppointmentTags = new HashSet<>(appointmentTags); + return new Appointment(ownerNric, petPatientName, remark, dateTime, thisAppointmentTags); } @Override @@ -129,10 +143,10 @@ public boolean equals(Object other) { } XmlAdaptedAppointment otherAppointment = (XmlAdaptedAppointment) other; - return Objects.equals(owner, otherAppointment.owner) - && Objects.equals(petPatient, otherAppointment.petPatient) + return Objects.equals(ownerNric, otherAppointment.ownerNric) + && Objects.equals(petPatientName, otherAppointment.petPatientName) && Objects.equals(remark, otherAppointment.remark) && Objects.equals(dateTime, otherAppointment.dateTime) - && tagged.equals(otherAppointment.tagged); + && appointmentTagged.equals(otherAppointment.appointmentTagged); } } diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index d53003b3ef8e..df39cd0c6166 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -5,6 +5,7 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_UNUSED; // import static seedu.address.testutil.TypicalAppointments.ALLY; +import static seedu.address.testutil.TypicalAppointments.ALLY; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.AMY; import static seedu.address.testutil.TypicalPersons.BOB; @@ -20,6 +21,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; +import javafx.beans.binding.ObjectExpression; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import seedu.address.model.appointment.Appointment; @@ -41,6 +43,7 @@ public void constructor() { assertEquals(Collections.emptyList(), addressBook.getPersonList()); assertEquals(Collections.emptyList(), addressBook.getTagList()); assertEquals(Collections.emptyList(), addressBook.getAppointmentList()); + assertEquals(Collections.emptyList(), addressBook.getAppointmentTagList()); } @Test @@ -61,9 +64,9 @@ public void resetData_withDuplicatePersons_throwsAssertionError() { // Repeat ALICE twice List newPersons = Arrays.asList(ALICE, ALICE); List newTags = new ArrayList<>(ALICE.getTags()); - //List newAppointments = Arrays.asList(ALLY); - //AddressBookStub newData = new AddressBookStub(newPersons, newTags, newAppointments); - AddressBookStub newData = new AddressBookStub(newPersons, newTags); + List newAppointments = Arrays.asList(ALLY); + List newAppointmentTags = new ArrayList<>(ALLY.getAppointmentTags()); + AddressBookStub newData = new AddressBookStub(newPersons, newTags, newAppointments, newAppointmentTags); thrown.expect(AssertionError.class); addressBook.resetData(newData); @@ -114,12 +117,16 @@ private static class AddressBookStub implements ReadOnlyAddressBook { private final ObservableList persons = FXCollections.observableArrayList(); private final ObservableList tags = FXCollections.observableArrayList(); private final ObservableList appointments = FXCollections.observableArrayList(); + private final ObservableList appointmentTags = FXCollections.observableArrayList(); private final ObservableList petPatients = FXCollections.observableArrayList(); private final ObservableList petPatientTags = FXCollections.observableArrayList(); - AddressBookStub(Collection persons, Collection tags) { + AddressBookStub(Collection persons, Collection tags, + Collection appointments, Collection appointmentTags) { this.persons.setAll(persons); this.tags.setAll(tags); + this.appointments.setAll(appointments); + this.appointmentTags.setAll(appointmentTags); } @Override @@ -137,6 +144,11 @@ public ObservableList getAppointmentList() { return appointments; } + @Override + public ObservableList getAppointmentTagList() { + return appointmentTags; + } + @Override public ObservableList getPetPatientList() { return petPatients; diff --git a/src/test/java/seedu/address/storage/XmlAdaptedAppointmentTest.java b/src/test/java/seedu/address/storage/XmlAdaptedAppointmentTest.java index 980676957087..f66cb1c42073 100644 --- a/src/test/java/seedu/address/storage/XmlAdaptedAppointmentTest.java +++ b/src/test/java/seedu/address/storage/XmlAdaptedAppointmentTest.java @@ -1,6 +1,6 @@ package seedu.address.storage; -/** import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import static seedu.address.storage.XmlAdaptedAppointment.MISSING_FIELD_MESSAGE_FORMAT; import static seedu.address.testutil.TypicalAppointments.ALLY; @@ -13,23 +13,24 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.appointment.Remark; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.petpatient.PetPatient; +import seedu.address.model.person.Nric; +import seedu.address.model.petpatient.PetPatientName; import seedu.address.testutil.Assert; -**/ + public class XmlAdaptedAppointmentTest { - /** + + private static final String INVALID_OWNER_NRIC = "S012345AB"; + private static final String INVALID_PET_PATIENT_NAME = "L@osai"; private static final String INVALID_REMARK = " "; private static final String INVALID_DATETIME = "MAAAY 2018 8PM"; - private static final String INVALID_TYPE = "#checkup"; + private static final String INVALID_APPOINTMENT_TAG = "#checkup"; - private static final Person VALID_OWNER = ALLY.getOwner(); - private static final PetPatient VALID_PET = ALLY.getPetPatient(); + private static final String VALID_OWNER_NRIC = ALLY.getOwnerNric().toString(); + private static final String VALID_PET_PATIENT_NAME = ALLY.getPetPatientName().toString(); private static final String VALID_REMARK = ALLY.getRemark().toString(); private static final String VALID_DATETIME = ALLY.getFormattedLocalDateTime(); - private static final List VALID_TYPE = ALLY.getType().stream() + private static final List VALID_APPOINTMENT_TAGS = ALLY.getAppointmentTags().stream() .map(XmlAdaptedTag::new) .collect(Collectors.toList()); @@ -40,17 +41,66 @@ public void toModelType_validAppointmentDetails_returnsAppointment() throws Exce } @Test - public void toModelType_nullName_throwsIllegalValueException() { + public void toModelType_invalidOwnerNric_throwsIllegalValueException() { + XmlAdaptedAppointment appointment = + new XmlAdaptedAppointment( + INVALID_OWNER_NRIC, + VALID_PET_PATIENT_NAME, + VALID_REMARK, + VALID_DATETIME, + VALID_APPOINTMENT_TAGS); + String expectedMessage = Nric.MESSAGE_NRIC_CONSTRAINTS; + Assert.assertThrows(IllegalValueException.class, expectedMessage, appointment::toModelType); + } + + @Test + public void toModelType_nullOwnerNric_throwsIllegalValueException() { + XmlAdaptedAppointment appointment = + new XmlAdaptedAppointment( + null, + VALID_PET_PATIENT_NAME, + VALID_REMARK, + VALID_DATETIME, + VALID_APPOINTMENT_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Nric.class.getSimpleName()); + Assert.assertThrows(IllegalValueException.class, expectedMessage, appointment::toModelType); + } + + @Test + public void toModelType_invalidPetName_throwsIllegalValueException() { XmlAdaptedAppointment appointment = - new XmlAdaptedAppointment(null, VALID_REMARK, VALID_PET, VALID_DATETIME, VALID_TYPE); - String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()); + new XmlAdaptedAppointment( + VALID_OWNER_NRIC, + INVALID_PET_PATIENT_NAME, + VALID_REMARK, + VALID_DATETIME, + VALID_APPOINTMENT_TAGS); + String expectedMessage = PetPatientName.MESSAGE_PET_NAME_CONSTRAINTS; + Assert.assertThrows(IllegalValueException.class, expectedMessage, appointment::toModelType); + } + + @Test + public void toModelType_nullPetName_throwsIllegalValueException() { + XmlAdaptedAppointment appointment = + new XmlAdaptedAppointment( + VALID_OWNER_NRIC, + null, + VALID_REMARK, + VALID_DATETIME, + VALID_APPOINTMENT_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, PetPatientName.class.getSimpleName()); Assert.assertThrows(IllegalValueException.class, expectedMessage, appointment::toModelType); } @Test public void toModelType_invalidRemark_throwsIllegalValueException() { XmlAdaptedAppointment appointment = - new XmlAdaptedAppointment(VALID_OWNER, INVALID_REMARK, VALID_DATETIME, VALID_TYPE); + new XmlAdaptedAppointment( + VALID_OWNER_NRIC, + VALID_PET_PATIENT_NAME, + INVALID_REMARK, + VALID_DATETIME, + VALID_APPOINTMENT_TAGS); String expectedMessage = Remark.MESSAGE_REMARK_CONSTRAINTS; Assert.assertThrows(IllegalValueException.class, expectedMessage, appointment::toModelType); } @@ -58,7 +108,12 @@ public void toModelType_invalidRemark_throwsIllegalValueException() { @Test public void toModelType_nullRemark_throwsIllegalValueException() { XmlAdaptedAppointment appointment = - new XmlAdaptedAppointment(VALID_OWNER, null, VALID_DATETIME, VALID_TYPE); + new XmlAdaptedAppointment( + VALID_OWNER_NRIC, + VALID_PET_PATIENT_NAME, + null, + VALID_DATETIME, + VALID_APPOINTMENT_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Remark.class.getSimpleName()); Assert.assertThrows(IllegalValueException.class, expectedMessage, appointment::toModelType); } @@ -66,26 +121,37 @@ public void toModelType_nullRemark_throwsIllegalValueException() { @Test public void toModelType_invalidDateTime_throwsIllegalValueException() { XmlAdaptedAppointment appointment = - new XmlAdaptedAppointment(VALID_OWNER, VALID_REMARK, INVALID_DATETIME, VALID_TYPE); + new XmlAdaptedAppointment(VALID_OWNER_NRIC, + VALID_PET_PATIENT_NAME, + VALID_REMARK, + INVALID_DATETIME, + VALID_APPOINTMENT_TAGS); String expectedMessage = "Please follow the format of yyyy-MM-dd HH:mm"; Assert.assertThrows(IllegalValueException.class, expectedMessage, appointment::toModelType); } @Test public void toModelType_nullDateTime_throwsIllegalValueException() { - XmlAdaptedAppointment appointment = new XmlAdaptedAppointment(VALID_OWNER, VALID_REMARK, - null, VALID_TYPE); + XmlAdaptedAppointment appointment = new XmlAdaptedAppointment(VALID_OWNER_NRIC, + VALID_PET_PATIENT_NAME, + VALID_REMARK, + null, + VALID_APPOINTMENT_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, LocalDateTime.class.getSimpleName()); Assert.assertThrows(IllegalValueException.class, expectedMessage, appointment::toModelType); } @Test public void toModelType_invalidType_throwsIllegalValueException() { - List invalidTags = new ArrayList<>(VALID_TYPE); - invalidTags.add(new XmlAdaptedTag(INVALID_TYPE)); + List invalidTags = new ArrayList<>(VALID_APPOINTMENT_TAGS); + invalidTags.add(new XmlAdaptedTag(INVALID_APPOINTMENT_TAG)); XmlAdaptedAppointment appointment = - new XmlAdaptedAppointment(VALID_OWNER, VALID_REMARK, VALID_DATETIME, invalidTags); + new XmlAdaptedAppointment(VALID_OWNER_NRIC, + VALID_PET_PATIENT_NAME, + VALID_REMARK, + VALID_DATETIME, + invalidTags); Assert.assertThrows(IllegalValueException.class, appointment::toModelType); } -**/ + } diff --git a/src/test/java/seedu/address/testutil/AppointmentBuilder.java b/src/test/java/seedu/address/testutil/AppointmentBuilder.java index 1d1d8b4a7d0e..47518f38e465 100644 --- a/src/test/java/seedu/address/testutil/AppointmentBuilder.java +++ b/src/test/java/seedu/address/testutil/AppointmentBuilder.java @@ -18,59 +18,59 @@ * A utility class to help with building Appointment Objects. */ public class AppointmentBuilder { - public static final Person DEFAULT_PERSON = TypicalPersons.ALICE; - public static final PetPatient DEFAULT_PET_PATIENT = TypicalPetPatients.JOKER; + public static final String DEFAULT_OWNER_NRIC = "S1012341B"; + public static final String DEFAULT_PET_PATIENT_NAME = "Joker"; public static final String DEFAULT_REMARK = "Requires home visit"; public static final String DEFAULT_DATE = "2018-12-31 12:30"; - public static final String DEFAULT_TYPE = "surgery"; + public static final String DEFAULT_APPOINTMENT_TAG = "surgery"; - private Nric owner; - private PetPatientName petPatient; + private Nric ownerNric; + private PetPatientName petPatientName; private Remark remark; private LocalDateTime localDateTime; - private Set type; + private Set appointmentTags; public AppointmentBuilder() { - owner = DEFAULT_PERSON.getNric(); - petPatient = DEFAULT_PET_PATIENT.getName(); + ownerNric = new Nric(DEFAULT_OWNER_NRIC); + petPatientName = new PetPatientName(DEFAULT_PET_PATIENT_NAME); remark = new Remark(DEFAULT_REMARK); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); localDateTime = LocalDateTime.parse(DEFAULT_DATE, formatter); - type = SampleDataUtil.getTagSet(DEFAULT_TYPE); + appointmentTags = SampleDataUtil.getTagSet(DEFAULT_APPOINTMENT_TAG); } /** * Initializes the AppointmentBuilder with the data of {@code appointmentToCopy}. */ public AppointmentBuilder(Appointment appointmentToCopy) { - owner = appointmentToCopy.getOwnerNric(); - petPatient = appointmentToCopy.getPetPatientName(); + ownerNric = appointmentToCopy.getOwnerNric(); + petPatientName = appointmentToCopy.getPetPatientName(); remark = appointmentToCopy.getRemark(); localDateTime = appointmentToCopy.getDateTime(); - type = new HashSet<>(appointmentToCopy.getType()); + appointmentTags = new HashSet<>(appointmentToCopy.getAppointmentTags()); } /** - * Sets the {@code Person} of the {@code Appointment} that we are building. + * Sets the {@code Nric} of the person of the {@code Appointment} that we are building. */ - public AppointmentBuilder withOwner(Nric owner) { - this.owner = owner; + public AppointmentBuilder withOwnerNric(String ownerNric) { + this.ownerNric = new Nric(ownerNric); return this; } /** - * Sets the {@code PetPatient} of the {@code Appointment} that we are building. + * Sets the {@code PetPatientName} of the pet of the {@code Appointment} that we are building. */ - public AppointmentBuilder withPetPatient(PetPatientName petPatient) { - this.petPatient = petPatient; + public AppointmentBuilder withPetPatientName(String petPatientName) { + this.petPatientName = new PetPatientName(petPatientName); return this; } /** - * Parses the {@code type} into a {@code Set} and set it to the {@code Appointment} that we are building. + * Parses the {@code appointmentTags} into a {@code Set} and set it to the {@code Appointment} that we are building. */ - public AppointmentBuilder withTags(String ... type) { - this.type = SampleDataUtil.getTagSet(type); + public AppointmentBuilder withAppointmentTags(String ... appointmentTags) { + this.appointmentTags = SampleDataUtil.getTagSet(appointmentTags); return this; } @@ -93,6 +93,6 @@ public AppointmentBuilder withDateTime(String stringDateTime) { } public Appointment build() { - return new Appointment(owner, petPatient, remark, localDateTime, type); + return new Appointment(ownerNric, petPatientName, remark, localDateTime, appointmentTags); } } diff --git a/src/test/java/seedu/address/testutil/AppointmentUtil.java b/src/test/java/seedu/address/testutil/AppointmentUtil.java index 6acba6010940..21e394d880e7 100644 --- a/src/test/java/seedu/address/testutil/AppointmentUtil.java +++ b/src/test/java/seedu/address/testutil/AppointmentUtil.java @@ -1,7 +1,8 @@ package seedu.address.testutil; import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_OWNER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC; import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; @@ -11,29 +12,16 @@ * A utility class for Appointment. */ public class AppointmentUtil { - /** - * Returns an add appointment command string for adding the {@code appointment}. - */ - //public static String getAddAppointmentCommand(Appointment appointment) { - // return AddAppointmentCommand.COMMAND_WORD + " " + getAppointmentDetails(appointment); - //} - - /** - * Returns an add appointment command string for adding the {@code appointment}. - */ - //public static String getAddAppointmentCommandAlias(Appointment appointment) { - // return AddAppointmentCommand.COMMAND_ALIAS + " " + getAppointmentDetails(appointment); - //} - /** * Returns the part of command string for the given {@code appointment}'s details. */ public static String getAppointmentDetails(Appointment appointment) { StringBuilder sb = new StringBuilder(); - sb.append(PREFIX_OWNER + appointment.getOwnerNric().toString() + " "); + sb.append(PREFIX_NRIC + appointment.getOwnerNric().toString() + " "); + sb.append(PREFIX_NAME + appointment.getPetPatientName().toString() + " "); sb.append(PREFIX_REMARK + appointment.getRemark().value + " "); sb.append(PREFIX_DATE + appointment.getFormattedLocalDateTime() + " "); - appointment.getType().stream().forEach( + appointment.getAppointmentTags().stream().forEach( s -> sb.append(PREFIX_TAG + s.tagName + " ") ); return sb.toString(); diff --git a/src/test/java/seedu/address/testutil/TypicalAppointments.java b/src/test/java/seedu/address/testutil/TypicalAppointments.java index a69c45c42bbc..36f1121e8d39 100644 --- a/src/test/java/seedu/address/testutil/TypicalAppointments.java +++ b/src/test/java/seedu/address/testutil/TypicalAppointments.java @@ -11,12 +11,18 @@ */ public class TypicalAppointments { - public static final Appointment ALLY = new AppointmentBuilder().withOwner(TypicalPersons.ALICE.getNric()) - .withRemark("Requires Home Visit").withDateTime("2018-12-31 12:30") - .withTags("checkup").build(); - public static final Appointment BENNY = new AppointmentBuilder().withOwner(TypicalPersons.BENSON.getNric()) - .withRemark("May require isolation").withDateTime("2018-12-31 14:30") - .withTags("surgery").build(); + public static final Appointment ALLY = new AppointmentBuilder() + .withOwnerNric("S9012345A") + .withPetPatientName("Hammy") + .withRemark("Requires Home Visit") + .withDateTime("2018-12-31 12:30") + .withAppointmentTags("checkup").build(); + public static final Appointment BENNY = new AppointmentBuilder() + .withOwnerNric("S1239049B") + .withPetPatientName("Lissy") + .withRemark("May require isolation") + .withDateTime("2018-12-31 14:30") + .withAppointmentTags("surgery").build(); private TypicalAppointments() {} // prevents instantiation From 7187acb729ef7fee65a34b08f46ace184de7855b Mon Sep 17 00:00:00 2001 From: wynonaK <35650845+wynonaK@users.noreply.github.com> Date: Mon, 26 Mar 2018 14:59:43 +0800 Subject: [PATCH 2/4] Removed unused imports. --- src/main/java/seedu/address/model/appointment/Appointment.java | 1 - src/main/java/seedu/address/storage/XmlAdaptedAppointment.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/seedu/address/model/appointment/Appointment.java b/src/main/java/seedu/address/model/appointment/Appointment.java index eb3162820d3d..3d7d20667898 100644 --- a/src/main/java/seedu/address/model/appointment/Appointment.java +++ b/src/main/java/seedu/address/model/appointment/Appointment.java @@ -8,7 +8,6 @@ import java.util.Objects; import java.util.Set; -import seedu.address.model.person.Name; import seedu.address.model.person.Nric; import seedu.address.model.petpatient.PetPatientName; import seedu.address.model.tag.Tag; diff --git a/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java b/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java index dc0b0cb06e6b..5198cfc3152b 100644 --- a/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java +++ b/src/main/java/seedu/address/storage/XmlAdaptedAppointment.java @@ -14,7 +14,6 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.appointment.Appointment; import seedu.address.model.appointment.Remark; -import seedu.address.model.person.Name; import seedu.address.model.person.Nric; import seedu.address.model.petpatient.PetPatientName; import seedu.address.model.tag.Tag; From 5508036933f10242719bcc73c3eb1652b1d439ff Mon Sep 17 00:00:00 2001 From: wynonaK <35650845+wynonaK@users.noreply.github.com> Date: Mon, 26 Mar 2018 15:09:40 +0800 Subject: [PATCH 3/4] Removed unused imports, made new line for a line > 120 characters. --- src/test/java/seedu/address/model/AddressBookTest.java | 2 -- src/test/java/seedu/address/testutil/AppointmentBuilder.java | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index df39cd0c6166..4dbc04c99eb6 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -4,7 +4,6 @@ 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_UNUSED; -// import static seedu.address.testutil.TypicalAppointments.ALLY; import static seedu.address.testutil.TypicalAppointments.ALLY; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.AMY; @@ -21,7 +20,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; -import javafx.beans.binding.ObjectExpression; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import seedu.address.model.appointment.Appointment; diff --git a/src/test/java/seedu/address/testutil/AppointmentBuilder.java b/src/test/java/seedu/address/testutil/AppointmentBuilder.java index 47518f38e465..bcefeac566d4 100644 --- a/src/test/java/seedu/address/testutil/AppointmentBuilder.java +++ b/src/test/java/seedu/address/testutil/AppointmentBuilder.java @@ -8,8 +8,6 @@ import seedu.address.model.appointment.Appointment; import seedu.address.model.appointment.Remark; import seedu.address.model.person.Nric; -import seedu.address.model.person.Person; -import seedu.address.model.petpatient.PetPatient; import seedu.address.model.petpatient.PetPatientName; import seedu.address.model.tag.Tag; import seedu.address.model.util.SampleDataUtil; @@ -67,7 +65,8 @@ public AppointmentBuilder withPetPatientName(String petPatientName) { } /** - * Parses the {@code appointmentTags} into a {@code Set} and set it to the {@code Appointment} that we are building. + * Parses the {@code appointmentTags} into a {@code Set} + * and set it to the {@code Appointment} that we are building. */ public AppointmentBuilder withAppointmentTags(String ... appointmentTags) { this.appointmentTags = SampleDataUtil.getTagSet(appointmentTags); From 2eb48510e7c142399dd2a00498f837067a1a2fe5 Mon Sep 17 00:00:00 2001 From: wynonaK <35650845+wynonaK@users.noreply.github.com> Date: Mon, 26 Mar 2018 15:14:30 +0800 Subject: [PATCH 4/4] Removed trailing whitespace from appointmentbuilder line 68. --- src/test/java/seedu/address/testutil/AppointmentBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/seedu/address/testutil/AppointmentBuilder.java b/src/test/java/seedu/address/testutil/AppointmentBuilder.java index bcefeac566d4..fc95ffed1a57 100644 --- a/src/test/java/seedu/address/testutil/AppointmentBuilder.java +++ b/src/test/java/seedu/address/testutil/AppointmentBuilder.java @@ -65,7 +65,7 @@ public AppointmentBuilder withPetPatientName(String petPatientName) { } /** - * Parses the {@code appointmentTags} into a {@code Set} + * Parses the {@code appointmentTags} into a {@code Set} * and set it to the {@code Appointment} that we are building. */ public AppointmentBuilder withAppointmentTags(String ... appointmentTags) {