diff --git a/src/main/java/seedu/address/logic/commands/AddEventCommand.java b/src/main/java/seedu/address/logic/commands/AddEventCommand.java index a92195312cd..db6e6a8700c 100644 --- a/src/main/java/seedu/address/logic/commands/AddEventCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddEventCommand.java @@ -36,7 +36,7 @@ public class AddEventCommand extends Command { + "h/2020-03-02 1400 1600 " + "r/y \n" + "Note: " - + "If you are adding a dated event, then index should be the index of " + + "Index should be the index of " + "the friend you are adding the dated event to or 'user' " + "if you would like to add the event to yourself \n"; @@ -111,4 +111,26 @@ public CommandResult execute(Model model) throws CommandException { } } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (!(o instanceof AddEventCommand)) { + return false; + } + + AddEventCommand other = (AddEventCommand) o; + if (index == null && other.index != null) { + return false; + } else if (index != null && other.index == null) { + return false; + } else { + return eventName.equals(other.eventName) + && schedule.equals(other.schedule) + && reminder.equals(other.reminder); + } + } + } diff --git a/src/main/java/seedu/address/logic/commands/AddScheduleCommand.java b/src/main/java/seedu/address/logic/commands/AddScheduleCommand.java index b255b854193..b0f112ef471 100644 --- a/src/main/java/seedu/address/logic/commands/AddScheduleCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddScheduleCommand.java @@ -27,13 +27,13 @@ public class AddScheduleCommand extends Command { + "Example: " + COMMAND_WORD + " 1" + " type/cca" - + " en/CS2103T Lecture\n" + + " en/Basketball\n" + " h/Monday 1400 1600\n" - + "NOTE: If you want to add an event to yourself, use index user\n" + + "NOTE: If you want to add a cca/module to yourself, use index user\n" + "Example: " + COMMAND_WORD + " user" + " type/cca" - + " en/CS2103T Lecture" + + " en/Basketball" + " h/Monday 1400 1600"; public static final String MESSAGE_SUCCESS = "New event added: "; @@ -45,10 +45,10 @@ public class AddScheduleCommand extends Command { /** * Constructs an AddScheduleCommand object with the specified event name, index, schedule and event type. - * @param eventName - * @param eventType - * @param index - * @param schedule + * @param eventName The name of the event. + * @param eventType The type of the event. + * @param index The index of the friend to add the event to. + * @param schedule The schedule of the event. */ public AddScheduleCommand(String eventName, String eventType, Index index, String schedule) { this.eventName = eventName; @@ -59,9 +59,9 @@ public AddScheduleCommand(String eventName, String eventType, Index index, Strin /** * Constructs an AddScheduleCommand object with the specified event name, schedule and event type. - * @param eventName - * @param eventType - * @param schedule + * @param eventName The name of the event. + * @param eventType The type of the event. + * @param schedule The schedule of the event. */ public AddScheduleCommand(String eventName, String eventType, String schedule) { this(eventName, eventType, null, schedule); @@ -108,8 +108,8 @@ public CommandResult execute(Model model) throws CommandException { + friend.getName(), false, false, true, false); case "module": // If the event type is module, add the event to the friend's module schedule - Schedule friendScedule = friend.getSchedule(); - friendScedule.addModule(eventName + " " + schedule); + friendSchedule = friend.getSchedule(); + friendSchedule.addModule(eventName + " " + schedule); return new CommandResult(MESSAGE_SUCCESS + "\nModule:\n" + eventName @@ -126,4 +126,26 @@ public CommandResult execute(Model model) throws CommandException { throw new CommandException(e.getMessage()); } } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (!(o instanceof AddScheduleCommand)) { + return false; + } + + AddScheduleCommand other = (AddScheduleCommand) o; + if (index == null && other.index != null) { + return false; + } else if (index != null && other.index == null) { + return false; + } else { + return eventName.equals(other.eventName) + && eventType.equals(other.eventType) + && schedule.equals(other.schedule); + } + } } diff --git a/src/main/java/seedu/address/logic/commands/CommonFreetimeCommand.java b/src/main/java/seedu/address/logic/commands/CommonFreetimeCommand.java index bad9c784354..b095d5ed9c2 100644 --- a/src/main/java/seedu/address/logic/commands/CommonFreetimeCommand.java +++ b/src/main/java/seedu/address/logic/commands/CommonFreetimeCommand.java @@ -9,7 +9,6 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.timetable.FreeTime; import seedu.address.model.person.timetable.Schedule; @@ -161,26 +160,6 @@ public StringBuilder createCommonFreeTimeMessage(ArrayList overlappingCo } } - /** - * Returns a List of common free times with specified contact. - * - * @param model {@code Model} which the command should operate on. - * @param contactName Name of contact to find common free time with. - * @return List of common free times with specified contact. - * @throws CommandException if an error occurs during command execution. - */ - public List getCommonFreeTimeWith(Model model, Name contactName) throws CommandException { - Person friend = model.getPersonWithName(contactName); - Schedule friendSchedule = friend.getSchedule(); - Schedule userSchedule = model.getUser().getSchedule(); - List commonFreeTime = userSchedule.getThisWeeksFreeTimesWith(friendSchedule); - if (commonFreeTime.isEmpty()) { - throw new CommandException(createNoOverlapFriendMessage(friend)); - } else { - return commonFreeTime; - } - } - @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/commands/RemoveEventCommand.java b/src/main/java/seedu/address/logic/commands/RemoveEventCommand.java index 7ee7d35dd9a..fe7f16f4551 100644 --- a/src/main/java/seedu/address/logic/commands/RemoveEventCommand.java +++ b/src/main/java/seedu/address/logic/commands/RemoveEventCommand.java @@ -63,29 +63,20 @@ public CommandResult execute(Model model) throws CommandException { Person friend; Schedule userSchedule = model.getUser().getSchedule(); - try { - if (index == null) { - userSchedule.deleteDatedEvent(eventName); - return new CommandResult("Dated Event '" - + eventName + if (index == null) { + userSchedule.deleteDatedEvent(eventName); + return new CommandResult("Dated Event '" + eventName + "' deleted from your calendar!", false, false, true, false); - } else { - List lastShownList = model.getFilteredPersonList(); - if (index.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX + "\n" + } else { + List lastShownList = model.getFilteredPersonList(); + if (index.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX + "\n" + "Index can be max " + lastShownList.size() + "!"); - } - friend = model.getFilteredPersonList().get(index.getZeroBased()); - friend.getSchedule().deleteDatedEvent(eventName); - return new CommandResult("Dated Event '" - + eventName - + "' deleted from " - + friend.getName().toString() - + "'s calendar!", false, false, true, false); } - } catch (Exception e) { - throw new CommandException("Event " + eventName + " does not exist!\n" - + "Please check that you have entered the correct event name!\n"); + friend = model.getFilteredPersonList().get(index.getZeroBased()); + friend.getSchedule().deleteDatedEvent(eventName); + return new CommandResult("Dated Event '" + eventName + "' deleted from " + + friend.getName().toString() + "'s calendar!", false, false, true, false); } } @@ -103,4 +94,25 @@ public String listEvents(List events) { } return result; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (!(o instanceof RemoveEventCommand)) { + return false; + } + + RemoveEventCommand other = (RemoveEventCommand) o; + if (index == null && other.index != null) { + return false; + } else if (index != null && other.index == null) { + return false; + } else { + return eventName.equals(other.eventName); + } + } + } diff --git a/src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java b/src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java index f648a715657..6efc6341501 100644 --- a/src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java +++ b/src/main/java/seedu/address/logic/commands/RemoveScheduleCommand.java @@ -29,13 +29,13 @@ public class RemoveScheduleCommand extends Command { + "en/EVENT_NAME\n" + "Example: " + COMMAND_WORD + " 1" - + " type/dated" - + " en/CS2103T Lecture\n" + + " type/cca" + + " en/Basketball\n" + "NOTE: If you want to remove an event from yourself, use index user\n" + "Example: " + COMMAND_WORD + " user" - + " type/dated" - + " en/CS2103T Lecture"; + + " type/cca" + + " en/Basketball"; private final String eventName; private final String eventType; @@ -74,56 +74,45 @@ public CommandResult execute(Model model) throws CommandException { Person friend; Schedule userSchedule = model.getUser().getSchedule(); - try { - if (this.index == null) { - friend = model.getUser(); - } else { - List lastShownList = model.getFilteredPersonList(); - if (index.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX + "\n" + if (this.index == null) { + friend = model.getUser(); + } else { + List lastShownList = model.getFilteredPersonList(); + if (index.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX + "\n" + "Index can be max " + lastShownList.size() + "!"); - } - friend = model.getFilteredPersonList().get(index.getZeroBased()); } - switch (eventType) { - // If the event is a cca event, remove it from the specified contact's calendar. - case "cca": - if (index == null) { - userSchedule.deleteCca(eventName); - return new CommandResult("CCA '" - + eventName + friend = model.getFilteredPersonList().get(index.getZeroBased()); + } + + switch (eventType) { + case "cca": + if (index == null) { + userSchedule.deleteCca(eventName); + return new CommandResult("CCA '" + eventName + "'' deleted from your calendar!", false, false, true, false); - } else { - friend = model.getFilteredPersonList().get(index.getZeroBased()); - friend.getSchedule().deleteCca(eventName); - return new CommandResult("CCA '" - + eventName - + "'' deleted from " + } else { + friend = model.getFilteredPersonList().get(index.getZeroBased()); + friend.getSchedule().deleteCca(eventName); + return new CommandResult("CCA '" + eventName + "'' deleted from " + friend.getName().toString() + "'s calendar!", false, false, true, false); - } - // If the event is a module event, remove it from the specified contact's calendar. - case "module": - if (index == null) { - userSchedule.deleteModule(eventName); - return new CommandResult("Module" + eventName + } + case "module": + if (index == null) { + userSchedule.deleteModule(eventName); + return new CommandResult("Module '" + eventName + "'' deleted from your calendar!", false, false, true, false); - } else { - friend = model.getFilteredPersonList().get(index.getZeroBased()); - friend.getSchedule().deleteModule(eventName); - return new CommandResult("Module '" - + eventName - + "'' deleted from " + } else { + friend = model.getFilteredPersonList().get(index.getZeroBased()); + friend.getSchedule().deleteModule(eventName); + return new CommandResult("Module '" + eventName + "'' deleted from " + friend.getName().toString() + "'s calendar!", false, false, true, false); - } - // If the event type is invalid, throw an exception. - default: - throw new CommandException("Invalid event type!\n" - + "Event type must either be 'cca' or 'module'!\n"); } - } catch (Exception e) { - throw new CommandException(e.getMessage()); + default: + throw new CommandException("Invalid event type!\n" + + "Event type must either be 'cca' or 'module'!\n"); } } @@ -139,4 +128,26 @@ public String listEvents(List events) { } return result; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (!(o instanceof RemoveScheduleCommand)) { + return false; + } + + RemoveScheduleCommand other = (RemoveScheduleCommand) o; + if (index == null && other.index != null) { + return false; + } else if (index != null && other.index == null) { + return false; + } else { + return eventName.equals(other.eventName) + && eventType.equals(other.eventType); + } + } + } diff --git a/src/main/java/seedu/address/logic/parser/AddEventCommandParser.java b/src/main/java/seedu/address/logic/parser/AddEventCommandParser.java index e68e893b38f..2b0734e5469 100644 --- a/src/main/java/seedu/address/logic/parser/AddEventCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddEventCommandParser.java @@ -43,20 +43,17 @@ public AddEventCommand parse(String args) throws ParseException { String schedule = argMultimap.getValue(PREFIX_SCHEDULE).get(); String reminder = argMultimap.getValue(PREFIX_REMINDER).get(); - try { - indexString = argMultimap.getPreamble().toLowerCase(); - if (indexString.equals("user")) { - return new AddEventCommand(eventName, schedule, reminder); - } else if (Integer.parseInt(indexString) > 0) { - return new AddEventCommand(eventName, ParserUtil.parseIndex(indexString), - schedule, reminder); - } else { + indexString = argMultimap.getPreamble().toLowerCase(); + if (indexString.equals("user")) { + return new AddEventCommand(eventName, schedule, reminder); + } else { + try { + Integer.parseInt(indexString); + return new AddEventCommand(eventName, ParserUtil.parseIndex(indexString), schedule, reminder); + } catch (NumberFormatException e) { throw new ParseException(String.format("Invalid index!" + "\n" + "Index can only be 'user' or a positive integer! \n")); } - } catch (Exception pe) { - throw new ParseException(String.format("Please input an index!" + "\n" - + "Message Usage:\n" + AddEventCommand.MESSAGE_USAGE)); } } diff --git a/src/main/java/seedu/address/logic/parser/AddScheduleCommandParser.java b/src/main/java/seedu/address/logic/parser/AddScheduleCommandParser.java index 6d11820016e..ce483ab2545 100644 --- a/src/main/java/seedu/address/logic/parser/AddScheduleCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddScheduleCommandParser.java @@ -3,7 +3,6 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_EVENTNAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_EVENTTYPE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_REMINDER; import static seedu.address.logic.parser.CliSyntax.PREFIX_SCHEDULE; import java.util.stream.Stream; @@ -33,8 +32,7 @@ public AddScheduleCommand parse(String args) throws ParseException { + AddScheduleCommand.MESSAGE_USAGE)); } - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_EVENTNAME, PREFIX_SCHEDULE, - PREFIX_REMINDER); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_EVENTNAME, PREFIX_SCHEDULE, PREFIX_EVENTTYPE); String indexString; @@ -42,21 +40,18 @@ public AddScheduleCommand parse(String args) throws ParseException { String eventType = argMultimap.getValue(PREFIX_EVENTTYPE).get().toLowerCase(); String schedule = argMultimap.getValue(PREFIX_SCHEDULE).get(); - try { - indexString = argMultimap.getPreamble().toLowerCase(); - } catch (Exception pe) { - throw new ParseException(String.format("Please input an index!" + "\n" - + "Message Usage:\n" + AddScheduleCommand.MESSAGE_USAGE)); - } + indexString = argMultimap.getPreamble().toLowerCase(); if (indexString.equals("user")) { return new AddScheduleCommand(eventName, eventType, schedule); - } else if (Integer.parseInt(indexString) > 0) { - return new AddScheduleCommand(eventName, eventType, - ParserUtil.parseIndex(indexString), schedule); } else { - throw new ParseException("Invalid index!\n" - + "Index can only be 'user' or a 'positive integer!' \n"); + try { + Integer.parseInt(indexString); + return new AddScheduleCommand(eventName, eventType, ParserUtil.parseIndex(indexString), schedule); + } catch (NumberFormatException e) { + throw new ParseException(String.format("Invalid index!" + "\n" + + "Index can only be 'user' or a positive integer! \n")); + } } } diff --git a/src/main/java/seedu/address/logic/parser/RemoveEventCommandParser.java b/src/main/java/seedu/address/logic/parser/RemoveEventCommandParser.java index 91356bef542..3597136d559 100644 --- a/src/main/java/seedu/address/logic/parser/RemoveEventCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/RemoveEventCommandParser.java @@ -31,25 +31,20 @@ public RemoveEventCommand parse(String args) throws ParseException { + RemoveEventCommand.MESSAGE_USAGE)); } - if (!arePrefixesUnique(argMultimap, PREFIX_EVENTNAME)) { - throw new ParseException(String.format("You can only have 1 of each prefix!\n" - + RemoveEventCommand.MESSAGE_USAGE)); - } - - try { - String indexString = argMultimap.getPreamble().toLowerCase(); - String eventName = argMultimap.getValue(PREFIX_EVENTNAME).get().toLowerCase(); - if (indexString.equals("user")) { - return new RemoveEventCommand(eventName, null); - } else if (Integer.parseInt(indexString) > 0) { + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_EVENTNAME); + + String indexString = argMultimap.getPreamble().toLowerCase(); + String eventName = argMultimap.getValue(PREFIX_EVENTNAME).get().toLowerCase(); + if (indexString.equals("user")) { + return new RemoveEventCommand(eventName, null); + } else { + try { + Integer.parseInt(indexString); return new RemoveEventCommand(eventName, ParserUtil.parseIndex(indexString)); - } else { - throw new ParseException("Invalid index!\n" - + "Index must either be 'user' or a positive integer!\n"); + } catch (NumberFormatException e) { + throw new ParseException(String.format("Invalid index!" + "\n" + + "Index can only be 'user' or a positive integer! \n")); } - } catch (Exception pe) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, RemoveEventCommand.MESSAGE_USAGE), pe); } } @@ -61,12 +56,4 @@ private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Pre return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); } - /** - * Returns true if there are duplicate prefixes - * @param argumentMultimap - * @param prefixes - */ - private static boolean arePrefixesUnique(ArgumentMultimap argumentMultimap, Prefix... prefixes) { - return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getAllValues(prefix).size() == 1); - } } diff --git a/src/main/java/seedu/address/logic/parser/RemoveScheduleCommandParser.java b/src/main/java/seedu/address/logic/parser/RemoveScheduleCommandParser.java index 148ad9ca089..a51e12eb26a 100644 --- a/src/main/java/seedu/address/logic/parser/RemoveScheduleCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/RemoveScheduleCommandParser.java @@ -32,27 +32,21 @@ public RemoveScheduleCommand parse(String args) throws ParseException { + RemoveScheduleCommand.MESSAGE_USAGE)); } - if (!arePrefixesUnique(argMultimap, PREFIX_EVENTNAME, PREFIX_EVENTTYPE)) { - throw new ParseException(String.format("You can only have 1 of each prefix!\n" - + RemoveScheduleCommand.MESSAGE_USAGE)); - } - - try { - String indexString = argMultimap.getPreamble().toLowerCase(); - String eventName = argMultimap.getValue(PREFIX_EVENTNAME).get().toLowerCase(); - String eventType = argMultimap.getValue(PREFIX_EVENTTYPE).get().toLowerCase(); - if (indexString.equals("user")) { - return new RemoveScheduleCommand(eventName, eventType, null); - } else if (Integer.parseInt(indexString) > 0) { - return new RemoveScheduleCommand(eventName, eventType, - ParserUtil.parseIndex(indexString)); - } else { - throw new ParseException("Invalid index!\n" - + "Index must either be 'user' or a positive integer!\n"); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_EVENTNAME, PREFIX_EVENTTYPE); + + String indexString = argMultimap.getPreamble().toLowerCase(); + String eventName = argMultimap.getValue(PREFIX_EVENTNAME).get().toLowerCase(); + String eventType = argMultimap.getValue(PREFIX_EVENTTYPE).get().toLowerCase(); + if (indexString.equals("user")) { + return new RemoveScheduleCommand(eventName, eventType, null); + } else { + try { + Integer.parseInt(indexString); + return new RemoveScheduleCommand(eventName, eventType, ParserUtil.parseIndex(indexString)); + } catch (NumberFormatException e) { + throw new ParseException(String.format("Invalid index!" + "\n" + + "Index can only be 'user' or a positive integer! \n")); } - } catch (Exception pe) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, RemoveScheduleCommand.MESSAGE_USAGE), pe); } } @@ -64,12 +58,4 @@ private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Pre return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); } - /** - * Returns true if there are duplicate prefixes - * @param argumentMultimap - * @param prefixes - */ - private static boolean arePrefixesUnique(ArgumentMultimap argumentMultimap, Prefix... prefixes) { - return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getAllValues(prefix).size() == 1); - } } diff --git a/src/main/java/seedu/address/model/person/Birthday.java b/src/main/java/seedu/address/model/person/Birthday.java index a2a58e3a5e6..26d376b0a2a 100644 --- a/src/main/java/seedu/address/model/person/Birthday.java +++ b/src/main/java/seedu/address/model/person/Birthday.java @@ -11,7 +11,7 @@ */ public class Birthday { public static final String MESSAGE_CONSTRAINTS = - "Birthday should be in the format of YYYY-MM-DD OR YYYY-M-D and should be a valid date."; + "Birthday should be in the format of YYYY-MM-DD and should be a valid date."; public static final String VALIDATION_REGEX = "^\\d{4}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$"; public final String date; diff --git a/src/main/java/seedu/address/model/person/timetable/Schedule.java b/src/main/java/seedu/address/model/person/timetable/Schedule.java index 02d8c8a2ba0..1e12bc36912 100644 --- a/src/main/java/seedu/address/model/person/timetable/Schedule.java +++ b/src/main/java/seedu/address/model/person/timetable/Schedule.java @@ -36,7 +36,8 @@ public Schedule(List modulesList, List ccasList, */ public List getThisWeeksSchedule() { LocalDate today = LocalDate.now(); - LocalDate startOfThisWeek = today.minusDays(today.getDayOfWeek().getValue() - DayOfWeek.MONDAY.getValue()); + LocalDate startOfThisWeek = today + .minusDays(today.getDayOfWeek().getValue() - DayOfWeek.MONDAY.getValue()); LocalDate endOfThisWeek = startOfThisWeek.plusDays(6); List thisWeeksSchedule = new ArrayList<>(); @@ -401,7 +402,8 @@ public void deleteDatedEvent(String eventName) throws CommandException { } if (!isFound) { - throw new CommandException("Meet-up event " + eventName + " does not exist!"); + throw new CommandException("Event " + eventName + " does not exist!\n" + + "Please check that you have entered the correct event name!\n"); } } diff --git a/src/test/data/JsonSerializableAddressBookTest/smallTypicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/smallTypicalPersonsAddressBook.json new file mode 100644 index 00000000000..c1527b24707 --- /dev/null +++ b/src/test/data/JsonSerializableAddressBookTest/smallTypicalPersonsAddressBook.json @@ -0,0 +1,27 @@ +{ + "_comment": "AddressBook save file which contains the same Person values as in TypicalPersons#getTypicalAddressBook()", + "persons" : [ { + "name" : "George Best", + "phone" : "94824424", + "email" : "anna@example.com", + "address" : "4th street", + "birthday": "2000-01-01", + "schedule" : { + "datedEvents" : [ { + "name" : "CS2103 Meeting", + "reminder" : true, + "timeBlockString" : "Tuesday 1030 1130", + "localDateString" : "2023-10-10" + } ], + "modules" : [ { + "name" : "CS2103", + "timeBlockString" : "Wednesday 1200 1300" + } ], + "ccas" : [ { + "name" : "Basketball", + "timeBlockString" : "Monday 1800 2000" + } ] + }, + "tags" : [ ] + } ] +} diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json index eeebc49b0f3..f5203b89037 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json @@ -61,7 +61,7 @@ "tags" : [ "friends" ] }, { "name" : "Elle Meyer", - "phone" : "94182224", + "phone" : "94822243", "email" : "werner@example.com", "address" : "michegan ave", "birthday": "2000-01-01", "schedule" : { @@ -83,7 +83,7 @@ "tags" : [ ] }, { "name" : "Fiona Kunz", - "phone" : "94182427", + "phone" : "94824272", "email" : "lydia@example.com", "address" : "little tokyo", "birthday": "2000-01-01", @@ -106,7 +106,7 @@ "tags" : [ ] }, { "name" : "George Best", - "phone" : "94821442", + "phone" : "94824424", "email" : "anna@example.com", "address" : "4th street", "birthday": "2000-01-01", diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index f02c16e340b..03a32a0eb9f 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -6,6 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.BENSON; import java.nio.file.Path; import java.util.ArrayList; @@ -56,6 +57,27 @@ public void execute_duplicatePerson_throwsCommandException() { assertThrows(CommandException.class, AddCommand.MESSAGE_DUPLICATE_PERSON, () -> addCommand.execute(modelStub)); } + @Test + public void execute_duplicatePhone_throwsCommandException() { + Person validPerson = new PersonBuilder(BENSON).withPhone("11111111").build(); + AddCommand addCommand = new AddCommand(validPerson); + ModelStubAcceptingPersonAdded modelStub = new ModelStubAcceptingPersonAdded(); + modelStub.addPerson(new PersonBuilder(ALICE).withPhone("11111111").build()); + + assertThrows(CommandException.class, AddCommand.MESSAGE_DUPLICATE_PHONE, () -> addCommand.execute(modelStub)); + } + + @Test + public void execute_duplicateEmail_throwsCommandException() { + Person validPerson = new PersonBuilder(BENSON).withEmail("xyz@example.com").build(); + AddCommand addCommand = new AddCommand(validPerson); + ModelStubAcceptingPersonAdded modelStub = new ModelStubAcceptingPersonAdded(); + modelStub.addPerson(new PersonBuilder(ALICE).withEmail("xyz@example.com").build()); + + assertThrows(CommandException.class, AddCommand.MESSAGE_DUPLICATE_EMAIL, () -> addCommand.execute(modelStub)); + } + + @Test public void equals() { Person alice = new PersonBuilder().withName("Alice").build(); diff --git a/src/test/java/seedu/address/logic/commands/CommonFreetimeCommandTest.java b/src/test/java/seedu/address/logic/commands/CommonFreetimeCommandTest.java index 04467c1cf33..1fe5d333ebd 100644 --- a/src/test/java/seedu/address/logic/commands/CommonFreetimeCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/CommonFreetimeCommandTest.java @@ -4,13 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.testutil.TypicalPersons.ALICE; -import static seedu.address.testutil.TypicalPersons.BENSON; -import static seedu.address.testutil.TypicalPersons.CARL; -import static seedu.address.testutil.TypicalPersons.DANIEL; -import static seedu.address.testutil.TypicalPersons.ELLE; -import static seedu.address.testutil.TypicalPersons.FIONA; -import static seedu.address.testutil.TypicalPersons.GEORGE; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import static seedu.address.testutil.TypicalUsers.JAMES; import static seedu.address.testutil.TypicalUsers.JANE; @@ -43,43 +36,20 @@ public void execute_userNoFreetime_failure() { model.setUser(JAMES); expectedModel.setUser(JAMES); CommonFreetimeCommand commonFreetimeCommand = new CommonFreetimeCommand(); - assertCommandFailure(commonFreetimeCommand, model, CommonFreetimeCommand.MESSAGE_NO_FREE_TIME); - } - - @Test - public void execute_nameNull_success() { - CommonFreetimeCommand commonFreetimeCommand = new CommonFreetimeCommand(); - String expectedMessage = CommonFreetimeCommand.MESSAGE_COMMON_FREETIME_SUCCESS - + ALICE.getName().toString() + " is free at " + "[Monday 1200 1300]" + "\n" - + BENSON.getName().toString() + " is free at " + "[Monday 1200 1300]" + "\n" - + CARL.getName().toString() + " is free at " + "[Monday 1200 1300]" + "\n" - + DANIEL.getName().toString() + " is free at " + "[Monday 1200 1300]" + "\n" - + ELLE.getName().toString() + " is free at " + "[Monday 1200 1300]" + "\n" - + FIONA.getName().toString() + " is free at " + "[Monday 1200 1300]" + "\n" - + GEORGE.getName().toString() + " is free at " + "[Monday 1200 1300]" + "\n"; - assertCommandSuccess(commonFreetimeCommand, model, expectedMessage, expectedModel); + assertCommandFailure(commonFreetimeCommand, model, CommonFreetimeCommand.MESSAGE_NO_CONTACTS); } @Test public void execute_nameFriend_success() { - CommonFreetimeCommand commonFreetimeCommand = new CommonFreetimeCommand(Index.fromOneBased(1)); - String expectedMessage = CommonFreetimeCommand.MESSAGE_COMMON_FREETIME_SUCCESS - + ALICE.getName().toString() + " is free at " + "[Monday 1200 1300]" + "\n"; + CommonFreetimeCommand commonFreetimeCommand = new CommonFreetimeCommand(Index.fromOneBased(2)); + String expectedMessage = "You have common free times with Benson Meier at:" + "\n" + + "[Monday 0000 1730]" + "\n" + "[Monday 2000 2330]" + "\n" + + "[Tuesday 0000 2330]" + "\n" + "[Wednesday 0000 1130]" + "\n" + "[Wednesday 1300 2330]" + "\n" + + "[Thursday 0000 2330]" + "\n" + "[Friday 0000 2330]" + "\n" + "[Saturday 0000 2330]" + "\n" + + "[Sunday 0000 2330]" + "\n"; assertCommandSuccess(commonFreetimeCommand, model, expectedMessage, expectedModel); } - @Test - public void execute_noOverlapContact_failure() { - CommonFreetimeCommand commonFreetimeCommand = new CommonFreetimeCommand(); - assertCommandFailure(commonFreetimeCommand, model, CommonFreetimeCommand.MESSAGE_NO_CONTACTS); - } - - @Test - public void execute_noOverlapFriend_failure() { - CommonFreetimeCommand commonFreetimeCommand = new CommonFreetimeCommand(Index.fromOneBased(1)); - assertCommandFailure(commonFreetimeCommand, model, CommonFreetimeCommand.createNoOverlapFriendMessage(ALICE)); - } - @Test public void equals() { final CommonFreetimeCommand standardCommand = new CommonFreetimeCommand(Index.fromOneBased(1)); diff --git a/src/test/java/seedu/address/logic/commands/RemoveScheduleCommandTest.java b/src/test/java/seedu/address/logic/commands/RemoveScheduleCommandTest.java index 6464a200f33..5c4c30364ac 100644 --- a/src/test/java/seedu/address/logic/commands/RemoveScheduleCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/RemoveScheduleCommandTest.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -101,8 +102,7 @@ public void execute_invalidEventType_failure() { RemoveScheduleCommand removeScheduleCommand = new RemoveScheduleCommand("CS2103", "sleep"); - String expectedMessage = "Invalid event type or name!\n" - + "Event type must either be 'cca' or 'module' and event must be in schedule!\n"; + String expectedMessage = "Invalid event type!\n" + "Event type must either be 'cca' or 'module'!\n"; assertCommandFailure(removeScheduleCommand, model, expectedMessage); } @@ -117,7 +117,7 @@ public void execute_invalidEventName_failure() { String expectedMessage = "Module " + "CS1101" + " does not exist!"; - assertCommandFailure(removeScheduleCommand, model, expectedMessage); + assertThrows(IllegalArgumentException.class, () -> removeScheduleCommand.execute(model)); } @Test diff --git a/src/test/java/seedu/address/logic/parser/AddEventCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddEventCommandParserTest.java index 853cd6e62db..f017a143880 100644 --- a/src/test/java/seedu/address/logic/parser/AddEventCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddEventCommandParserTest.java @@ -20,7 +20,7 @@ public void parse_allFieldsPresent_success() { // dated event in user assertParseSuccess(parser, "user en/CS2103 Meeting h/2023-10-10 1030 1130 r/y", - new AddEventCommand("CS2103 Meeting", "2023-10-10 1030 1130", "dated")); + new AddEventCommand("CS2103 Meeting", "2023-10-10 1030 1130", "y")); // dated event in friend assertParseSuccess(parser, "1 en/CS2103 Meeting h/2023-10-10 1030 1130 r/y", @@ -34,39 +34,29 @@ public void parse_repeatedValue_failure() { String validCommand = "user en/CS2103 Meeting h/2023-10-10 1030 1130 r/y"; // multiple event name - assertParseFailure(parser, validCommand + "en/CS2103 Meeting", + assertParseFailure(parser, validCommand + " en/CS2103 Meeting", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTNAME)); // multiple event schedule - assertParseFailure(parser, validCommand + "h/2023-10-10 1030 1130", + assertParseFailure(parser, validCommand + " h/2023-10-10 1030 1130", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_SCHEDULE)); // multiple event reminder - assertParseFailure(parser, validCommand + "r/y", + assertParseFailure(parser, validCommand + " r/y", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_REMINDER)); // multiple fields repeated - assertParseFailure(parser, validCommand + "en/CS2103 Meeting" + "r/y", + assertParseFailure(parser, validCommand + " en/CS2103 Meeting" + " r/y", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTNAME, PREFIX_REMINDER)); - // invalid value followed by valid value - - // invalid schedule - assertParseFailure(parser, "h/2023-10-10 1030 1145" + validCommand, - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_SCHEDULE)); - - //invalid reminder - assertParseFailure(parser, "r/yes" + validCommand, - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_REMINDER)); - //valid value followed by invalid value // invalid schedule - assertParseFailure(parser, validCommand + "h/2023-10-10 1030 1145", + assertParseFailure(parser, validCommand + " h/2023-10-10 1030 1145", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_SCHEDULE)); //invalid reminder - assertParseFailure(parser, validCommand + "r/yes", + assertParseFailure(parser, validCommand + " r/yes", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_REMINDER)); } @@ -76,7 +66,7 @@ public void parse_fieldMissing_failure() { + AddEventCommand.MESSAGE_USAGE); String expectedMessage2 = String.format("Invalid index!\n" - + "Index can only be 'user' or a 'positive integer!' \n"); + + "Index can only be 'user' or a positive integer! \n"); // missing event name prefix assertParseFailure(parser, "user h/2023-10-10 1030 1130 r/y", @@ -95,7 +85,7 @@ public void parse_fieldMissing_failure() { expectedMessage); // wrong index - assertParseFailure(parser, "wrong type/dated en/CS2103 Meeting h/2023-10-10 1030 1130 r/y", + assertParseFailure(parser, "wrong en/CS2103 Meeting h/2023-10-10 1030 1130 r/y", expectedMessage2); } diff --git a/src/test/java/seedu/address/logic/parser/AddScheduleCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddScheduleCommandParserTest.java index 9ddb7d4ecad..0e79963ade3 100644 --- a/src/test/java/seedu/address/logic/parser/AddScheduleCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddScheduleCommandParserTest.java @@ -10,7 +10,6 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; -import seedu.address.logic.commands.AddEventCommand; import seedu.address.logic.commands.AddScheduleCommand; public class AddScheduleCommandParserTest { @@ -21,20 +20,20 @@ public void parse_allFieldsPresent_success() { // cca in user assertParseSuccess(parser, "user type/cca en/Basketball h/Monday 1030 1130", - new AddScheduleCommand("Basketball", "cca", "Monday 1030 1130")); + new AddScheduleCommand("basketball", "cca", "Monday 1030 1130")); // cca in friend assertParseSuccess(parser, "1 type/cca en/Basketball h/Monday 1030 1130", - new AddScheduleCommand("Basketball", "cca", Index.fromOneBased(1), + new AddScheduleCommand("basketball", "cca", Index.fromOneBased(1), "Monday 1030 1130")); // module in user - assertParseSuccess(parser, "user type/module en/CS2103 h/Monday 1030 1130 r/y", - new AddScheduleCommand("CS2103", "module", "Monday 1030 1130")); + assertParseSuccess(parser, "user type/module en/CS2103 h/Monday 1030 1130", + new AddScheduleCommand("cs2103", "module", "Monday 1030 1130")); // module in friend - assertParseSuccess(parser, "1 type/module en/CS2103 h/Monday 1030 1130 r/y", - new AddScheduleCommand("CS2103", "module", Index.fromOneBased(1), + assertParseSuccess(parser, "1 type/module en/CS2103 h/Monday 1030 1130", + new AddScheduleCommand("cs2103", "module", Index.fromOneBased(1), "Monday 1030 1130")); } @@ -43,36 +42,25 @@ public void parse_repeatedValue_failure() { String validCommand = "user type/cca en/Basketball h/Monday 1030 1130"; // multiple event type - assertParseFailure(parser, validCommand + "type/cca", + assertParseFailure(parser, validCommand + " type/cca", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTTYPE)); // multiple event name - assertParseFailure(parser, validCommand + "en/CS2103", + assertParseFailure(parser, validCommand + " en/CS2103", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTNAME)); // multiple event schedule - assertParseFailure(parser, validCommand + "h/Monday 1030 1130", + assertParseFailure(parser, validCommand + " h/Monday 1030 1130", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_SCHEDULE)); - // invalid value followed by valid value - - // invalid type - assertParseFailure(parser, "typed/cca" + validCommand, - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTTYPE)); - - // invalid schedule - assertParseFailure(parser, "h/Monday 1030 1145" + validCommand, - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_SCHEDULE)); - - //valid value followed by invalid value // invalid type - assertParseFailure(parser, validCommand + "typed/cca", + assertParseFailure(parser, validCommand + " type/cca", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTTYPE)); // invalid schedule - assertParseFailure(parser, validCommand + "h/Monday 1030 1145", + assertParseFailure(parser, validCommand + " h/Monday 1030 1145", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_SCHEDULE)); } @@ -80,10 +68,10 @@ public void parse_repeatedValue_failure() { @Test public void parse_fieldMissing_failure() { String expectedMessage = String.format("Command format is invalid! \n" - + AddEventCommand.MESSAGE_USAGE); + + AddScheduleCommand.MESSAGE_USAGE); String expectedMessage2 = String.format("Invalid index!\n" - + "Index can only be 'user' or a 'positive integer!' \n"); + + "Index can only be 'user' or a positive integer! \n"); // missing schedule name prefix assertParseFailure(parser, "user type/cca en/Basketball", @@ -102,7 +90,7 @@ public void parse_fieldMissing_failure() { expectedMessage); // wrong index - assertParseFailure(parser, "wrong type/dated en/CS2103 Meeting h/2023-10-10 1030 1130 r/y", + assertParseFailure(parser, "wrong type/cca en/CS2103 Meeting h/2023-10-10 1030 1130 r/y", expectedMessage2); } diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 11c8f2cfec8..254e2337832 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -126,7 +126,7 @@ public void parseCommand_addEvent() throws Exception { public void parseCommand_addSchedule() throws Exception { AddScheduleCommand command = (AddScheduleCommand) parser.parseCommand( AddScheduleCommand.COMMAND_WORD + " user type/cca en/Basketball h/Monday 1030 1130"); - assertEquals(new AddScheduleCommand("cca", "Basketball", "Monday 1030 1130"), + assertEquals(new AddScheduleCommand("basketball", "cca", "Monday 1030 1130"), command); } @@ -134,14 +134,14 @@ public void parseCommand_addSchedule() throws Exception { public void parseCommand_removeEvent() throws Exception { RemoveEventCommand command = (RemoveEventCommand) parser.parseCommand( RemoveEventCommand.COMMAND_WORD + " user en/CS2103 Meeting"); - assertEquals(new RemoveEventCommand("CS2103 Meeting", null), command); + assertEquals(new RemoveEventCommand("cs2103 meeting", null), command); } @Test public void parseCommand_removeSchedule() throws Exception { RemoveScheduleCommand command = (RemoveScheduleCommand) parser.parseCommand( RemoveScheduleCommand.COMMAND_WORD + " user type/cca en/Basketball"); - assertEquals(new RemoveScheduleCommand("cca", "Basketball"), command); + assertEquals(new RemoveScheduleCommand("basketball", "cca"), command); } diff --git a/src/test/java/seedu/address/logic/parser/RemoveEventCommandParserTest.java b/src/test/java/seedu/address/logic/parser/RemoveEventCommandParserTest.java index 89fb305c797..e1de51ef867 100644 --- a/src/test/java/seedu/address/logic/parser/RemoveEventCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/RemoveEventCommandParserTest.java @@ -1,7 +1,6 @@ package seedu.address.logic.parser; import static seedu.address.logic.parser.CliSyntax.PREFIX_EVENTNAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_EVENTTYPE; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; @@ -9,7 +8,6 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; -import seedu.address.logic.commands.AddEventCommand; import seedu.address.logic.commands.RemoveEventCommand; public class RemoveEventCommandParserTest { @@ -20,11 +18,11 @@ public void parse_allFieldsPresent_success() { // dated event in user assertParseSuccess(parser, "user en/CS2103 Meeting", - new RemoveEventCommand("CS2103 Meeting", null)); + new RemoveEventCommand("cs2103 meeting", null)); // dated event in friend assertParseSuccess(parser, "1 en/CS2103 Meeting", - new RemoveEventCommand("CS2103 Meeting", Index.fromOneBased(1))); + new RemoveEventCommand("cs2103 meeting", Index.fromOneBased(1))); } @Test @@ -32,37 +30,31 @@ public void parse_repeatedValue_failure() { String validCommand = "user en/CS2103 Meeting"; // multiple event name - assertParseFailure(parser, validCommand + "en/CS2103 Meeting", + assertParseFailure(parser, validCommand + " en/CS2103 Meeting", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTNAME)); // multiple fields repeated - assertParseFailure(parser, validCommand + "en/CS2103 Meeting", - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTTYPE, PREFIX_EVENTNAME)); - - // invalid value followed by valid value - - // invalid name - assertParseFailure(parser, "en/CS2103 Meeting" + validCommand, + assertParseFailure(parser, validCommand + " en/CS2103 Meeting", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTNAME)); //valid value followed by invalid value // invalid name - assertParseFailure(parser, validCommand + "en/CS2103 Meeting", + assertParseFailure(parser, validCommand + " en/CS2103 Meeting", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTNAME)); } @Test public void parse_fieldMissing_failure() { String expectedMessage = String.format("Command format is invalid! \n" - + AddEventCommand.MESSAGE_USAGE); + + RemoveEventCommand.MESSAGE_USAGE); String expectedMessage2 = String.format("Invalid index!\n" - + "Index can only be 'user' or a 'positive integer!' \n"); + + "Index can only be 'user' or a positive integer! \n"); // missing event name prefix - assertParseFailure(parser, "user h/2023-10-10 1030 1130 r/y", + assertParseFailure(parser, "user", expectedMessage); // all prefixes missing diff --git a/src/test/java/seedu/address/logic/parser/RemoveScheduleCommandParserTest.java b/src/test/java/seedu/address/logic/parser/RemoveScheduleCommandParserTest.java index bef1c67cb85..1efb4f5bf3f 100644 --- a/src/test/java/seedu/address/logic/parser/RemoveScheduleCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/RemoveScheduleCommandParserTest.java @@ -9,7 +9,6 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; -import seedu.address.logic.commands.AddEventCommand; import seedu.address.logic.commands.RemoveScheduleCommand; public class RemoveScheduleCommandParserTest { @@ -20,66 +19,55 @@ public void parse_allFieldsPresent_success() { // cca in user assertParseSuccess(parser, "user type/cca en/Basketball", - new RemoveScheduleCommand("Basketball", "cca", null)); + new RemoveScheduleCommand("basketball", "cca")); // cca in friend assertParseSuccess(parser, "1 type/cca en/Basketball", - new RemoveScheduleCommand("Basketball", "cca", Index.fromOneBased(1))); + new RemoveScheduleCommand("basketball", "cca", Index.fromOneBased(1))); // module in user assertParseSuccess(parser, "user type/module en/CS2103", - new RemoveScheduleCommand("CS2103", "module", Index.fromOneBased(1))); + new RemoveScheduleCommand("cs2103", "module")); // module in friend assertParseSuccess(parser, "1 type/module en/CS2103", - new RemoveScheduleCommand("CS2103", "module", Index.fromOneBased(1))); + new RemoveScheduleCommand("cs2103", "module", Index.fromOneBased(1))); } @Test public void parse_repeatedValue_failure() { - String validCommand = "user type/cca en/Basketabll"; + String validCommand = "user type/cca en/Basketball"; // multiple event type - assertParseFailure(parser, validCommand + "type/cca", + assertParseFailure(parser, validCommand + " type/cca", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTTYPE)); // multiple event name - assertParseFailure(parser, validCommand + "en/Basketball", + assertParseFailure(parser, validCommand + " en/Basketball", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTNAME)); // multiple fields repeated - assertParseFailure(parser, validCommand + "typed/cca" + "en/Basketball", + assertParseFailure(parser, validCommand + " type/cca" + " en/Basketball", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTTYPE, PREFIX_EVENTNAME)); - // invalid value followed by valid value - - // invalid type - assertParseFailure(parser, "typed/cca" + validCommand, - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTTYPE)); - - // invalid name - assertParseFailure(parser, "en/Basketball" + validCommand, - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTNAME)); - - //valid value followed by invalid value // invalid type - assertParseFailure(parser, validCommand + "typed/cca", + assertParseFailure(parser, validCommand + " type/cca", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTTYPE)); // invalid name - assertParseFailure(parser, validCommand + "en/Basketball", + assertParseFailure(parser, validCommand + " en/Basketball", Messages.getErrorMessageForDuplicatePrefixes(PREFIX_EVENTNAME)); } @Test public void parse_fieldMissing_failure() { String expectedMessage = String.format("Command format is invalid! \n" - + AddEventCommand.MESSAGE_USAGE); + + RemoveScheduleCommand.MESSAGE_USAGE); String expectedMessage2 = String.format("Invalid index!\n" - + "Index can only be 'user' or a 'positive integer!' \n"); + + "Index can only be 'user' or a positive integer! \n"); // missing event name prefix assertParseFailure(parser, "user type/cca", diff --git a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java index e024ad84804..44fbbd6e557 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java @@ -119,7 +119,7 @@ public void toModelType_invalidBirthday_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, INVALID_BIRTHDAY, VALID_SCHEDULE, VALID_TAGS); - String expectedMessage = "Birthday should be in the format of YYYY-MM-DD OR YYYY-M-D " + String expectedMessage = "Birthday should be in the format of YYYY-MM-DD " + "and should be a valid date."; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } diff --git a/src/test/java/seedu/address/storage/JsonAdaptedUserTest.java b/src/test/java/seedu/address/storage/JsonAdaptedUserTest.java index af02e07a315..84ff8346bef 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedUserTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedUserTest.java @@ -124,7 +124,7 @@ public void toModelType_invalidBirthday_throwsIllegalValueException() { JsonAdaptedUser user = new JsonAdaptedUser(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, INVALID_BIRTHDAY, VALID_TAGS, VALID_SCHEDULE, VALID_DATEDEVENTS); - String expectedMessage = "Birthday should be in the format of YYYY-MM-DD OR YYYY-M-D " + String expectedMessage = "Birthday should be in the format of YYYY-MM-DD " + "and should be a valid date."; assertThrows(IllegalValueException.class, expectedMessage, user::toModelType); } diff --git a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java index a102f39fded..9c82707166a 100644 --- a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java +++ b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java @@ -16,20 +16,19 @@ public class JsonSerializableAddressBookTest { private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "JsonSerializableAddressBookTest"); - private static final Path TYPICAL_PERSONS_FILE = TEST_DATA_FOLDER.resolve("typicalPersonsAddressBook.json"); private static final Path INVALID_PERSON_FILE = TEST_DATA_FOLDER.resolve("invalidPersonAddressBook.json"); private static final Path DUPLICATE_PERSON_FILE = TEST_DATA_FOLDER.resolve("duplicatePersonAddressBook.json"); + private static final Path TYPICAL_PERSONS_FILE = TEST_DATA_FOLDER.resolve("smallTypicalPersonsAddressBook.json"); @Test public void toModelType_typicalPersonsFile_success() throws Exception { JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(TYPICAL_PERSONS_FILE, JsonSerializableAddressBook.class).get(); AddressBook addressBookFromFile = dataFromFile.toModelType(); - AddressBook typicalPersonsAddressBook = TypicalPersons.getTypicalAddressBook(); + AddressBook typicalPersonsAddressBook = TypicalPersons.getSmallTypicalAddressBook(); assertEquals(addressBookFromFile, typicalPersonsAddressBook); } - @Test public void toModelType_invalidPersonFile_throwsIllegalValueException() throws Exception { JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(INVALID_PERSON_FILE, diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java index f9194614c44..037bc431447 100644 --- a/src/test/java/seedu/address/testutil/TypicalPersons.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -78,6 +78,12 @@ public static AddressBook getTypicalAddressBook() { return ab; } + public static AddressBook getSmallTypicalAddressBook() { + AddressBook ab = new AddressBook(); + ab.addPerson(GEORGE); + return ab; + } + public static List getTypicalPersons() { return new ArrayList<>(Arrays.asList(ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE)); }