From 05431310a24d88715113244881f256d53ca102a4 Mon Sep 17 00:00:00 2001 From: jaredlhf Date: Wed, 13 Oct 2021 04:22:37 +0800 Subject: [PATCH 1/9] incorporate dates to add command and update test cases --- .../logic/commands/AddCommand.java | 6 +- .../logic/parser/AddCommandParser.java | 7 +- .../java/safeforhall/model/person/Person.java | 14 ++- .../logic/commands/CommandTestUtil.java | 14 ++- .../logic/parser/AddCommandParserTest.java | 90 ++++++++++++++----- 5 files changed, 99 insertions(+), 32 deletions(-) diff --git a/src/main/java/safeforhall/logic/commands/AddCommand.java b/src/main/java/safeforhall/logic/commands/AddCommand.java index 51718a98fa8..c295452d338 100644 --- a/src/main/java/safeforhall/logic/commands/AddCommand.java +++ b/src/main/java/safeforhall/logic/commands/AddCommand.java @@ -22,7 +22,6 @@ public class AddCommand extends Command { + CliSyntax.PREFIX_EMAIL + "EMAIL " + CliSyntax.PREFIX_VACCSTATUS + "VACCINATION STATUS " + CliSyntax.PREFIX_FACULTY + "FACULTY " - //TODO + CliSyntax.PREFIX_FETDATE + "LAST FET DATE " + CliSyntax.PREFIX_COLLECTIONDATE + "LAST COLLECTION DATE \n" @@ -33,9 +32,8 @@ public class AddCommand extends Command { + CliSyntax.PREFIX_EMAIL + "johnd@example.com " + CliSyntax.PREFIX_VACCSTATUS + "T " + CliSyntax.PREFIX_FACULTY + "SoC " - //TODO - + CliSyntax.PREFIX_FETDATE + "TODO " - + CliSyntax.PREFIX_COLLECTIONDATE + "TODO "; + + CliSyntax.PREFIX_FETDATE + "20-10-2021 " + + CliSyntax.PREFIX_COLLECTIONDATE + "23-10-2021 "; public static final String MESSAGE_SUCCESS = "New resident added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This resident already exists in the address book"; diff --git a/src/main/java/safeforhall/logic/parser/AddCommandParser.java b/src/main/java/safeforhall/logic/parser/AddCommandParser.java index 94134c63209..f25a70607f4 100644 --- a/src/main/java/safeforhall/logic/parser/AddCommandParser.java +++ b/src/main/java/safeforhall/logic/parser/AddCommandParser.java @@ -16,6 +16,7 @@ import safeforhall.logic.parser.exceptions.ParseException; import safeforhall.model.person.Email; import safeforhall.model.person.Faculty; +import safeforhall.model.person.LastDate; import safeforhall.model.person.Name; import safeforhall.model.person.Person; import safeforhall.model.person.Phone; @@ -36,7 +37,7 @@ public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ROOM, PREFIX_VACCSTATUS, PREFIX_FACULTY, - PREFIX_FETDATE, PREFIX_COLLECTIONDATE); + PREFIX_FETDATE, PREFIX_COLLECTIONDATE, PREFIX_FETDATE, PREFIX_COLLECTIONDATE); if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ROOM, PREFIX_VACCSTATUS, PREFIX_FACULTY) @@ -50,8 +51,10 @@ public AddCommand parse(String args) throws ParseException { Room room = ParserUtil.parseRoom(argMultimap.getValue(PREFIX_ROOM).get()); VaccStatus vaccStatus = ParserUtil.parseVaccStatus(argMultimap.getValue(PREFIX_VACCSTATUS).get()); Faculty faculty = ParserUtil.parseFaculty(argMultimap.getValue(PREFIX_FACULTY).get()); + LastDate lastFetDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_FETDATE).get()); + LastDate lastCollectionDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_COLLECTIONDATE).get()); - Person person = new Person(name, room, phone, email, vaccStatus, faculty, null, null); + Person person = new Person(name, room, phone, email, vaccStatus, faculty, lastFetDate, lastCollectionDate); return new AddCommand(person); } diff --git a/src/main/java/safeforhall/model/person/Person.java b/src/main/java/safeforhall/model/person/Person.java index a8172c485a2..e9a968e4b8c 100644 --- a/src/main/java/safeforhall/model/person/Person.java +++ b/src/main/java/safeforhall/model/person/Person.java @@ -23,12 +23,12 @@ public class Person { private final LastDate lastCollectionDate; /** - * Every field must be present and only last 3 can be null. + * Every field must be present and only last 2 can be null. */ public Person(Name name, Room room, Phone phone, Email email, VaccStatus vaccStatus, Faculty faculty, LastDate lastFetDate, LastDate lastCollectionDate) { - // Optionals: faculty, lastFetDate, lastCollectionDate - requireAllNonNull(name, room, phone, email, vaccStatus); + // Optionals: lastFetDate, lastCollectionDate + requireAllNonNull(name, room, phone, email, vaccStatus, faculty); this.name = name; this.room = room; this.phone = phone; @@ -102,7 +102,9 @@ public boolean equals(Object other) { return otherPerson.getName().equals(getName()) && otherPerson.getRoom().equals(getRoom()) && otherPerson.getPhone().equals(getPhone()) - && otherPerson.getEmail().equals(getEmail()); + && otherPerson.getEmail().equals(getEmail()) + && otherPerson.getVaccStatus().equals(getVaccStatus()) + && otherPerson.getFaculty().equals(getFaculty()); } @Override @@ -125,6 +127,10 @@ public String toString() { .append(getVaccStatus()) .append("; Faculty: ") .append(getFaculty()); + /*.append("; Last Fet Date: ") + .append(getLastFetDate()) + .append("; Last Collection Date: ") + .append(getLastCollectionDate());*/ return builder.toString(); } diff --git a/src/test/java/safeforhall/logic/commands/CommandTestUtil.java b/src/test/java/safeforhall/logic/commands/CommandTestUtil.java index 8cb8d72d382..d9ac5ace50c 100644 --- a/src/test/java/safeforhall/logic/commands/CommandTestUtil.java +++ b/src/test/java/safeforhall/logic/commands/CommandTestUtil.java @@ -2,10 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static safeforhall.logic.parser.CliSyntax.PREFIX_COLLECTIONDATE; import static safeforhall.logic.parser.CliSyntax.PREFIX_DATE1; import static safeforhall.logic.parser.CliSyntax.PREFIX_DATE2; import static safeforhall.logic.parser.CliSyntax.PREFIX_EMAIL; import static safeforhall.logic.parser.CliSyntax.PREFIX_FACULTY; +import static safeforhall.logic.parser.CliSyntax.PREFIX_FETDATE; import static safeforhall.logic.parser.CliSyntax.PREFIX_KEYWORD; import static safeforhall.logic.parser.CliSyntax.PREFIX_NAME; import static safeforhall.logic.parser.CliSyntax.PREFIX_PHONE; @@ -42,6 +44,10 @@ public class CommandTestUtil { public static final String VALID_FACULTY_BOB = "FASS"; public static final String VALID_VACCSTATUS_AMY = "T"; public static final String VALID_VACCSTATUS_BOB = "F"; + public static final String VALID_FETDATE_AMY = "20-11-2021"; + public static final String VALID_FETDATE_BOB = "02-09-2021"; + public static final String VALID_COLLECTIONDATE_AMY = "22-11-2021"; + public static final String VALID_COLLECTIONDATE_BOB = "12-09-2021"; public static final String VALID_LAST_DATE1_OCT = "10-10-2021"; public static final String VALID_LAST_DATE2_OCT = "15-10-2021"; public static final String VALID_KEYWORD_F = "f"; @@ -59,6 +65,10 @@ public class CommandTestUtil { public static final String FACULTY_DESC_BOB = " " + PREFIX_FACULTY + VALID_FACULTY_BOB; public static final String VACCSTATUS_DESC_AMY = " " + PREFIX_VACCSTATUS + VALID_VACCSTATUS_AMY; public static final String VACCSTATUS_DESC_BOB = " " + PREFIX_VACCSTATUS + VALID_VACCSTATUS_BOB; + public static final String FET_DESC_AMY = " " + PREFIX_FETDATE + VALID_FETDATE_AMY; + public static final String FET_DESC_BOB = " " + PREFIX_FETDATE + VALID_FETDATE_BOB; + public static final String COLLECTION_DESC_AMY = " " + PREFIX_COLLECTIONDATE + VALID_COLLECTIONDATE_AMY; + public static final String COLLECTION_DESC_BOB = " " + PREFIX_COLLECTIONDATE + VALID_COLLECTIONDATE_BOB; public static final String LAST_DATE1_DESC_OCT = " " + PREFIX_DATE1 + VALID_LAST_DATE1_OCT; public static final String LAST_DATE2_DESC_OCT = " " + PREFIX_DATE2 + VALID_LAST_DATE2_OCT; public static final String KEYWORD_DESC_F = " " + PREFIX_KEYWORD + VALID_KEYWORD_F; @@ -70,7 +80,9 @@ public class CommandTestUtil { public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol public static final String INVALID_ROOM_DESC = " " + PREFIX_ROOM; // empty string not allowed for room public static final String INVALID_FACULTY_DESC = " " + PREFIX_FACULTY; // empty string not allowed for faculty - public static final String INVALID_VACCSTATUS_DESC = " " + PREFIX_VACCSTATUS + "fake"; //only T or F allowed + public static final String INVALID_VACCSTATUS_DESC = " " + PREFIX_VACCSTATUS + "fake"; // only T or F allowed + public static final String INVALID_FETDATE_DESC = " " + PREFIX_FETDATE + "41-20-20"; // not valid date + public static final String INVALID_COLLECTIONDATE_DESC = " " + PREFIX_FETDATE + "41/20/20"; // not valid date public static final String PREAMBLE_WHITESPACE = "\t \r \n"; public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble"; diff --git a/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java b/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java index 542dbdb5cb6..c263820da4a 100644 --- a/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java +++ b/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java @@ -1,11 +1,17 @@ package safeforhall.logic.parser; +import static safeforhall.logic.commands.CommandTestUtil.COLLECTION_DESC_AMY; +import static safeforhall.logic.commands.CommandTestUtil.COLLECTION_DESC_BOB; import static safeforhall.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.EMAIL_DESC_BOB; import static safeforhall.logic.commands.CommandTestUtil.FACULTY_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.FACULTY_DESC_BOB; +import static safeforhall.logic.commands.CommandTestUtil.FET_DESC_AMY; +import static safeforhall.logic.commands.CommandTestUtil.FET_DESC_BOB; +import static safeforhall.logic.commands.CommandTestUtil.INVALID_COLLECTIONDATE_DESC; import static safeforhall.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC; import static safeforhall.logic.commands.CommandTestUtil.INVALID_FACULTY_DESC; +import static safeforhall.logic.commands.CommandTestUtil.INVALID_FETDATE_DESC; import static safeforhall.logic.commands.CommandTestUtil.INVALID_NAME_DESC; import static safeforhall.logic.commands.CommandTestUtil.INVALID_PHONE_DESC; import static safeforhall.logic.commands.CommandTestUtil.INVALID_ROOM_DESC; @@ -28,15 +34,18 @@ import static safeforhall.logic.commands.CommandTestUtil.VALID_VACCSTATUS_BOB; import static safeforhall.logic.parser.CommandParserTestUtil.assertParseFailure; import static safeforhall.logic.parser.CommandParserTestUtil.assertParseSuccess; -//import static safeforhall.testutil.TypicalPersons.AMY; +import static safeforhall.testutil.TypicalPersons.AMY; import static safeforhall.testutil.TypicalPersons.BOB; +import java.time.LocalDate; + import org.junit.jupiter.api.Test; import safeforhall.commons.core.Messages; import safeforhall.logic.commands.AddCommand; import safeforhall.model.person.Email; import safeforhall.model.person.Faculty; +import safeforhall.model.person.LastDate; import safeforhall.model.person.Name; import safeforhall.model.person.Person; import safeforhall.model.person.Phone; @@ -53,40 +62,62 @@ public void parse_allFieldsPresent_success() { // whitespace only preamble assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple names - last name accepted assertParseSuccess(parser, NAME_DESC_AMY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple phones - last phone accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_AMY + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple emails - last email accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_AMY + EMAIL_DESC_BOB - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple rooms - last room accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_AMY - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple faculties - last faculty accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_AMY + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + FACULTY_DESC_AMY + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple vaccination status - last vaccStatus accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_BOB + VACCSTATUS_DESC_AMY + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_AMY + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); + + // multiple fet dates - last fet date accepted + assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB + + FACULTY_DESC_BOB + VACCSTATUS_DESC_AMY + VACCSTATUS_DESC_BOB + + FET_DESC_AMY + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); + + // multiple collection dates - last collection date accepted + assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB + + FACULTY_DESC_BOB + VACCSTATUS_DESC_AMY + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_AMY + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); } - /*@Test + @Test public void parse_optionalFieldsMissing_success() { - // zero tags Person expectedPerson = new PersonBuilder(AMY).build(); - assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ADDRESS_DESC_AMY, - new AddCommand(expectedPerson)); - }*/ + + // missing lastFetDate + assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ROOM_DESC_AMY + + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + COLLECTION_DESC_AMY, new AddCommand(expectedPerson)); + + // missing lastCollectionDate + assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ROOM_DESC_AMY + + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + FET_DESC_AMY, new AddCommand(expectedPerson)); + } @Test public void parse_compulsoryFieldMissing_failure() { @@ -125,35 +156,52 @@ public void parse_compulsoryFieldMissing_failure() { public void parse_invalidValue_failure() { // invalid name assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, Name.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Name.MESSAGE_CONSTRAINTS); // invalid phone assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, Phone.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Phone.MESSAGE_CONSTRAINTS); // invalid email assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + ROOM_DESC_BOB - + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, Email.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Email.MESSAGE_CONSTRAINTS); // invalid room assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ROOM_DESC - + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, Room.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Room.MESSAGE_CONSTRAINTS); // invalid faculty assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + INVALID_FACULTY_DESC + VACCSTATUS_DESC_BOB, Faculty.MESSAGE_CONSTRAINTS); + + INVALID_FACULTY_DESC + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Faculty.MESSAGE_CONSTRAINTS); // invalid vaccination status assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_BOB + INVALID_VACCSTATUS_DESC, VaccStatus.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + INVALID_VACCSTATUS_DESC + FET_DESC_BOB + + COLLECTION_DESC_BOB, VaccStatus.MESSAGE_CONSTRAINTS); + + // invalid FET date + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB + + FACULTY_DESC_BOB + INVALID_VACCSTATUS_DESC + INVALID_FETDATE_DESC + + COLLECTION_DESC_BOB, LastDate.MESSAGE_CONSTRAINTS); + + // invalid collection date + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB + + FACULTY_DESC_BOB + INVALID_VACCSTATUS_DESC + FET_DESC_BOB + + INVALID_COLLECTIONDATE_DESC, LastDate.MESSAGE_CONSTRAINTS); // two invalid values, only first invalid value reported assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ROOM_DESC - + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, Name.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Name.MESSAGE_CONSTRAINTS); // non-empty preamble assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + COLLECTION_DESC_BOB, String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } } From 3aec27ee69c4bc28cf68f565d0bf6c83cf2fba4a Mon Sep 17 00:00:00 2001 From: jaredlhf Date: Wed, 13 Oct 2021 17:34:28 +0800 Subject: [PATCH 2/9] fix bugs --- .../logic/commands/EditCommand.java | 6 +-- .../logic/parser/AddCommandParser.java | 11 +++-- .../safeforhall/model/person/LastDate.java | 4 ++ .../java/safeforhall/model/person/Person.java | 13 +++-- .../typicalPersonsAddressBook.json | 48 +++++++++---------- .../safeforhall/logic/LogicManagerTest.java | 6 +-- .../logic/parser/AddCommandParserTest.java | 10 ++-- .../model/person/LastDateTest.java | 2 +- .../testutil/EditPersonDescriptorBuilder.java | 4 +- .../safeforhall/testutil/TypicalPersons.java | 30 +++++++----- 10 files changed, 74 insertions(+), 60 deletions(-) diff --git a/src/main/java/safeforhall/logic/commands/EditCommand.java b/src/main/java/safeforhall/logic/commands/EditCommand.java index 821754e2d21..a0fab0cebb1 100644 --- a/src/main/java/safeforhall/logic/commands/EditCommand.java +++ b/src/main/java/safeforhall/logic/commands/EditCommand.java @@ -253,9 +253,9 @@ && getPhone().equals(e.getPhone()) && getEmail().equals(e.getEmail()) && getRoom().equals(e.getRoom()) && getVaccStatus().equals(e.getVaccStatus()) - && getFaculty().equals(e.getFaculty()) - && getLastFetDate().equals(e.getLastFetDate()) - && getLastCollectionDate().equals(e.getLastCollectionDate()); + && getFaculty().equals(e.getFaculty()); + /*&& getLastFetDate().equals(e.getLastFetDate()) + && getLastCollectionDate().equals(e.getLastCollectionDate());*/ } } } diff --git a/src/main/java/safeforhall/logic/parser/AddCommandParser.java b/src/main/java/safeforhall/logic/parser/AddCommandParser.java index f25a70607f4..c525ece163c 100644 --- a/src/main/java/safeforhall/logic/parser/AddCommandParser.java +++ b/src/main/java/safeforhall/logic/parser/AddCommandParser.java @@ -37,7 +37,7 @@ public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ROOM, PREFIX_VACCSTATUS, PREFIX_FACULTY, - PREFIX_FETDATE, PREFIX_COLLECTIONDATE, PREFIX_FETDATE, PREFIX_COLLECTIONDATE); + PREFIX_FETDATE, PREFIX_COLLECTIONDATE); if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ROOM, PREFIX_VACCSTATUS, PREFIX_FACULTY) @@ -45,14 +45,19 @@ public AddCommand parse(String args) throws ParseException { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } + // Required fields 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()); Room room = ParserUtil.parseRoom(argMultimap.getValue(PREFIX_ROOM).get()); VaccStatus vaccStatus = ParserUtil.parseVaccStatus(argMultimap.getValue(PREFIX_VACCSTATUS).get()); Faculty faculty = ParserUtil.parseFaculty(argMultimap.getValue(PREFIX_FACULTY).get()); - LastDate lastFetDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_FETDATE).get()); - LastDate lastCollectionDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_COLLECTIONDATE).get()); + + // Optional fields + LastDate lastFetDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_FETDATE) + .orElse(LastDate.DEFAULT_DATE)); + LastDate lastCollectionDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_COLLECTIONDATE) + .orElse(LastDate.DEFAULT_DATE)); Person person = new Person(name, room, phone, email, vaccStatus, faculty, lastFetDate, lastCollectionDate); return new AddCommand(person); diff --git a/src/main/java/safeforhall/model/person/LastDate.java b/src/main/java/safeforhall/model/person/LastDate.java index 16fe384d4cf..30bc521d299 100644 --- a/src/main/java/safeforhall/model/person/LastDate.java +++ b/src/main/java/safeforhall/model/person/LastDate.java @@ -8,6 +8,7 @@ public class LastDate { public static final String MESSAGE_CONSTRAINTS = "Date inputted has to be in dd-mm-yyyy format"; + public static final String DEFAULT_DATE = ""; private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); @@ -29,6 +30,9 @@ public LastDate(String date) { * Returns true if a given string is a valid date. */ public static boolean isValidDate(String date) { + if (date == DEFAULT_DATE) { + return true; + } try { LocalDate.parse(date, dateFormatter); } catch (DateTimeParseException e) { diff --git a/src/main/java/safeforhall/model/person/Person.java b/src/main/java/safeforhall/model/person/Person.java index e9a968e4b8c..4ffb144e302 100644 --- a/src/main/java/safeforhall/model/person/Person.java +++ b/src/main/java/safeforhall/model/person/Person.java @@ -23,12 +23,11 @@ public class Person { private final LastDate lastCollectionDate; /** - * Every field must be present and only last 2 can be null. + * Every field must be present. */ public Person(Name name, Room room, Phone phone, Email email, VaccStatus vaccStatus, Faculty faculty, LastDate lastFetDate, LastDate lastCollectionDate) { - // Optionals: lastFetDate, lastCollectionDate - requireAllNonNull(name, room, phone, email, vaccStatus, faculty); + requireAllNonNull(name, room, phone, email, vaccStatus, faculty, lastFetDate, lastCollectionDate); this.name = name; this.room = room; this.phone = phone; @@ -127,10 +126,10 @@ public String toString() { .append(getVaccStatus()) .append("; Faculty: ") .append(getFaculty()); - /*.append("; Last Fet Date: ") - .append(getLastFetDate()) - .append("; Last Collection Date: ") - .append(getLastCollectionDate());*/ + /*.append("; Last Fet Date: ") + .append(getLastFetDate()) + .append("; Last Collection Date: ") + .append(getLastCollectionDate());*/ return builder.toString(); } diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json index efaa8cb652b..86a87dc57a6 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json @@ -6,62 +6,62 @@ "phone" : "94351253", "email" : "alice@example.com", "vaccStatus" : "T", - "faculty" : "SoC", - "lastFetDate" : "09-09-2021", - "lastCollectionDate" : "10-09-2021" + "faculty" : "S0C", + "lastFetDate" : "03-10-2021", + "lastCollectionDate" : "03-10-2021" }, { "name" : "Benson Meier", "room" : "A101", "phone" : "98765432", "email" : "johnd@example.com", "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "10-09-2021", - "lastCollectionDate" : "11-09-2021" + "faculty" : "SOC", + "lastFetDate" : "12-10-2021", + "lastCollectionDate" : "13-10-2021" }, { "name" : "Carl Kurz", "room" : "A102", "phone" : "95352563", "email" : "heinz@example.com", - "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "11-09-2021", - "lastCollectionDate" : "12-09-2021" + "vaccStatus" : "F", + "faculty" : "SOC", + "lastFetDate" : "10-10-2021", + "lastCollectionDate" : "03-10-2021" }, { "name" : "Daniel Meier", "room" : "A103", "phone" : "87652533", "email" : "cornelia@example.com", "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "09-09-2021", - "lastCollectionDate" : "08-09-2021" + "faculty" : "SOC", + "lastFetDate" : "12-10-2021", + "lastCollectionDate" : "13-10-2021" }, { "name" : "Elle Meyer", "room" : "A104", "phone" : "9482224", "email" : "werner@example.com", - "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "12-09-2021", - "lastCollectionDate" : "12-09-2021" + "vaccStatus" : "F", + "faculty" : "SOC", + "lastFetDate" : "05-10-2021", + "lastCollectionDate" : "16-10-2021" }, { "name" : "Fiona Kunz", "room" : "A105", "phone" : "9482427", "email" : "lydia@example.com", "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "20-09-2021", - "lastCollectionDate" : "21-09-2021" + "faculty" : "SOC", + "lastFetDate" : "20-10-2021", + "lastCollectionDate" : "04-10-2021" }, { "name" : "George Best", "room" : "A106", "phone" : "9482442", "email" : "anna@example.com", - "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "01-09-2021", - "lastCollectionDate" : "22-09-2021" + "vaccStatus" : "F", + "faculty" : "SOC", + "lastFetDate" : "15-10-2021", + "lastCollectionDate" : "01-10-2021" } ] } diff --git a/src/test/java/safeforhall/logic/LogicManagerTest.java b/src/test/java/safeforhall/logic/LogicManagerTest.java index 2716c052c3a..0c860cc402b 100644 --- a/src/test/java/safeforhall/logic/LogicManagerTest.java +++ b/src/test/java/safeforhall/logic/LogicManagerTest.java @@ -1,10 +1,10 @@ package safeforhall.logic; import static org.junit.jupiter.api.Assertions.assertEquals; +import static safeforhall.logic.commands.CommandTestUtil.COLLECTION_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.FACULTY_DESC_AMY; -import static safeforhall.logic.commands.CommandTestUtil.LAST_DATE1_DESC_OCT; -import static safeforhall.logic.commands.CommandTestUtil.LAST_DATE2_DESC_OCT; +import static safeforhall.logic.commands.CommandTestUtil.FET_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.NAME_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.PHONE_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.ROOM_DESC_AMY; @@ -103,7 +103,7 @@ public void execute_storageThrowsIoException_throwsCommandException() { // Execute add command String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + ROOM_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY - + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + LAST_DATE1_DESC_OCT + LAST_DATE2_DESC_OCT; + + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + FET_DESC_AMY + COLLECTION_DESC_AMY; Person expectedPerson = new PersonBuilder(TypicalPersons.AMY).build(); ModelManager expectedModel = new ModelManager(); expectedModel.addPerson(expectedPerson); diff --git a/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java b/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java index c263820da4a..c2d4736c96c 100644 --- a/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java +++ b/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java @@ -37,8 +37,6 @@ import static safeforhall.testutil.TypicalPersons.AMY; import static safeforhall.testutil.TypicalPersons.BOB; -import java.time.LocalDate; - import org.junit.jupiter.api.Test; import safeforhall.commons.core.Messages; @@ -110,6 +108,10 @@ public void parse_allFieldsPresent_success() { public void parse_optionalFieldsMissing_success() { Person expectedPerson = new PersonBuilder(AMY).build(); + // missing lastFetDate and lastCollectionDate + assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ROOM_DESC_AMY + + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY, new AddCommand(expectedPerson)); + // missing lastFetDate assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ROOM_DESC_AMY + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + COLLECTION_DESC_AMY, new AddCommand(expectedPerson)); @@ -186,12 +188,12 @@ public void parse_invalidValue_failure() { // invalid FET date assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_BOB + INVALID_VACCSTATUS_DESC + INVALID_FETDATE_DESC + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + INVALID_FETDATE_DESC + COLLECTION_DESC_BOB, LastDate.MESSAGE_CONSTRAINTS); // invalid collection date assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_BOB + INVALID_VACCSTATUS_DESC + FET_DESC_BOB + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + INVALID_COLLECTIONDATE_DESC, LastDate.MESSAGE_CONSTRAINTS); // two invalid values, only first invalid value reported diff --git a/src/test/java/safeforhall/model/person/LastDateTest.java b/src/test/java/safeforhall/model/person/LastDateTest.java index 4e97d279108..dacad9349f0 100644 --- a/src/test/java/safeforhall/model/person/LastDateTest.java +++ b/src/test/java/safeforhall/model/person/LastDateTest.java @@ -18,7 +18,7 @@ public void isValidDate() { assertThrows(NullPointerException.class, () -> new LastDate(null)); // invalid dates - assertFalse(LastDate.isValidDate("")); + //assertFalse(LastDate.isValidDate("")); assertFalse(LastDate.isValidDate("10.10.2021")); assertFalse(LastDate.isValidDate("10/10/2021")); assertFalse(LastDate.isValidDate("9-9-2021")); diff --git a/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java b/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java index c827b7d4b42..92d010f1527 100644 --- a/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java +++ b/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java @@ -39,10 +39,10 @@ public EditPersonDescriptorBuilder(Person person) { descriptor.setEmail(person.getEmail()); descriptor.setRoom(person.getRoom()); descriptor.setFaculty(person.getFaculty()); + descriptor.setVaccStatus(person.getVaccStatus()); //TODO: lastfetdate and lastcollectiondate - // descriptor.setAddress(person.getAddress()); - // descriptor.setTags(person.getTags()); + } /** diff --git a/src/test/java/safeforhall/testutil/TypicalPersons.java b/src/test/java/safeforhall/testutil/TypicalPersons.java index a0964977e89..9c469148c0a 100644 --- a/src/test/java/safeforhall/testutil/TypicalPersons.java +++ b/src/test/java/safeforhall/testutil/TypicalPersons.java @@ -1,9 +1,13 @@ package safeforhall.testutil; +import static safeforhall.logic.commands.CommandTestUtil.VALID_COLLECTIONDATE_AMY; +import static safeforhall.logic.commands.CommandTestUtil.VALID_COLLECTIONDATE_BOB; import static safeforhall.logic.commands.CommandTestUtil.VALID_EMAIL_AMY; import static safeforhall.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; import static safeforhall.logic.commands.CommandTestUtil.VALID_FACULTY_AMY; import static safeforhall.logic.commands.CommandTestUtil.VALID_FACULTY_BOB; +import static safeforhall.logic.commands.CommandTestUtil.VALID_FETDATE_AMY; +import static safeforhall.logic.commands.CommandTestUtil.VALID_FETDATE_BOB; import static safeforhall.logic.commands.CommandTestUtil.VALID_NAME_AMY; import static safeforhall.logic.commands.CommandTestUtil.VALID_NAME_BOB; import static safeforhall.logic.commands.CommandTestUtil.VALID_PHONE_AMY; @@ -30,7 +34,7 @@ public class TypicalPersons { .withPhone("94351253") .withEmail("alice@example.com") .withVaccStatus("T") - .withFaculty("SoC") + .withFaculty("SOC") .withFet("03-10-2021") .withCollection("03-10-2021") .build(); @@ -39,7 +43,7 @@ public class TypicalPersons { .withEmail("johnd@example.com") .withPhone("98765432") .withVaccStatus("T") - .withFaculty("SoC") + .withFaculty("SOC") .withFet("12-10-2021") .withCollection("13-10-2021") .build(); @@ -48,7 +52,7 @@ public class TypicalPersons { .withPhone("95352563") .withEmail("heinz@example.com") .withVaccStatus("F") - .withFaculty("SoC") + .withFaculty("SOC") .withFet("10-10-2021") .withCollection("03-10-2021") .build(); @@ -57,7 +61,7 @@ public class TypicalPersons { .withPhone("87652533") .withEmail("cornelia@example.com") .withVaccStatus("T") - .withFaculty("SoC") + .withFaculty("SOC") .withFet("12-10-2021") .withCollection("13-10-2021") .build(); @@ -66,7 +70,7 @@ public class TypicalPersons { .withPhone("9482224") .withEmail("werner@example.com") .withVaccStatus("F") - .withFaculty("SoC") + .withFaculty("SOC") .withFet("05-10-2021") .withCollection("16-10-2021") .build(); @@ -75,7 +79,7 @@ public class TypicalPersons { .withPhone("9482427") .withEmail("lydia@example.com") .withVaccStatus("T") - .withFaculty("SoC") + .withFaculty("SOC") .withFet("20-10-2021") .withCollection("04-10-2021") .build(); @@ -84,7 +88,7 @@ public class TypicalPersons { .withPhone("9482442") .withEmail("anna@example.com") .withVaccStatus("F") - .withFaculty("SoC") + .withFaculty("SOC") .withFet("15-10-2021") .withCollection("01-10-2021") .build(); @@ -95,7 +99,7 @@ public class TypicalPersons { .withEmail("stefan@example.com") .withRoom("A103") .withVaccStatus("T") - .withFaculty("SoC") + .withFaculty("SOC") .withFet("15-10-2021") .withCollection("15-10-2021") .build(); @@ -104,7 +108,7 @@ public class TypicalPersons { .withEmail("hans@example.com") .withRoom("C200") .withVaccStatus("F") - .withFaculty("SoC") + .withFaculty("SOC") .withFet("20-10-2021") .withCollection("22-10-2021") .build(); @@ -116,8 +120,8 @@ public class TypicalPersons { .withRoom(VALID_ROOM_AMY) .withFaculty(VALID_FACULTY_AMY) .withVaccStatus(VALID_VACCSTATUS_AMY) - .withFet("09-10-2021") - .withCollection("08-10-2021") + .withFet(VALID_FETDATE_AMY) + .withCollection(VALID_COLLECTIONDATE_AMY) .build(); public static final Person BOB = new PersonBuilder().withName(VALID_NAME_BOB) .withPhone(VALID_PHONE_BOB) @@ -125,8 +129,8 @@ public class TypicalPersons { .withRoom(VALID_ROOM_BOB) .withFaculty(VALID_FACULTY_BOB) .withVaccStatus(VALID_VACCSTATUS_BOB) - .withFet("15-11-2021") - .withCollection("12-11-2021") + .withFet(VALID_FETDATE_BOB) + .withCollection(VALID_COLLECTIONDATE_BOB) .build(); public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER From 6e07558fbca984842f6a944cf975bfe175649870 Mon Sep 17 00:00:00 2001 From: jaredlhf Date: Wed, 13 Oct 2021 17:56:45 +0800 Subject: [PATCH 3/9] fix testcase error --- .../typicalPersonsAddressBook.json | 14 ++++++------- .../safeforhall/testutil/TypicalPersons.java | 20 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json index 86a87dc57a6..da27e36a6a2 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json @@ -6,7 +6,7 @@ "phone" : "94351253", "email" : "alice@example.com", "vaccStatus" : "T", - "faculty" : "S0C", + "faculty" : "SoC", "lastFetDate" : "03-10-2021", "lastCollectionDate" : "03-10-2021" }, { @@ -15,7 +15,7 @@ "phone" : "98765432", "email" : "johnd@example.com", "vaccStatus" : "T", - "faculty" : "SOC", + "faculty" : "SoC", "lastFetDate" : "12-10-2021", "lastCollectionDate" : "13-10-2021" }, { @@ -24,7 +24,7 @@ "phone" : "95352563", "email" : "heinz@example.com", "vaccStatus" : "F", - "faculty" : "SOC", + "faculty" : "SoC", "lastFetDate" : "10-10-2021", "lastCollectionDate" : "03-10-2021" }, { @@ -33,7 +33,7 @@ "phone" : "87652533", "email" : "cornelia@example.com", "vaccStatus" : "T", - "faculty" : "SOC", + "faculty" : "SoC", "lastFetDate" : "12-10-2021", "lastCollectionDate" : "13-10-2021" }, { @@ -42,7 +42,7 @@ "phone" : "9482224", "email" : "werner@example.com", "vaccStatus" : "F", - "faculty" : "SOC", + "faculty" : "SoC", "lastFetDate" : "05-10-2021", "lastCollectionDate" : "16-10-2021" }, { @@ -51,7 +51,7 @@ "phone" : "9482427", "email" : "lydia@example.com", "vaccStatus" : "T", - "faculty" : "SOC", + "faculty" : "SoC", "lastFetDate" : "20-10-2021", "lastCollectionDate" : "04-10-2021" }, { @@ -60,7 +60,7 @@ "phone" : "9482442", "email" : "anna@example.com", "vaccStatus" : "F", - "faculty" : "SOC", + "faculty" : "SoC", "lastFetDate" : "15-10-2021", "lastCollectionDate" : "01-10-2021" } ] diff --git a/src/test/java/safeforhall/testutil/TypicalPersons.java b/src/test/java/safeforhall/testutil/TypicalPersons.java index 9c469148c0a..1a49d715d5a 100644 --- a/src/test/java/safeforhall/testutil/TypicalPersons.java +++ b/src/test/java/safeforhall/testutil/TypicalPersons.java @@ -34,16 +34,16 @@ public class TypicalPersons { .withPhone("94351253") .withEmail("alice@example.com") .withVaccStatus("T") - .withFaculty("SOC") + .withFaculty("SoC") .withFet("03-10-2021") .withCollection("03-10-2021") .build(); public static final Person BENSON = new PersonBuilder().withName("Benson Meier") .withRoom("A101") - .withEmail("johnd@example.com") .withPhone("98765432") + .withEmail("johnd@example.com") .withVaccStatus("T") - .withFaculty("SOC") + .withFaculty("SoC") .withFet("12-10-2021") .withCollection("13-10-2021") .build(); @@ -52,7 +52,7 @@ public class TypicalPersons { .withPhone("95352563") .withEmail("heinz@example.com") .withVaccStatus("F") - .withFaculty("SOC") + .withFaculty("SoC") .withFet("10-10-2021") .withCollection("03-10-2021") .build(); @@ -61,7 +61,7 @@ public class TypicalPersons { .withPhone("87652533") .withEmail("cornelia@example.com") .withVaccStatus("T") - .withFaculty("SOC") + .withFaculty("SoC") .withFet("12-10-2021") .withCollection("13-10-2021") .build(); @@ -70,7 +70,7 @@ public class TypicalPersons { .withPhone("9482224") .withEmail("werner@example.com") .withVaccStatus("F") - .withFaculty("SOC") + .withFaculty("SoC") .withFet("05-10-2021") .withCollection("16-10-2021") .build(); @@ -79,7 +79,7 @@ public class TypicalPersons { .withPhone("9482427") .withEmail("lydia@example.com") .withVaccStatus("T") - .withFaculty("SOC") + .withFaculty("SoC") .withFet("20-10-2021") .withCollection("04-10-2021") .build(); @@ -88,7 +88,7 @@ public class TypicalPersons { .withPhone("9482442") .withEmail("anna@example.com") .withVaccStatus("F") - .withFaculty("SOC") + .withFaculty("SoC") .withFet("15-10-2021") .withCollection("01-10-2021") .build(); @@ -99,7 +99,7 @@ public class TypicalPersons { .withEmail("stefan@example.com") .withRoom("A103") .withVaccStatus("T") - .withFaculty("SOC") + .withFaculty("SoC") .withFet("15-10-2021") .withCollection("15-10-2021") .build(); @@ -108,7 +108,7 @@ public class TypicalPersons { .withEmail("hans@example.com") .withRoom("C200") .withVaccStatus("F") - .withFaculty("SOC") + .withFaculty("SoC") .withFet("20-10-2021") .withCollection("22-10-2021") .build(); From 9f1d4636657e9411ab5642bba7ca7e838371f462 Mon Sep 17 00:00:00 2001 From: jaredlhf Date: Wed, 13 Oct 2021 21:16:49 +0800 Subject: [PATCH 4/9] Fix Regex for Faculty and suggested changes --- .../java/safeforhall/logic/commands/EditCommand.java | 6 +++--- src/main/java/safeforhall/model/person/Faculty.java | 5 +++-- src/main/java/safeforhall/model/person/Person.java | 10 +++++----- .../testutil/EditPersonDescriptorBuilder.java | 5 ++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/safeforhall/logic/commands/EditCommand.java b/src/main/java/safeforhall/logic/commands/EditCommand.java index a0fab0cebb1..821754e2d21 100644 --- a/src/main/java/safeforhall/logic/commands/EditCommand.java +++ b/src/main/java/safeforhall/logic/commands/EditCommand.java @@ -253,9 +253,9 @@ && getPhone().equals(e.getPhone()) && getEmail().equals(e.getEmail()) && getRoom().equals(e.getRoom()) && getVaccStatus().equals(e.getVaccStatus()) - && getFaculty().equals(e.getFaculty()); - /*&& getLastFetDate().equals(e.getLastFetDate()) - && getLastCollectionDate().equals(e.getLastCollectionDate());*/ + && getFaculty().equals(e.getFaculty()) + && getLastFetDate().equals(e.getLastFetDate()) + && getLastCollectionDate().equals(e.getLastCollectionDate()); } } } diff --git a/src/main/java/safeforhall/model/person/Faculty.java b/src/main/java/safeforhall/model/person/Faculty.java index c24790fa67d..1919fe093e5 100644 --- a/src/main/java/safeforhall/model/person/Faculty.java +++ b/src/main/java/safeforhall/model/person/Faculty.java @@ -9,13 +9,14 @@ */ public class Faculty { - public static final String MESSAGE_CONSTRAINTS = "Faculty can take any values, and it should not be blank"; + public static final String MESSAGE_CONSTRAINTS = "Faculty is a single word made up of alphabets " + + "and it should not be blank"; /* * The first character of the faculty must not be a whitespace, * otherwise " " (a blank string) becomes a valid input. */ - public static final String VALIDATION_REGEX = "[^\\s].*"; + public static final String VALIDATION_REGEX = "[A-Za-z]{2,}$"; public final String faculty; diff --git a/src/main/java/safeforhall/model/person/Person.java b/src/main/java/safeforhall/model/person/Person.java index 4ffb144e302..fe70f49645b 100644 --- a/src/main/java/safeforhall/model/person/Person.java +++ b/src/main/java/safeforhall/model/person/Person.java @@ -125,11 +125,11 @@ public String toString() { .append("; Vaccinated: ") .append(getVaccStatus()) .append("; Faculty: ") - .append(getFaculty()); - /*.append("; Last Fet Date: ") - .append(getLastFetDate()) - .append("; Last Collection Date: ") - .append(getLastCollectionDate());*/ + .append(getFaculty()) + .append("; Last Fet Date: ") + .append(getLastFetDate()) + .append("; Last Collection Date: ") + .append(getLastCollectionDate()); return builder.toString(); } diff --git a/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java b/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java index 92d010f1527..7868d1f3602 100644 --- a/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java +++ b/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java @@ -40,9 +40,8 @@ public EditPersonDescriptorBuilder(Person person) { descriptor.setRoom(person.getRoom()); descriptor.setFaculty(person.getFaculty()); descriptor.setVaccStatus(person.getVaccStatus()); - //TODO: lastfetdate and lastcollectiondate - - + descriptor.setLastFetDate(person.getLastFetDate()); + descriptor.setLastCollectionDate(person.getLastCollectionDate()); } /** From f4a734146e7b0304a4dc550b5bab2c9381253fba Mon Sep 17 00:00:00 2001 From: VimuthM Date: Wed, 13 Oct 2021 21:57:15 +0800 Subject: [PATCH 5/9] Fix date parsing bug --- src/main/java/safeforhall/model/person/Faculty.java | 4 ++-- src/main/java/safeforhall/model/person/LastDate.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/safeforhall/model/person/Faculty.java b/src/main/java/safeforhall/model/person/Faculty.java index 1919fe093e5..ad0a3da96ad 100644 --- a/src/main/java/safeforhall/model/person/Faculty.java +++ b/src/main/java/safeforhall/model/person/Faculty.java @@ -9,8 +9,8 @@ */ public class Faculty { - public static final String MESSAGE_CONSTRAINTS = "Faculty is a single word made up of alphabets " + - "and it should not be blank"; + public static final String MESSAGE_CONSTRAINTS = "Faculty is a single word made up of alphabets " + + "and it should not be blank"; /* * The first character of the faculty must not be a whitespace, diff --git a/src/main/java/safeforhall/model/person/LastDate.java b/src/main/java/safeforhall/model/person/LastDate.java index 30bc521d299..d864c9631f7 100644 --- a/src/main/java/safeforhall/model/person/LastDate.java +++ b/src/main/java/safeforhall/model/person/LastDate.java @@ -56,7 +56,9 @@ public LocalDate toLocalDate() { * Adds the period of validity to the given {@code LastDate} to get the next deadline. */ public LocalDate getDeadline() { - return LocalDate.parse(date, dateFormatter).plusWeeks(LASTDATE_DEADLINE); + return date.equals("") + ? LocalDate.now() + : LocalDate.parse(date, dateFormatter).plusWeeks(LASTDATE_DEADLINE); } @Override From 0e261d139c892fcbc19188d3259e243277e34daf Mon Sep 17 00:00:00 2001 From: jaredlhf Date: Wed, 13 Oct 2021 23:17:07 +0800 Subject: [PATCH 6/9] Improve UI --- .../java/safeforhall/model/person/Email.java | 1 + .../safeforhall/model/person/Faculty.java | 9 ++--- .../safeforhall/model/person/LastDate.java | 6 +++- .../java/safeforhall/model/person/Name.java | 2 ++ .../java/safeforhall/model/person/Phone.java | 3 ++ .../java/safeforhall/model/person/Room.java | 2 ++ .../safeforhall/model/person/VaccStatus.java | 2 ++ src/main/java/safeforhall/ui/PersonCard.java | 34 ++++++++++++++----- src/main/resources/view/PersonListCard.fxml | 4 +-- 9 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/main/java/safeforhall/model/person/Email.java b/src/main/java/safeforhall/model/person/Email.java index 844f1a0cc38..e70dca63e8f 100644 --- a/src/main/java/safeforhall/model/person/Email.java +++ b/src/main/java/safeforhall/model/person/Email.java @@ -9,6 +9,7 @@ */ public class Email { + public static final String DESC = "Email: "; private static final String SPECIAL_CHARACTERS = "+_.-"; public static final String MESSAGE_CONSTRAINTS = "Emails should be of the format local-part@domain " + "and adhere to the following constraints:\n" diff --git a/src/main/java/safeforhall/model/person/Faculty.java b/src/main/java/safeforhall/model/person/Faculty.java index 1919fe093e5..2e8d762bc98 100644 --- a/src/main/java/safeforhall/model/person/Faculty.java +++ b/src/main/java/safeforhall/model/person/Faculty.java @@ -9,15 +9,16 @@ */ public class Faculty { - public static final String MESSAGE_CONSTRAINTS = "Faculty is a single word made up of alphabets " + - "and it should not be blank"; + public static final String MESSAGE_CONSTRAINTS = "Faculty is a single word made up of alphabets " + + "and it should not be blank"; /* - * The first character of the faculty must not be a whitespace, - * otherwise " " (a blank string) becomes a valid input. + * faculty must consist of 2 or more alphabets. */ public static final String VALIDATION_REGEX = "[A-Za-z]{2,}$"; + public static final String DESC = "Faculty: "; + public final String faculty; /** diff --git a/src/main/java/safeforhall/model/person/LastDate.java b/src/main/java/safeforhall/model/person/LastDate.java index 30bc521d299..ac2594f8c2c 100644 --- a/src/main/java/safeforhall/model/person/LastDate.java +++ b/src/main/java/safeforhall/model/person/LastDate.java @@ -9,6 +9,8 @@ public class LastDate { public static final String MESSAGE_CONSTRAINTS = "Date inputted has to be in dd-mm-yyyy format"; public static final String DEFAULT_DATE = ""; + public static final String FET_DESC = "Last FET: "; + public static final String COLLECTION_DESC = "Last Collection: "; private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); @@ -56,7 +58,9 @@ public LocalDate toLocalDate() { * Adds the period of validity to the given {@code LastDate} to get the next deadline. */ public LocalDate getDeadline() { - return LocalDate.parse(date, dateFormatter).plusWeeks(LASTDATE_DEADLINE); + return date.equals("") + ? LocalDate.now() + : LocalDate.parse(date, dateFormatter).plusWeeks(LASTDATE_DEADLINE); } @Override diff --git a/src/main/java/safeforhall/model/person/Name.java b/src/main/java/safeforhall/model/person/Name.java index 5ead9eb3f27..8976dacdcfa 100644 --- a/src/main/java/safeforhall/model/person/Name.java +++ b/src/main/java/safeforhall/model/person/Name.java @@ -18,6 +18,8 @@ public class Name { */ public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + public static final String DESC = "Name: "; + public final String fullName; /** diff --git a/src/main/java/safeforhall/model/person/Phone.java b/src/main/java/safeforhall/model/person/Phone.java index 98225e1507e..8cdb8de430c 100644 --- a/src/main/java/safeforhall/model/person/Phone.java +++ b/src/main/java/safeforhall/model/person/Phone.java @@ -13,6 +13,9 @@ public class Phone { public static final String MESSAGE_CONSTRAINTS = "Phone numbers should only contain numbers, and it should be at least 3 digits long"; public static final String VALIDATION_REGEX = "\\d{3,}"; + + public static final String DESC = "Phone: "; + public final String value; /** diff --git a/src/main/java/safeforhall/model/person/Room.java b/src/main/java/safeforhall/model/person/Room.java index 6a9562f4793..388a8e390b4 100644 --- a/src/main/java/safeforhall/model/person/Room.java +++ b/src/main/java/safeforhall/model/person/Room.java @@ -25,6 +25,8 @@ public class Room { */ public static final String VALIDATION_REGEX = "^[a-eA-E][1-4][0-2][0-9]$"; + public static final String DESC = "Room: "; + public final String room; /** diff --git a/src/main/java/safeforhall/model/person/VaccStatus.java b/src/main/java/safeforhall/model/person/VaccStatus.java index 54349ed52d0..d6bdc4f9d15 100644 --- a/src/main/java/safeforhall/model/person/VaccStatus.java +++ b/src/main/java/safeforhall/model/person/VaccStatus.java @@ -16,6 +16,8 @@ public class VaccStatus { */ public static final String VALIDATION_REGEX = "^([Tt]|[Ff])$"; + public static final String DESC = "Vaccinated: "; + public final String vaccStatus; public final boolean vaccinated; diff --git a/src/main/java/safeforhall/ui/PersonCard.java b/src/main/java/safeforhall/ui/PersonCard.java index ff6eb170c14..0f3d5738777 100644 --- a/src/main/java/safeforhall/ui/PersonCard.java +++ b/src/main/java/safeforhall/ui/PersonCard.java @@ -1,5 +1,7 @@ package safeforhall.ui; +import static safeforhall.model.person.LastDate.DEFAULT_DATE; + import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.image.Image; @@ -8,7 +10,13 @@ import javafx.scene.layout.VBox; import javafx.scene.paint.ImagePattern; import javafx.scene.shape.Rectangle; +import javafx.scene.text.Font; +import safeforhall.model.person.Email; +import safeforhall.model.person.Faculty; +import safeforhall.model.person.LastDate; import safeforhall.model.person.Person; +import safeforhall.model.person.Phone; +import safeforhall.model.person.Room; /** * An UI component that displays information of a {@code Person}. @@ -50,9 +58,7 @@ public class PersonCard extends UiPart { @FXML private VBox statusContainer; @FXML - private Label lastfetdate; - @FXML - private Label lastcollectiondate; + private VBox labelBox; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. @@ -62,12 +68,22 @@ public PersonCard(Person person, int displayedIndex) { this.person = person; id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); - room.setText(person.getRoom().room); - phone.setText(person.getPhone().value); - email.setText(person.getEmail().value); - faculty.setText(person.getFaculty().faculty); - lastfetdate.setText(person.getLastFetDate().date); - lastcollectiondate.setText(person.getLastCollectionDate().date); + room.setText(Room.DESC + person.getRoom().room); + phone.setText(Phone.DESC + person.getPhone().value); + email.setText(Email.DESC + person.getEmail().value); + faculty.setText(Faculty.DESC + person.getFaculty().faculty); + + if (person.getLastFetDate().date != DEFAULT_DATE) { + Label textBox = new Label(LastDate.FET_DESC + person.getLastFetDate().date); + textBox.setFont(new Font(3)); + labelBox.getChildren().add(textBox); + } + + if (person.getLastCollectionDate().date != DEFAULT_DATE) { + Label textBox = new Label(LastDate.COLLECTION_DESC + person.getLastCollectionDate().date); + textBox.setFont(new Font(3)); + labelBox.getChildren().add(textBox); + } if (person.hasMissedDeadline()) { this.getRoot().setStyle("-fx-background-color: #8B0000;"); diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index 65a45801a9f..44b41727042 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -13,7 +13,7 @@ - + @@ -30,8 +30,6 @@ From df55a51b9d6a0b266b0b209eee176d7625fb8dc8 Mon Sep 17 00:00:00 2001 From: jaredlhf Date: Wed, 13 Oct 2021 23:24:54 +0800 Subject: [PATCH 7/9] Add dates to equality check for Person --- src/main/java/safeforhall/model/person/Person.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/safeforhall/model/person/Person.java b/src/main/java/safeforhall/model/person/Person.java index e6638c5382d..507cb0be8b7 100644 --- a/src/main/java/safeforhall/model/person/Person.java +++ b/src/main/java/safeforhall/model/person/Person.java @@ -105,7 +105,9 @@ public boolean equals(Object other) { && otherPerson.getPhone().equals(getPhone()) && otherPerson.getEmail().equals(getEmail()) && otherPerson.getVaccStatus().equals(getVaccStatus()) - && otherPerson.getFaculty().equals(getFaculty()); + && otherPerson.getFaculty().equals(getFaculty()) + && otherPerson.getLastFetDate().equals(getLastFetDate()) + && otherPerson.getLastCollectionDate().equals(getLastCollectionDate()); } @Override From 219c9baf828e823b7456dddda850a08e04575a28 Mon Sep 17 00:00:00 2001 From: jaredlhf Date: Wed, 13 Oct 2021 23:44:16 +0800 Subject: [PATCH 8/9] fix missing dates for PersonUtil --- src/main/java/safeforhall/model/person/Person.java | 6 +++--- src/test/java/safeforhall/testutil/PersonUtil.java | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/safeforhall/model/person/Person.java b/src/main/java/safeforhall/model/person/Person.java index 507cb0be8b7..b16311337d9 100644 --- a/src/main/java/safeforhall/model/person/Person.java +++ b/src/main/java/safeforhall/model/person/Person.java @@ -105,9 +105,9 @@ public boolean equals(Object other) { && otherPerson.getPhone().equals(getPhone()) && otherPerson.getEmail().equals(getEmail()) && otherPerson.getVaccStatus().equals(getVaccStatus()) - && otherPerson.getFaculty().equals(getFaculty()) - && otherPerson.getLastFetDate().equals(getLastFetDate()) - && otherPerson.getLastCollectionDate().equals(getLastCollectionDate()); + && otherPerson.getFaculty().equals(getFaculty()); + //&& otherPerson.getLastFetDate().equals(getLastFetDate()) + //&& otherPerson.getLastCollectionDate().equals(getLastCollectionDate()); } @Override diff --git a/src/test/java/safeforhall/testutil/PersonUtil.java b/src/test/java/safeforhall/testutil/PersonUtil.java index 674dd17a7f1..02888f1404b 100644 --- a/src/test/java/safeforhall/testutil/PersonUtil.java +++ b/src/test/java/safeforhall/testutil/PersonUtil.java @@ -1,7 +1,9 @@ package safeforhall.testutil; +import static safeforhall.logic.parser.CliSyntax.PREFIX_COLLECTIONDATE; import static safeforhall.logic.parser.CliSyntax.PREFIX_EMAIL; import static safeforhall.logic.parser.CliSyntax.PREFIX_FACULTY; +import static safeforhall.logic.parser.CliSyntax.PREFIX_FETDATE; import static safeforhall.logic.parser.CliSyntax.PREFIX_NAME; import static safeforhall.logic.parser.CliSyntax.PREFIX_PHONE; import static safeforhall.logic.parser.CliSyntax.PREFIX_ROOM; @@ -34,6 +36,8 @@ public static String getPersonDetails(Person person) { sb.append(PREFIX_ROOM + person.getRoom().room + " "); sb.append(PREFIX_FACULTY + person.getFaculty().faculty + " "); sb.append(PREFIX_VACCSTATUS + person.getVaccStatus().vaccStatus + " "); + sb.append(PREFIX_FETDATE + person.getLastFetDate().date + " "); + sb.append(PREFIX_COLLECTIONDATE + person.getLastCollectionDate().date + " "); return sb.toString(); } From 7cb1e48df84a5e20efcf6a18a0fbcc94b335c973 Mon Sep 17 00:00:00 2001 From: VimuthM Date: Thu, 14 Oct 2021 01:00:48 +0800 Subject: [PATCH 9/9] Fix date equality checks; Fix ui --- .../safeforhall/model/person/LastDate.java | 2 +- .../java/safeforhall/model/person/Person.java | 6 ++--- src/main/java/safeforhall/ui/PersonCard.java | 11 ++++---- src/main/resources/view/PersonListCard.fxml | 10 ++++--- .../logic/parser/AddCommandParserTest.java | 8 ++++-- .../safeforhall/testutil/PersonBuilder.java | 4 +-- .../safeforhall/testutil/TypicalPersons.java | 26 +++++++++++++++++++ 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/src/main/java/safeforhall/model/person/LastDate.java b/src/main/java/safeforhall/model/person/LastDate.java index ac2594f8c2c..5b5ea3d1cb9 100644 --- a/src/main/java/safeforhall/model/person/LastDate.java +++ b/src/main/java/safeforhall/model/person/LastDate.java @@ -32,7 +32,7 @@ public LastDate(String date) { * Returns true if a given string is a valid date. */ public static boolean isValidDate(String date) { - if (date == DEFAULT_DATE) { + if (date.equals(DEFAULT_DATE)) { return true; } try { diff --git a/src/main/java/safeforhall/model/person/Person.java b/src/main/java/safeforhall/model/person/Person.java index b16311337d9..507cb0be8b7 100644 --- a/src/main/java/safeforhall/model/person/Person.java +++ b/src/main/java/safeforhall/model/person/Person.java @@ -105,9 +105,9 @@ public boolean equals(Object other) { && otherPerson.getPhone().equals(getPhone()) && otherPerson.getEmail().equals(getEmail()) && otherPerson.getVaccStatus().equals(getVaccStatus()) - && otherPerson.getFaculty().equals(getFaculty()); - //&& otherPerson.getLastFetDate().equals(getLastFetDate()) - //&& otherPerson.getLastCollectionDate().equals(getLastCollectionDate()); + && otherPerson.getFaculty().equals(getFaculty()) + && otherPerson.getLastFetDate().equals(getLastFetDate()) + && otherPerson.getLastCollectionDate().equals(getLastCollectionDate()); } @Override diff --git a/src/main/java/safeforhall/ui/PersonCard.java b/src/main/java/safeforhall/ui/PersonCard.java index 0f3d5738777..8bfd9cf0f60 100644 --- a/src/main/java/safeforhall/ui/PersonCard.java +++ b/src/main/java/safeforhall/ui/PersonCard.java @@ -10,7 +10,6 @@ import javafx.scene.layout.VBox; import javafx.scene.paint.ImagePattern; import javafx.scene.shape.Rectangle; -import javafx.scene.text.Font; import safeforhall.model.person.Email; import safeforhall.model.person.Faculty; import safeforhall.model.person.LastDate; @@ -59,6 +58,8 @@ public class PersonCard extends UiPart { private VBox statusContainer; @FXML private VBox labelBox; + @FXML + private VBox labelBoxInterior; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. @@ -75,14 +76,14 @@ public PersonCard(Person person, int displayedIndex) { if (person.getLastFetDate().date != DEFAULT_DATE) { Label textBox = new Label(LastDate.FET_DESC + person.getLastFetDate().date); - textBox.setFont(new Font(3)); - labelBox.getChildren().add(textBox); + textBox.getStyleClass().add("cell_small_label"); + labelBoxInterior.getChildren().add(textBox); } if (person.getLastCollectionDate().date != DEFAULT_DATE) { Label textBox = new Label(LastDate.COLLECTION_DESC + person.getLastCollectionDate().date); - textBox.setFont(new Font(3)); - labelBox.getChildren().add(textBox); + textBox.getStyleClass().add("cell_small_label"); + labelBoxInterior.getChildren().add(textBox); } if (person.hasMissedDeadline()) { diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index 44b41727042..b1818d82545 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -26,10 +26,12 @@ - diff --git a/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java b/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java index c2d4736c96c..d45d8954d5c 100644 --- a/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java +++ b/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java @@ -34,7 +34,9 @@ import static safeforhall.logic.commands.CommandTestUtil.VALID_VACCSTATUS_BOB; import static safeforhall.logic.parser.CommandParserTestUtil.assertParseFailure; import static safeforhall.logic.parser.CommandParserTestUtil.assertParseSuccess; -import static safeforhall.testutil.TypicalPersons.AMY; +import static safeforhall.testutil.TypicalPersons.AMY_NO_COLLECTION; +import static safeforhall.testutil.TypicalPersons.AMY_NO_FET; +import static safeforhall.testutil.TypicalPersons.AMY_NO_FET_COLLECTION; import static safeforhall.testutil.TypicalPersons.BOB; import org.junit.jupiter.api.Test; @@ -106,17 +108,19 @@ public void parse_allFieldsPresent_success() { @Test public void parse_optionalFieldsMissing_success() { - Person expectedPerson = new PersonBuilder(AMY).build(); + Person expectedPerson = new PersonBuilder(AMY_NO_FET_COLLECTION).build(); // missing lastFetDate and lastCollectionDate assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ROOM_DESC_AMY + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY, new AddCommand(expectedPerson)); // missing lastFetDate + expectedPerson = new PersonBuilder(AMY_NO_FET).build(); assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ROOM_DESC_AMY + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + COLLECTION_DESC_AMY, new AddCommand(expectedPerson)); // missing lastCollectionDate + expectedPerson = new PersonBuilder(AMY_NO_COLLECTION).build(); assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ROOM_DESC_AMY + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + FET_DESC_AMY, new AddCommand(expectedPerson)); } diff --git a/src/test/java/safeforhall/testutil/PersonBuilder.java b/src/test/java/safeforhall/testutil/PersonBuilder.java index 9c2a4300bf1..951d987ba6e 100644 --- a/src/test/java/safeforhall/testutil/PersonBuilder.java +++ b/src/test/java/safeforhall/testutil/PersonBuilder.java @@ -20,8 +20,8 @@ public class PersonBuilder { public static final String DEFAULT_EMAIL = "amy@gmail.com"; public static final String DEFAULT_VACCSTATUS = "T"; public static final String DEFAULT_FACULTY = "SoC"; - public static final String DEFAULT_FETDATE = "10-09-2021"; - public static final String DEFAULT_COLLECTDATE = "10-09-2021"; + public static final String DEFAULT_FETDATE = ""; + public static final String DEFAULT_COLLECTDATE = ""; private Name name; private Room room; diff --git a/src/test/java/safeforhall/testutil/TypicalPersons.java b/src/test/java/safeforhall/testutil/TypicalPersons.java index 1a49d715d5a..56e3992d452 100644 --- a/src/test/java/safeforhall/testutil/TypicalPersons.java +++ b/src/test/java/safeforhall/testutil/TypicalPersons.java @@ -123,6 +123,32 @@ public class TypicalPersons { .withFet(VALID_FETDATE_AMY) .withCollection(VALID_COLLECTIONDATE_AMY) .build(); + // Person AMY without FET or COLLECTION + public static final Person AMY_NO_FET_COLLECTION = new PersonBuilder().withName(VALID_NAME_AMY) + .withPhone(VALID_PHONE_AMY) + .withEmail(VALID_EMAIL_AMY) + .withRoom(VALID_ROOM_AMY) + .withFaculty(VALID_FACULTY_AMY) + .withVaccStatus(VALID_VACCSTATUS_AMY) + .build(); + // Person AMY without FET + public static final Person AMY_NO_FET = new PersonBuilder().withName(VALID_NAME_AMY) + .withPhone(VALID_PHONE_AMY) + .withEmail(VALID_EMAIL_AMY) + .withRoom(VALID_ROOM_AMY) + .withFaculty(VALID_FACULTY_AMY) + .withVaccStatus(VALID_VACCSTATUS_AMY) + .withCollection(VALID_COLLECTIONDATE_AMY) + .build(); + // Person AMY without COLLECTION + public static final Person AMY_NO_COLLECTION = new PersonBuilder().withName(VALID_NAME_AMY) + .withPhone(VALID_PHONE_AMY) + .withEmail(VALID_EMAIL_AMY) + .withRoom(VALID_ROOM_AMY) + .withFaculty(VALID_FACULTY_AMY) + .withVaccStatus(VALID_VACCSTATUS_AMY) + .withFet(VALID_FETDATE_AMY) + .build(); public static final Person BOB = new PersonBuilder().withName(VALID_NAME_BOB) .withPhone(VALID_PHONE_BOB) .withEmail(VALID_EMAIL_BOB)