From 168bd5bacfa1862e4d48c59edc962cdc2a50bc59 Mon Sep 17 00:00:00 2001 From: Han Bin Date: Fri, 8 Nov 2024 04:56:25 +0800 Subject: [PATCH 1/5] Refractor Message from Task and Find Command Refractor Messages from Task and Find Command. Fix bugs for certain messages with wrong formatting. --- .../java/seedu/address/logic/Messages.java | 99 ++++++++++++++----- .../findcommand/FindAddressCommand.java | 10 +- .../commands/findcommand/FindCommand.java | 2 - .../findcommand/FindEmailCommand.java | 9 +- .../commands/findcommand/FindNameCommand.java | 10 +- .../findcommand/FindPhoneCommand.java | 11 +-- .../commands/findcommand/FindTagCommand.java | 10 +- .../commands/findcommand/FindTaskCommand.java | 10 +- .../findcommand/FindWeddingCommand.java | 10 +- .../commands/task/AssignTaskCommand.java | 20 ++-- .../commands/task/CreateTaskCommand.java | 10 +- .../commands/task/DeleteTaskCommand.java | 6 +- .../logic/commands/task/ListTasksCommand.java | 5 +- .../logic/commands/task/MarkTaskCommand.java | 7 +- .../commands/task/TaskStatusModifier.java | 1 - .../commands/task/UnassignTaskCommand.java | 20 ++-- .../commands/task/UnmarkTaskCommand.java | 5 +- .../findcommand/FindAddressCommandTest.java | 23 +++-- .../findcommand/FindEmailCommandTest.java | 25 +++-- .../findcommand/FindNameCommandTest.java | 19 ++-- .../findcommand/FindPhoneCommandTest.java | 25 +++-- .../findcommand/FindTagCommandTest.java | 9 +- .../findcommand/FindTaskCommandTest.java | 6 +- .../findcommand/FindWeddingCommandTest.java | 15 +-- .../commands/task/AssignTaskCommandTest.java | 21 ++-- .../commands/task/CreateTaskCommandTest.java | 7 +- .../commands/task/DeleteTaskCommandTest.java | 4 +- .../commands/task/MarkTaskCommandTest.java | 2 +- .../task/UnassignTaskCommandTest.java | 5 +- .../commands/task/UnmarkTaskCommandTest.java | 2 +- 30 files changed, 247 insertions(+), 161 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 66d9714419c..27a3702957a 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -16,48 +16,97 @@ */ public class Messages { - public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command"; - public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; + /** + * General Messages + */ public static final String MESSAGE_ENTER_VALID_INDEX = "Please enter a valid index from %d to %d."; + public static final String MESSAGE_DUPLICATE_FIELDS = + "Multiple values specified for the following single-valued field(s): "; + public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; public static final String MESSAGE_NOTHING_TO_PERFORM_ON = "There are no %s to %s."; + public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command"; + + /** + * Messages specific to People + */ public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid. \n" + MESSAGE_ENTER_VALID_INDEX; - public static final String MESSAGE_INVALID_TASK_DISPLAYED_INDEX = "The task index provided (%d) is invalid. \n" - + MESSAGE_ENTER_VALID_INDEX; - public static final String MESSAGE_INVALID_DATE_FORMAT = "Invalid date format. Expected format: yyyy-MM-dd"; - public static final String MESSAGE_TASK_NOT_FOUND_IN_AB = "Task does not exist in the address book."; - public static final String MESSAGE_TO_BEFORE_FROM_INVALID = "\"From\" date must be before \"To\" date."; - public static final String MESSAGE_INVALID_WEDDING_DISPLAYED_INDEX = "The wedding index provided is invalid"; - public static final String MESSAGE_DUPLICATE_FIELDS = - "Multiple values specified for the following single-valued field(s): "; + + /** + * Messages specific to Tag + */ + public static final String MESSAGE_ADD_TAG_SUCCESS = "Added tag(s) %1$s to %2$s."; + public static final String MESSAGE_FORCE_TAG_TO_CONTACT = "Use f/ to force the tagging of contacts." + + " This will create the require Tags."; + public static final String MESSAGE_FORCE_DELETE_TAG = "Use f/ to force the deletion of tags." + + " This will unassign all people currently with the Tag."; + public static final String MESSAGE_TAG_NOT_FOUND = "One or more specified tags do not exist in the Wedlinker."; public static final String MESSAGE_TAG_NOT_FOUND_IN_CONTACT = "Some tags were not found in the person's tag list."; - public static final String MESSAGE_ADD_TAG_SUCCESS = "Added tag(s) %1$s to %2$s."; - public static final String MESSAGE_ADD_TASK_SUCCESS = "Added task(s) %1$s to %2$s."; - public static final String MESSAGE_UNASSIGN_TASK_SUCCESS = "Removed task(s) %1$s from %2$s."; - public static final String MESSAGE_TASK_NOT_FOUND_IN_CONTACT = "Some task(s) " - + "were not found in the person's task list."; - public static final String MESSAGE_ONLY_VENDOR_CAN_BE_ASSIGNED_TASK = "%1$s is not a Vendor, " - + "tasks can only be assigned to vendors."; + /** + * Messages specific to Wedding + */ public static final String MESSAGE_ADD_WEDDING_SUCCESS = "Added wedding(s) %1$s to %2$s."; + public static final String MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT = "Use f/ to force the assignment of wedding(s)." + + " This will automatically help you create the wedding required."; + public static final String MESSAGE_FORCE_DELETE_WEDDING = "Use f/ to force the deletion of wedding." + + " This will unassign all people currently assigned to this Wedding."; + public static final String MESSAGE_INVALID_WEDDING_DISPLAYED_INDEX = "The wedding index provided is invalid"; public static final String MESSAGE_REMOVE_WEDDING_SUCCESS = "Removed wedding(s) %1$s from %2$s."; public static final String MESSAGE_WEDDING_NOT_FOUND = "One or more specified weddings do not exist in " + "the Wedlinker."; public static final String MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT = "Some weddings were not found in " + "the person's wedding list."; - public static final String MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT = "Use f/ to force the assignment of wedding(s)." - + " This will automatically help you create the wedding required."; - public static final String MESSAGE_FORCE_DELETE_WEDDING = "Use f/ to force the deletion of wedding." - + " This will unassign all people currently assigned to this Wedding."; - public static final String MESSAGE_FORCE_TAG_TO_CONTACT = "Use f/ to force the tagging of contacts." - + " This will create the require Tags."; - public static final String MESSAGE_FORCE_DELETE_TAG = "Use f/ to force the deletion of tags." - + " This will unassign all people currently with the Tag."; + + /** + * Messages specific to Task + */ + public static final String MESSAGE_ADD_TASK_SUCCESS = "Added task(s) %1$s to %2$s."; + public static final String MESSAGE_DUPLICATE_TASK_IN_PERSON = "Task '%s' is already assigned to %s"; + public static final String MESSAGE_DUPLICATE_TASK_IN_WEDLINKER = "This task already exists in the address book"; + public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted task: %1$s"; + public static final String MESSAGE_INVALID_TASK_DISPLAYED_INDEX = "The task index provided (%d) is invalid. \n" + + MESSAGE_ENTER_VALID_INDEX; + public static final String MESSAGE_INVALID_DATE_FORMAT = "Invalid date format. Expected format: yyyy-MM-dd"; + public static final String MESSAGE_LIST_SUCCESS = "Listed all tasks"; + public static final String MESSAGE_MARK_TASK_SUCCESS = "Marked task: %1$s"; + public static final String MESSAGE_ONLY_VENDOR_CAN_BE_ASSIGNED_TASK = "%1$s is not a Vendor, " + + "tasks can only be assigned to vendors."; + public static final String MESSAGE_SUCCESS = "New task(s) added: %1$s"; public static final String MESSAGE_TASK_ALREADY_COMPLETED = "Some tasks specified are already completed."; public static final String MESSAGE_TASK_ALREADY_UNCOMPLETED = "Some tasks specified are already uncompleted."; + public static final String MESSAGE_TASK_NOT_FOUND_IN_AB = "Task does not exist in the address book."; + public static final String MESSAGE_TASK_NOT_FOUND_IN_CONTACT = "Some task(s) " + + "were not found in the person's task list."; + public static final String MESSAGE_TO_BEFORE_FROM_INVALID = "\"From\" date must be before \"To\" date."; + public static final String MESSAGE_UNASSIGN_TASK_SUCCESS = "Removed task(s) %1$s from %2$s."; + public static final String MESSAGE_UNMARK_TASK_SUCCESS = "Unmarked task: %1$s"; + + /** + * Messages specific to Vendor + */ public static final String MESSAGE_FORCE_UNASSIGN_VENDOR = "Use f/ to force the unassignment of vendors." + " This will unassign all tasks currently with the Vendor."; + /** + * Messages specific to Find + */ + public static final String MESSAGE_FIND_ADDRESS_PERSON_SUCCESS = "Search for address containing \"%s\" " + + " was successful. Showing results:"; + public static final String MESSAGE_FIND_EMAIL_PERSON_SUCCESS = "Search for email containing \"%s\" was successful. " + + " Showing results:"; + public static final String MESSAGE_FIND_NAME_PERSON_SUCCESS = "Search for name containing \"%s\" was successful. " + + " Showing results:"; + public static final String MESSAGE_FIND_PHONE_PERSON_SUCCESS = "Search for phone number containing \"%s\" " + + " was successful. Showing results:"; + public static final String MESSAGE_FIND_TAG_PERSON_SUCCESS = "Search for tag containing \"%s\" was successful. " + + " Showing results:"; + public static final String MESSAGE_FIND_TASK_PERSON_SUCCESS = "Search for task containing \"%s\" was successful. " + + " Showing results:"; + public static final String MESSAGE_FIND_WEDDING_PERSON_SUCCESS = "Search for wedding(s) containing " + + "\"%s\" was successful. Showing results:"; + public static final String MESSAGE_FIND_PERSON_UNSUCCESSFUL = "No contacts found."; + /** * Returns an error message indicating the duplicate prefixes. */ diff --git a/src/main/java/seedu/address/logic/commands/findcommand/FindAddressCommand.java b/src/main/java/seedu/address/logic/commands/findcommand/FindAddressCommand.java index 20b29b02c00..37eae487e30 100644 --- a/src/main/java/seedu/address/logic/commands/findcommand/FindAddressCommand.java +++ b/src/main/java/seedu/address/logic/commands/findcommand/FindAddressCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.person.keywordspredicate.AddressContainsKeywordsPredicate; @@ -11,9 +12,6 @@ */ public class FindAddressCommand extends FindCommand { - public static final String MESSAGE_FIND_ADDRESS_PERSON_SUCCESS = "Search for address containing \"%s\" " - + " was successful. Showing results:"; - /** * Command to filter contacts in WedLinker based on phone numbers. * The search matches any parts of the phone numbers. @@ -30,9 +28,11 @@ public CommandResult execute(Model model) { model.updateFilteredPersonList((AddressContainsKeywordsPredicate) predicate); if (!model.getFilteredPersonList().isEmpty()) { - return new CommandResult(String.format(MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString())); + return new CommandResult(String.format( + Messages.MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString() + )); } else { - return new CommandResult(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + return new CommandResult(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); } } diff --git a/src/main/java/seedu/address/logic/commands/findcommand/FindCommand.java b/src/main/java/seedu/address/logic/commands/findcommand/FindCommand.java index 3e78ea70118..b79a4284aac 100644 --- a/src/main/java/seedu/address/logic/commands/findcommand/FindCommand.java +++ b/src/main/java/seedu/address/logic/commands/findcommand/FindCommand.java @@ -24,8 +24,6 @@ public abstract class FindCommand extends Command { + "Parameters: PREFIX/ KEYWORDS [MORE_KEYWORDS]...\n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + " alice charlie"; - public static final String MESSAGE_FIND_PERSON_UNSUCCESSFUL = "No contacts found."; - protected final TraitContainsKeywordsPredicate predicate; public FindCommand(TraitContainsKeywordsPredicate predicate) { diff --git a/src/main/java/seedu/address/logic/commands/findcommand/FindEmailCommand.java b/src/main/java/seedu/address/logic/commands/findcommand/FindEmailCommand.java index 0a563bcac15..1cbabd536b3 100644 --- a/src/main/java/seedu/address/logic/commands/findcommand/FindEmailCommand.java +++ b/src/main/java/seedu/address/logic/commands/findcommand/FindEmailCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.person.keywordspredicate.EmailContainsKeywordsPredicate; @@ -10,8 +11,6 @@ * Keyword matching is case-insensitive and allows partial matching, including numbers and symbols. */ public class FindEmailCommand extends FindCommand { - public static final String MESSAGE_FIND_EMAIL_PERSON_SUCCESS = "Search for email containing \"%s\" was successful. " - + " Showing results:"; /** * Command to filter contacts in WedLinker based on names using partial matching. @@ -30,9 +29,11 @@ public CommandResult execute(Model model) { model.updateFilteredPersonList((EmailContainsKeywordsPredicate) predicate); if (!model.getFilteredPersonList().isEmpty()) { - return new CommandResult(String.format(MESSAGE_FIND_EMAIL_PERSON_SUCCESS, predicate.getDisplayString())); + return new CommandResult(String.format( + Messages.MESSAGE_FIND_EMAIL_PERSON_SUCCESS, predicate.getDisplayString() + )); } else { - return new CommandResult(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + return new CommandResult(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); } } diff --git a/src/main/java/seedu/address/logic/commands/findcommand/FindNameCommand.java b/src/main/java/seedu/address/logic/commands/findcommand/FindNameCommand.java index 52c6478dc61..93deaebaa02 100644 --- a/src/main/java/seedu/address/logic/commands/findcommand/FindNameCommand.java +++ b/src/main/java/seedu/address/logic/commands/findcommand/FindNameCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.person.keywordspredicate.NameContainsKeywordsPredicate; @@ -11,9 +12,6 @@ */ public class FindNameCommand extends FindCommand { - public static final String MESSAGE_FIND_NAME_PERSON_SUCCESS = "Search for name containing \"%s\" was successful. " - + " Showing results:"; - /** * Command to filter contacts in WedLinker based on names using partial matching. * This command allows users to search for contacts by providing one or more keywords. @@ -31,9 +29,11 @@ public CommandResult execute(Model model) { model.updateFilteredPersonList((NameContainsKeywordsPredicate) predicate); if (!model.getFilteredPersonList().isEmpty()) { - return new CommandResult(String.format(MESSAGE_FIND_NAME_PERSON_SUCCESS, predicate.getDisplayString())); + return new CommandResult(String.format( + Messages.MESSAGE_FIND_NAME_PERSON_SUCCESS, predicate.getDisplayString() + )); } else { - return new CommandResult(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + return new CommandResult(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); } } diff --git a/src/main/java/seedu/address/logic/commands/findcommand/FindPhoneCommand.java b/src/main/java/seedu/address/logic/commands/findcommand/FindPhoneCommand.java index 700e278a02d..2803252ce1c 100644 --- a/src/main/java/seedu/address/logic/commands/findcommand/FindPhoneCommand.java +++ b/src/main/java/seedu/address/logic/commands/findcommand/FindPhoneCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.person.keywordspredicate.PhoneContainsKeywordsPredicate; @@ -11,10 +12,6 @@ */ public class FindPhoneCommand extends FindCommand { - public static final String MESSAGE_FIND_PHONE_PERSON_SUCCESS = "Search for phone number containing \"%s\" " - + " was successful. Showing results:"; - - /** * Command to filter contacts in WedLinker based on phone numbers. * The search matches any parts of the phone numbers. @@ -31,9 +28,11 @@ public CommandResult execute(Model model) { model.updateFilteredPersonList((PhoneContainsKeywordsPredicate) predicate); if (!model.getFilteredPersonList().isEmpty()) { - return new CommandResult(String.format(MESSAGE_FIND_PHONE_PERSON_SUCCESS, predicate.getDisplayString())); + return new CommandResult(String.format( + Messages.MESSAGE_FIND_PHONE_PERSON_SUCCESS, predicate.getDisplayString() + )); } else { - return new CommandResult(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + return new CommandResult(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); } } diff --git a/src/main/java/seedu/address/logic/commands/findcommand/FindTagCommand.java b/src/main/java/seedu/address/logic/commands/findcommand/FindTagCommand.java index cdb24e55cf1..eaf4829661f 100644 --- a/src/main/java/seedu/address/logic/commands/findcommand/FindTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/findcommand/FindTagCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.person.keywordspredicate.TagContainsKeywordsPredicate; @@ -12,9 +13,6 @@ */ public class FindTagCommand extends FindCommand { - public static final String MESSAGE_FIND_TAG_PERSON_SUCCESS = "Search for tag containing \"%s\" was successful. " - + " Showing results:"; - public FindTagCommand(TagContainsKeywordsPredicate predicate) { super(predicate); } @@ -25,9 +23,11 @@ public CommandResult execute(Model model) { model.updateFilteredPersonListByTag((TagContainsKeywordsPredicate) predicate); if (!model.getFilteredPersonList().isEmpty()) { - return new CommandResult(String.format(MESSAGE_FIND_TAG_PERSON_SUCCESS, predicate.getDisplayString())); + return new CommandResult(String.format( + Messages.MESSAGE_FIND_TAG_PERSON_SUCCESS, predicate.getDisplayString() + )); } else { - return new CommandResult(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + return new CommandResult(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); } } diff --git a/src/main/java/seedu/address/logic/commands/findcommand/FindTaskCommand.java b/src/main/java/seedu/address/logic/commands/findcommand/FindTaskCommand.java index 9ae9fa45bf3..23a369f434c 100644 --- a/src/main/java/seedu/address/logic/commands/findcommand/FindTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/findcommand/FindTaskCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.person.keywordspredicate.TaskContainsKeywordsPredicate; @@ -12,9 +13,6 @@ */ public class FindTaskCommand extends FindCommand { - public static final String MESSAGE_FIND_TASK_PERSON_SUCCESS = "Search for task containing \"%s\" was successful. " - + " Showing results:"; - public FindTaskCommand(TaskContainsKeywordsPredicate predicate) { super(predicate); } @@ -25,9 +23,11 @@ public CommandResult execute(Model model) { model.updateFilteredPersonListByTask((TaskContainsKeywordsPredicate) predicate); if (!model.getFilteredPersonList().isEmpty()) { - return new CommandResult(String.format(MESSAGE_FIND_TASK_PERSON_SUCCESS, predicate.getDisplayString())); + return new CommandResult(String.format( + Messages.MESSAGE_FIND_TASK_PERSON_SUCCESS, predicate.getDisplayString() + )); } else { - return new CommandResult(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + return new CommandResult(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); } } diff --git a/src/main/java/seedu/address/logic/commands/findcommand/FindWeddingCommand.java b/src/main/java/seedu/address/logic/commands/findcommand/FindWeddingCommand.java index bb629ccda21..8a369a4d059 100644 --- a/src/main/java/seedu/address/logic/commands/findcommand/FindWeddingCommand.java +++ b/src/main/java/seedu/address/logic/commands/findcommand/FindWeddingCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.person.keywordspredicate.WeddingContainsKeywordsPredicate; @@ -12,9 +13,6 @@ */ public class FindWeddingCommand extends FindCommand { - public static final String MESSAGE_FIND_WEDDING_PERSON_SUCCESS = "Search for wedding(s) containing " - + "\"%s\" was successful. Showing results:"; - public FindWeddingCommand(WeddingContainsKeywordsPredicate predicate) { super(predicate); } @@ -25,9 +23,11 @@ public CommandResult execute(Model model) { model.updateFilteredPersonListByWedding((WeddingContainsKeywordsPredicate) predicate); if (!model.getFilteredPersonList().isEmpty()) { - return new CommandResult(String.format(MESSAGE_FIND_WEDDING_PERSON_SUCCESS, predicate.getDisplayString())); + return new CommandResult(String.format( + Messages.MESSAGE_FIND_WEDDING_PERSON_SUCCESS, predicate.getDisplayString() + )); } else { - return new CommandResult(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + return new CommandResult(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); } } diff --git a/src/main/java/seedu/address/logic/commands/task/AssignTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/AssignTaskCommand.java index d8ca07bfa2c..d508f73accf 100644 --- a/src/main/java/seedu/address/logic/commands/task/AssignTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/AssignTaskCommand.java @@ -1,10 +1,6 @@ package seedu.address.logic.commands.task; import static java.util.Objects.requireNonNull; -import static seedu.address.logic.Messages.MESSAGE_ADD_TASK_SUCCESS; -import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; -import static seedu.address.logic.Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX; -import static seedu.address.logic.Messages.MESSAGE_ONLY_VENDOR_CAN_BE_ASSIGNED_TASK; import java.util.HashSet; import java.util.List; @@ -12,6 +8,7 @@ import java.util.stream.Collectors; import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; @@ -37,7 +34,6 @@ public class AssignTaskCommand extends Command { + "TASK_INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 1 " + "1"; - public static final String MESSAGE_DUPLICATE_TASK = "Task '%s' is already assigned to %s"; private final Index personIndex; private final Set taskIndexes; @@ -64,7 +60,9 @@ private String generateSuccessMessage(Person personToEdit, Set taskToAdd) String addedTasks = taskToAdd.stream() .map(task -> task.toString().replaceAll("[\\[\\]]", "")) .collect(Collectors.joining(", ")); - return String.format(MESSAGE_ADD_TASK_SUCCESS, addedTasks, personToEdit.getName().toString()); + return String.format( + Messages.MESSAGE_ADD_TASK_SUCCESS, addedTasks, personToEdit.getName().toString() + ); } @Override @@ -74,24 +72,26 @@ public CommandResult execute(Model model) throws CommandException { if (personIndex.getZeroBased() >= lastShownPersonList.size()) { - throw new CommandException(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } Person personToEdit = lastShownPersonList.get(personIndex.getZeroBased()); if (!personToEdit.isVendor()) { - throw new CommandException(String.format(MESSAGE_ONLY_VENDOR_CAN_BE_ASSIGNED_TASK, personToEdit.getName())); + throw new CommandException(String.format( + Messages.MESSAGE_ONLY_VENDOR_CAN_BE_ASSIGNED_TASK, personToEdit.getName() + )); } Set tasksToAdd = new HashSet<>(); Set updatedTasks = new HashSet<>(personToEdit.getTasks()); for (Index taskIndex : taskIndexes) { if (taskIndex.getZeroBased() >= lastShownTaskList.size()) { - throw new CommandException(MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); } Task newTask = lastShownTaskList.get(taskIndex.getZeroBased()); if (updatedTasks.contains(newTask)) { - throw new CommandException(String.format(MESSAGE_DUPLICATE_TASK, + throw new CommandException(String.format(Messages.MESSAGE_DUPLICATE_TASK_IN_PERSON, newTask.toString(), personToEdit.getName().toString())); } tasksToAdd.add(newTask); diff --git a/src/main/java/seedu/address/logic/commands/task/CreateTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/CreateTaskCommand.java index 1716940a605..64c219f36d8 100644 --- a/src/main/java/seedu/address/logic/commands/task/CreateTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/CreateTaskCommand.java @@ -8,6 +8,7 @@ import seedu.address.commons.util.StringUtil; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.logic.Messages; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; @@ -36,9 +37,6 @@ public class CreateTaskCommand extends Command { + PREFIX_TASK + "Secure venue d/2024-10-31 " + PREFIX_TASK + "Inform groom of itinerary"; - public static final String MESSAGE_SUCCESS = "New task(s) added: %1$s"; - public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the address book"; - private final HashSet tasksToAdd; /** @@ -62,12 +60,14 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); for (Task task : tasksToAdd) { if (model.hasTask(task)) { - throw new CommandException(MESSAGE_DUPLICATE_TASK); + throw new CommandException(Messages.MESSAGE_DUPLICATE_TASK_IN_WEDLINKER); } model.addTask(task); } - return new CommandResult(String.format(MESSAGE_SUCCESS, StringUtil.tasksString(tasksToAdd))); + return new CommandResult(String.format( + Messages.MESSAGE_SUCCESS, StringUtil.tasksString(tasksToAdd) + )); } @Override diff --git a/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java index a75a1083a00..f81c450438b 100644 --- a/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java @@ -31,8 +31,6 @@ public class DeleteTaskCommand extends Command { + "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 1"; - public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted task: %1$s"; - private final Index targetIndex; public DeleteTaskCommand(Index targetIndex) { @@ -66,7 +64,9 @@ public CommandResult execute(Model model) throws CommandException { model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); } - return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete.toString())); + return new CommandResult(String.format( + Messages.MESSAGE_DELETE_TASK_SUCCESS, taskToDelete.toString() + )); } @Override diff --git a/src/main/java/seedu/address/logic/commands/task/ListTasksCommand.java b/src/main/java/seedu/address/logic/commands/task/ListTasksCommand.java index f5b9857d377..67145f949db 100644 --- a/src/main/java/seedu/address/logic/commands/task/ListTasksCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/ListTasksCommand.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_TASKS; +import seedu.address.logic.Messages; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.CommandResult.SwitchView; @@ -18,12 +19,10 @@ public class ListTasksCommand extends Command { public static final String COMMAND_KEYWORD = "ltasks"; - public static final String MESSAGE_SUCCESS = "Listed all tasks"; - @Override public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS); - return new CommandResult(MESSAGE_SUCCESS, SwitchView.TASK); + return new CommandResult(Messages.MESSAGE_LIST_SUCCESS, SwitchView.TASK); } } diff --git a/src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java index 2b0e0f1e708..f59c13a4cd7 100644 --- a/src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java @@ -4,6 +4,7 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.logic.Messages; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; @@ -25,8 +26,6 @@ public class MarkTaskCommand extends Command { + "Example: " + COMMAND_WORD + " 1\n" + COMMAND_WORD + " 1 3 5\n"; - public static final String MESSAGE_MARK_TASK_SUCCESS = "Marked task: %1$s"; - private final TaskStatusModifier taskStatusModifier; public MarkTaskCommand(Set targetIndexes) { @@ -38,7 +37,9 @@ public Set getTargetIndexes() { @Override public CommandResult execute(Model model) throws CommandException { Set markedTasks = taskStatusModifier.modifyTasks(model); - return new CommandResult(String.format(MESSAGE_MARK_TASK_SUCCESS, markedTasks)); + return new CommandResult(String.format( + Messages.MESSAGE_MARK_TASK_SUCCESS, markedTasks + )); } @Override diff --git a/src/main/java/seedu/address/logic/commands/task/TaskStatusModifier.java b/src/main/java/seedu/address/logic/commands/task/TaskStatusModifier.java index 53b129976c7..3488e00aaf3 100644 --- a/src/main/java/seedu/address/logic/commands/task/TaskStatusModifier.java +++ b/src/main/java/seedu/address/logic/commands/task/TaskStatusModifier.java @@ -23,7 +23,6 @@ public class TaskStatusModifier { private final Set targetIndexes; private final boolean markAsDone; - /** * Constructs a {@code TaskStatusModifier} with the specified target indexes and status flag. * diff --git a/src/main/java/seedu/address/logic/commands/task/UnassignTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/UnassignTaskCommand.java index a112861b3a9..688ecdd942c 100644 --- a/src/main/java/seedu/address/logic/commands/task/UnassignTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/UnassignTaskCommand.java @@ -1,10 +1,5 @@ package seedu.address.logic.commands.task; -import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; -import static seedu.address.logic.Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX; -import static seedu.address.logic.Messages.MESSAGE_TASK_NOT_FOUND_IN_CONTACT; -import static seedu.address.logic.Messages.MESSAGE_UNASSIGN_TASK_SUCCESS; - import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; @@ -13,6 +8,7 @@ import java.util.stream.Collectors; import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; @@ -59,7 +55,8 @@ private String generateSuccessMessage(Person personToEdit, Set tasksToRemo String removedTasks = tasksToRemove.stream() .map(task -> task.toString().replaceAll("[\\[\\]]", "")) .collect(Collectors.joining(", ")); - return String.format(MESSAGE_UNASSIGN_TASK_SUCCESS, removedTasks, personToEdit.getName().toString()); + return String.format( + Messages.MESSAGE_UNASSIGN_TASK_SUCCESS, removedTasks, personToEdit.getName().toString()); } @Override @@ -67,7 +64,7 @@ public CommandResult execute(Model model) throws CommandException { List lastShownList = model.getFilteredPersonList(); if (index.getZeroBased() >= lastShownList.size()) { - throw new CommandException(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } Person personToEdit = lastShownList.get(index.getZeroBased()); @@ -75,13 +72,13 @@ public CommandResult execute(Model model) throws CommandException { Set updatedTasks = currentPersonTasks; if (currentPersonTasks.isEmpty() || taskIndexes.isEmpty()) { - throw new CommandException(MESSAGE_TASK_NOT_FOUND_IN_CONTACT); + throw new CommandException(Messages.MESSAGE_TASK_NOT_FOUND_IN_CONTACT); } Set tasksToRemove = getTasksToRemove(currentPersonTasks); if (!updatedTasks.containsAll(tasksToRemove)) { - throw new CommandException(MESSAGE_TASK_NOT_FOUND_IN_CONTACT); + throw new CommandException(Messages.MESSAGE_TASK_NOT_FOUND_IN_CONTACT); } updatedTasks.removeAll(tasksToRemove); @@ -98,7 +95,10 @@ private Set getTasksToRemove(Set currentPersonTasks) throws CommandE List currentPersonTaskList = new ArrayList<>(currentPersonTasks); for (Index specifiedTaskIndex : taskIndexes) { if (specifiedTaskIndex.getZeroBased() >= currentPersonTasks.size()) { - throw new CommandException(MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + throw new CommandException(String.format( + Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX, specifiedTaskIndex.getOneBased(), + 1, currentPersonTasks.size() + )); } Integer indexOfTask = specifiedTaskIndex.getZeroBased(); Task taskToRemove = currentPersonTaskList.get(indexOfTask); diff --git a/src/main/java/seedu/address/logic/commands/task/UnmarkTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/UnmarkTaskCommand.java index 5424ace3801..ea140488db7 100644 --- a/src/main/java/seedu/address/logic/commands/task/UnmarkTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/UnmarkTaskCommand.java @@ -4,6 +4,7 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.logic.Messages; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; @@ -25,8 +26,6 @@ public class UnmarkTaskCommand extends Command { + "Example: " + COMMAND_WORD + " 1\n" + COMMAND_WORD + " 1 3 5\n"; - public static final String MESSAGE_UNMARK_TASK_SUCCESS = "Unmarked task: %1$s"; - private final TaskStatusModifier taskStatusModifier; public UnmarkTaskCommand(Set targetIndexes) { @@ -36,7 +35,7 @@ public UnmarkTaskCommand(Set targetIndexes) { @Override public CommandResult execute(Model model) throws CommandException { Set unmarkedTasks = taskStatusModifier.modifyTasks(model); - return new CommandResult(String.format(MESSAGE_UNMARK_TASK_SUCCESS, unmarkedTasks)); + return new CommandResult(String.format(Messages.MESSAGE_UNMARK_TASK_SUCCESS, unmarkedTasks)); } @Override diff --git a/src/test/java/seedu/address/logic/commands/findcommand/FindAddressCommandTest.java b/src/test/java/seedu/address/logic/commands/findcommand/FindAddressCommandTest.java index 3fd1eb7ccf6..553cd317993 100644 --- a/src/test/java/seedu/address/logic/commands/findcommand/FindAddressCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/findcommand/FindAddressCommandTest.java @@ -4,8 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.findcommand.FindAddressCommand.MESSAGE_FIND_ADDRESS_PERSON_SUCCESS; -import static seedu.address.logic.commands.findcommand.FindCommand.MESSAGE_FIND_PERSON_UNSUCCESSFUL; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.BENSON; import static seedu.address.testutil.TypicalPersons.CARL; @@ -17,6 +15,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -56,7 +55,9 @@ public void equals() { @Test public void execute_fullMatch_singlePersonFound() { AddressContainsKeywordsPredicate predicate = preparePredicate("311, Clementi Ave 2, #02-25"); - String expectedMessage = String.format(MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString() + ); FindAddressCommand command = new FindAddressCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -66,7 +67,9 @@ public void execute_fullMatch_singlePersonFound() { @Test public void execute_partialMatch_singlePersonFound() { AddressContainsKeywordsPredicate predicate = preparePredicate("Jurong"); - String expectedMessage = String.format(MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString() + ); FindAddressCommand command = new FindAddressCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -76,7 +79,9 @@ public void execute_partialMatch_singlePersonFound() { @Test public void execute_partialMatch2_singlePersonFound() { AddressContainsKeywordsPredicate predicate = preparePredicate("wall str"); - String expectedMessage = String.format(MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString() + ); FindAddressCommand command = new FindAddressCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -86,7 +91,9 @@ public void execute_partialMatch2_singlePersonFound() { @Test public void execute_partialMatch_multiplePersonsFound() { AddressContainsKeywordsPredicate predicate = preparePredicate("ave"); - String expectedMessage = String.format(MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_ADDRESS_PERSON_SUCCESS, predicate.getDisplayString() + ); FindAddressCommand command = new FindAddressCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -96,7 +103,7 @@ public void execute_partialMatch_multiplePersonsFound() { @Test public void execute_absentPartialMatchKeyword_noPersonFound() { AddressContainsKeywordsPredicate predicate = preparePredicate("x"); - String expectedMessage = MESSAGE_FIND_PERSON_UNSUCCESSFUL; + String expectedMessage = Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL; FindAddressCommand command = new FindAddressCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -106,7 +113,7 @@ public void execute_absentPartialMatchKeyword_noPersonFound() { @Test public void execute_absentPartialMatchKeyword2_noPersonFound() { AddressContainsKeywordsPredicate predicate = preparePredicate("834 Bukit Batok"); - String expectedMessage = MESSAGE_FIND_PERSON_UNSUCCESSFUL; + String expectedMessage = Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL; FindAddressCommand command = new FindAddressCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); diff --git a/src/test/java/seedu/address/logic/commands/findcommand/FindEmailCommandTest.java b/src/test/java/seedu/address/logic/commands/findcommand/FindEmailCommandTest.java index 5152a38da1b..80739cc7141 100644 --- a/src/test/java/seedu/address/logic/commands/findcommand/FindEmailCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/findcommand/FindEmailCommandTest.java @@ -4,8 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.findcommand.FindCommand.MESSAGE_FIND_PERSON_UNSUCCESSFUL; -import static seedu.address.logic.commands.findcommand.FindEmailCommand.MESSAGE_FIND_EMAIL_PERSON_SUCCESS; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.BENSON; import static seedu.address.testutil.TypicalPersons.CARL; @@ -18,6 +16,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -57,7 +56,7 @@ public void equals() { @Test public void execute_emptyString_noPersonFound() { - String expectedMessage = MESSAGE_FIND_PERSON_UNSUCCESSFUL; + String expectedMessage = Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL; EmailContainsKeywordsPredicate predicate = preparePredicate(" "); FindEmailCommand command = new FindEmailCommand(predicate); expectedModel.updateFilteredPersonList(predicate); @@ -68,7 +67,9 @@ public void execute_emptyString_noPersonFound() { @Test public void execute_fullMatchEmail_singlePersonFound() { EmailContainsKeywordsPredicate predicate = preparePredicate("alice@example.com"); - String expectedMessage = String.format(MESSAGE_FIND_EMAIL_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_EMAIL_PERSON_SUCCESS, predicate.getDisplayString() + ); FindEmailCommand command = new FindEmailCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -78,7 +79,9 @@ public void execute_fullMatchEmail_singlePersonFound() { @Test public void execute_multipleFullMatchEmails_multiplePersonsFound() { EmailContainsKeywordsPredicate predicate = preparePredicate("lydia@example.com heinz@example.com"); - String expectedMessage = String.format(MESSAGE_FIND_EMAIL_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_EMAIL_PERSON_SUCCESS, predicate.getDisplayString() + ); FindEmailCommand command = new FindEmailCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -88,7 +91,9 @@ public void execute_multipleFullMatchEmails_multiplePersonsFound() { @Test public void execute_singlePartialMatchNumber_singlePersonFound() { EmailContainsKeywordsPredicate predicate = preparePredicate("hnd"); - String expectedMessage = String.format(MESSAGE_FIND_EMAIL_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_EMAIL_PERSON_SUCCESS, predicate.getDisplayString() + ); FindEmailCommand command = new FindEmailCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -98,7 +103,9 @@ public void execute_singlePartialMatchNumber_singlePersonFound() { @Test public void execute_singlePartialMatchNumber_multiplePersonsFound() { EmailContainsKeywordsPredicate predicate = preparePredicate("ia"); - String expectedMessage = String.format(MESSAGE_FIND_EMAIL_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_EMAIL_PERSON_SUCCESS, predicate.getDisplayString() + ); FindEmailCommand command = new FindEmailCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -108,7 +115,7 @@ public void execute_singlePartialMatchNumber_multiplePersonsFound() { @Test public void execute_absentPartialMatchKeyword_noPersonFound() { EmailContainsKeywordsPredicate predicate = preparePredicate("xXx"); - String expectedMessage = MESSAGE_FIND_PERSON_UNSUCCESSFUL; + String expectedMessage = Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL; FindEmailCommand command = new FindEmailCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -118,7 +125,7 @@ public void execute_absentPartialMatchKeyword_noPersonFound() { @Test public void execute_absentPartialMatchKeyword2_noPersonFound() { EmailContainsKeywordsPredicate predicate = preparePredicate("allen"); - String expectedMessage = MESSAGE_FIND_PERSON_UNSUCCESSFUL; + String expectedMessage = Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL; FindEmailCommand command = new FindEmailCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); diff --git a/src/test/java/seedu/address/logic/commands/findcommand/FindNameCommandTest.java b/src/test/java/seedu/address/logic/commands/findcommand/FindNameCommandTest.java index 21b61fd1964..0003e05a5c1 100644 --- a/src/test/java/seedu/address/logic/commands/findcommand/FindNameCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/findcommand/FindNameCommandTest.java @@ -4,8 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.findcommand.FindCommand.MESSAGE_FIND_PERSON_UNSUCCESSFUL; -import static seedu.address.logic.commands.findcommand.FindNameCommand.MESSAGE_FIND_NAME_PERSON_SUCCESS; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.BENSON; import static seedu.address.testutil.TypicalPersons.CARL; @@ -20,6 +18,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -61,7 +60,7 @@ public void equals() { @Test public void execute_zeroKeywords_noPersonFound() { - String expectedMessage = MESSAGE_FIND_PERSON_UNSUCCESSFUL; + String expectedMessage = Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL; NameContainsKeywordsPredicate predicate = preparePredicate(" "); FindNameCommand command = new FindNameCommand(predicate); expectedModel.updateFilteredPersonList(predicate); @@ -72,7 +71,9 @@ public void execute_zeroKeywords_noPersonFound() { @Test public void execute_multipleKeywords_multiplePersonsFound() { NameContainsKeywordsPredicate predicate = preparePredicate("Kurz Elle Kunz"); - String expectedMessage = String.format(MESSAGE_FIND_NAME_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_NAME_PERSON_SUCCESS, predicate.getDisplayString() + ); FindNameCommand command = new FindNameCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -82,7 +83,9 @@ public void execute_multipleKeywords_multiplePersonsFound() { @Test public void execute_partialMatchKeyword_correctPersonFound() { NameContainsKeywordsPredicate predicate = preparePredicate("ell"); - String expectedMessage = String.format(MESSAGE_FIND_NAME_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_NAME_PERSON_SUCCESS, predicate.getDisplayString() + ); FindNameCommand command = new FindNameCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -92,7 +95,9 @@ public void execute_partialMatchKeyword_correctPersonFound() { @Test public void execute_partialMatchKeyword_multiplePersonsFound() { NameContainsKeywordsPredicate predicate = preparePredicate("e"); - String expectedMessage = String.format(MESSAGE_FIND_NAME_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_NAME_PERSON_SUCCESS, predicate.getDisplayString() + ); FindNameCommand command = new FindNameCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -102,7 +107,7 @@ public void execute_partialMatchKeyword_multiplePersonsFound() { @Test public void execute_absentPartialMatchKeyword_noPersonFound() { NameContainsKeywordsPredicate predicate = preparePredicate("x"); - String expectedMessage = MESSAGE_FIND_PERSON_UNSUCCESSFUL; + String expectedMessage = Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL; FindNameCommand command = new FindNameCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); diff --git a/src/test/java/seedu/address/logic/commands/findcommand/FindPhoneCommandTest.java b/src/test/java/seedu/address/logic/commands/findcommand/FindPhoneCommandTest.java index 587514828ca..cb7e5e6c8f0 100644 --- a/src/test/java/seedu/address/logic/commands/findcommand/FindPhoneCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/findcommand/FindPhoneCommandTest.java @@ -4,8 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.findcommand.FindCommand.MESSAGE_FIND_PERSON_UNSUCCESSFUL; -import static seedu.address.logic.commands.findcommand.FindPhoneCommand.MESSAGE_FIND_PHONE_PERSON_SUCCESS; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.BENSON; import static seedu.address.testutil.TypicalPersons.CARL; @@ -19,6 +17,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -57,7 +56,7 @@ public void equals() { @Test public void execute_emptyString_noPersonFound() { - String expectedMessage = MESSAGE_FIND_PERSON_UNSUCCESSFUL; + String expectedMessage = Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL; PhoneContainsKeywordsPredicate predicate = preparePredicate(" "); FindPhoneCommand command = new FindPhoneCommand(predicate); expectedModel.updateFilteredPersonList(predicate); @@ -68,7 +67,9 @@ public void execute_emptyString_noPersonFound() { @Test public void execute_fullMatch_singlePersonFound() { PhoneContainsKeywordsPredicate predicate = preparePredicate("9482442"); - String expectedMessage = String.format(MESSAGE_FIND_PHONE_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_PHONE_PERSON_SUCCESS, predicate.getDisplayString() + ); FindPhoneCommand command = new FindPhoneCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -78,7 +79,9 @@ public void execute_fullMatch_singlePersonFound() { @Test public void execute_multipleFullMatchNumbers_multiplePersonsFound() { PhoneContainsKeywordsPredicate predicate = preparePredicate("95352563 9482427"); - String expectedMessage = String.format(MESSAGE_FIND_PHONE_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_PHONE_PERSON_SUCCESS, predicate.getDisplayString() + ); FindPhoneCommand command = new FindPhoneCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -88,7 +91,9 @@ public void execute_multipleFullMatchNumbers_multiplePersonsFound() { @Test public void execute_singlePartialMatchNumber_singlePersonFound() { PhoneContainsKeywordsPredicate predicate = preparePredicate("2224"); - String expectedMessage = String.format(MESSAGE_FIND_PHONE_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_PHONE_PERSON_SUCCESS, predicate.getDisplayString() + ); FindPhoneCommand command = new FindPhoneCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -98,7 +103,9 @@ public void execute_singlePartialMatchNumber_singlePersonFound() { @Test public void execute_singlePartialMatchNumber_multiplePersonsFound() { PhoneContainsKeywordsPredicate predicate = preparePredicate("9"); - String expectedMessage = String.format(MESSAGE_FIND_PHONE_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_PHONE_PERSON_SUCCESS, predicate.getDisplayString() + ); FindPhoneCommand command = new FindPhoneCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -108,7 +115,7 @@ public void execute_singlePartialMatchNumber_multiplePersonsFound() { @Test public void execute_absentPartialMatchKeyword_noPersonFound() { PhoneContainsKeywordsPredicate predicate = preparePredicate("0"); - String expectedMessage = MESSAGE_FIND_PERSON_UNSUCCESSFUL; + String expectedMessage = Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL; FindPhoneCommand command = new FindPhoneCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -118,7 +125,7 @@ public void execute_absentPartialMatchKeyword_noPersonFound() { @Test public void execute_absentPartialMatchKeyword2_noPersonFound() { PhoneContainsKeywordsPredicate predicate = preparePredicate("54321"); - String expectedMessage = MESSAGE_FIND_PERSON_UNSUCCESSFUL; + String expectedMessage = Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL; FindPhoneCommand command = new FindPhoneCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); diff --git a/src/test/java/seedu/address/logic/commands/findcommand/FindTagCommandTest.java b/src/test/java/seedu/address/logic/commands/findcommand/FindTagCommandTest.java index bf33f0c009e..a14c4085a52 100644 --- a/src/test/java/seedu/address/logic/commands/findcommand/FindTagCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/findcommand/FindTagCommandTest.java @@ -4,8 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.findcommand.FindCommand.MESSAGE_FIND_PERSON_UNSUCCESSFUL; -import static seedu.address.logic.commands.findcommand.FindTagCommand.MESSAGE_FIND_TAG_PERSON_SUCCESS; import static seedu.address.testutil.TypicalPersons.BENSON; import static seedu.address.testutil.TypicalPersons.DANIEL; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -15,6 +13,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -55,7 +54,7 @@ public void equals() { @Test public void execute_zeroKeywords_noPersonFound() { - String expectedMessage = String.format(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + String expectedMessage = String.format(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); TagContainsKeywordsPredicate predicate = preparePredicate(" "); FindTagCommand command = new FindTagCommand(predicate); expectedModel.updateFilteredPersonListByTag(predicate); @@ -66,7 +65,9 @@ public void execute_zeroKeywords_noPersonFound() { @Test public void execute_multipleKeywords_multiplePersonsFound() { TagContainsKeywordsPredicate predicate = preparePredicate("florist"); - String expectedMessage = String.format(MESSAGE_FIND_TAG_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_TAG_PERSON_SUCCESS, predicate.getDisplayString() + ); FindTagCommand command = new FindTagCommand(predicate); expectedModel.updateFilteredPersonListByTag(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); diff --git a/src/test/java/seedu/address/logic/commands/findcommand/FindTaskCommandTest.java b/src/test/java/seedu/address/logic/commands/findcommand/FindTaskCommandTest.java index 026c070fdae..782ef8e74ae 100644 --- a/src/test/java/seedu/address/logic/commands/findcommand/FindTaskCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/findcommand/FindTaskCommandTest.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.findcommand.FindCommand.MESSAGE_FIND_PERSON_UNSUCCESSFUL; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.util.Arrays; @@ -12,6 +11,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -51,7 +51,7 @@ public void equals() { @Test public void execute_zeroKeywords_noPersonFound() { - String expectedMessage = String.format(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + String expectedMessage = String.format(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); TaskContainsKeywordsPredicate predicate = preparePredicate(" "); FindTaskCommand command = new FindTaskCommand(predicate); expectedModel.updateFilteredPersonListByTask(predicate); @@ -61,7 +61,7 @@ public void execute_zeroKeywords_noPersonFound() { @Test public void execute_missingKeyword_noPersonsFound() { - String expectedMessage = String.format(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + String expectedMessage = String.format(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); TaskContainsKeywordsPredicate predicate = preparePredicate("XxX"); FindTaskCommand command = new FindTaskCommand(predicate); expectedModel.updateFilteredPersonListByTask(predicate); diff --git a/src/test/java/seedu/address/logic/commands/findcommand/FindWeddingCommandTest.java b/src/test/java/seedu/address/logic/commands/findcommand/FindWeddingCommandTest.java index 5bbbcc0f156..d5eb73b5ffd 100644 --- a/src/test/java/seedu/address/logic/commands/findcommand/FindWeddingCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/findcommand/FindWeddingCommandTest.java @@ -4,8 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.findcommand.FindCommand.MESSAGE_FIND_PERSON_UNSUCCESSFUL; -import static seedu.address.logic.commands.findcommand.FindWeddingCommand.MESSAGE_FIND_WEDDING_PERSON_SUCCESS; import static seedu.address.testutil.TypicalPersons.BENSON; import static seedu.address.testutil.TypicalPersons.ELLE; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -15,6 +13,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -53,7 +52,7 @@ public void equals() { @Test public void execute_zeroKeywords_noPersonFound() { - String expectedMessage = String.format(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + String expectedMessage = String.format(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); WeddingContainsKeywordsPredicate predicate = preparePredicate(" "); FindWeddingCommand command = new FindWeddingCommand(predicate); expectedModel.updateFilteredPersonListByWedding(predicate); @@ -64,7 +63,9 @@ public void execute_zeroKeywords_noPersonFound() { @Test public void execute_multipleKeywords_multiplePersonsFound() { WeddingContainsKeywordsPredicate predicate = preparePredicate("Wedding 2"); - String expectedMessage = String.format(MESSAGE_FIND_WEDDING_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_WEDDING_PERSON_SUCCESS, predicate.getDisplayString() + ); FindWeddingCommand command = new FindWeddingCommand(predicate); expectedModel.updateFilteredPersonListByWedding(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -74,7 +75,9 @@ public void execute_multipleKeywords_multiplePersonsFound() { @Test public void execute_partialMatchKeyword_multiplePersonsFound() { WeddingContainsKeywordsPredicate predicate = preparePredicate("Carl"); - String expectedMessage = String.format(MESSAGE_FIND_WEDDING_PERSON_SUCCESS, predicate.getDisplayString()); + String expectedMessage = String.format( + Messages.MESSAGE_FIND_WEDDING_PERSON_SUCCESS, predicate.getDisplayString() + ); FindWeddingCommand command = new FindWeddingCommand(predicate); expectedModel.updateFilteredPersonListByWedding(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -83,7 +86,7 @@ public void execute_partialMatchKeyword_multiplePersonsFound() { @Test public void execute_missingKeyword_noPersonsFound() { - String expectedMessage = String.format(MESSAGE_FIND_PERSON_UNSUCCESSFUL); + String expectedMessage = String.format(Messages.MESSAGE_FIND_PERSON_UNSUCCESSFUL); WeddingContainsKeywordsPredicate predicate = preparePredicate("XxX"); FindWeddingCommand command = new FindWeddingCommand(predicate); expectedModel.updateFilteredPersonListByWedding(predicate); diff --git a/src/test/java/seedu/address/logic/commands/task/AssignTaskCommandTest.java b/src/test/java/seedu/address/logic/commands/task/AssignTaskCommandTest.java index 04d2f88b963..b30530d5b3d 100644 --- a/src/test/java/seedu/address/logic/commands/task/AssignTaskCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/task/AssignTaskCommandTest.java @@ -3,10 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.Messages.MESSAGE_ADD_TASK_SUCCESS; -import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; -import static seedu.address.logic.Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX; -import static seedu.address.logic.Messages.MESSAGE_ONLY_VENDOR_CAN_BE_ASSIGNED_TASK; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST; import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND; @@ -20,6 +16,7 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; @@ -53,7 +50,9 @@ public void execute_validVendorAndTask_success() throws Exception { CommandResult result = command.execute(model); String addedTasks = taskToAssign.toString().replaceAll("[\\[\\]]", ""); - String expectedMessage = String.format(MESSAGE_ADD_TASK_SUCCESS, addedTasks, validPerson.getName()); + String expectedMessage = String.format( + Messages.MESSAGE_ADD_TASK_SUCCESS, addedTasks, validPerson.getName() + ); assertEquals(expectedMessage, result.getFeedbackToUser()); } @@ -64,7 +63,9 @@ public void execute_invalidPersonIndex_throwsCommandException() { AssignTaskCommand command = new AssignTaskCommand(Index.fromOneBased(10), Set.of(INDEX_FIRST)); // Assert: Command should throw a CommandException for invalid person index - assertThrows(CommandException.class, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, () -> command.execute(model)); + assertThrows( + CommandException.class, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, () -> command.execute(model) + ); } @Test @@ -79,7 +80,9 @@ public void execute_invalidTaskIndex_throwsCommandException() { Set.of(Index.fromOneBased(10))); // Assert: Command should throw a CommandException for invalid task index - assertThrows(CommandException.class, MESSAGE_INVALID_TASK_DISPLAYED_INDEX, () -> command.execute(model)); + assertThrows( + CommandException.class, Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX, () -> command.execute(model) + ); } @Test @@ -91,7 +94,7 @@ public void execute_taskAlreadyAssigned_throwsCommandException() { // Try to assign the same task again AssignTaskCommand command = new AssignTaskCommand(Index.fromZeroBased(0), Set.of(INDEX_FIRST)); // Assert: Command should throw a CommandException for duplicate task assignment - assertThrows(CommandException.class, String.format(AssignTaskCommand.MESSAGE_DUPLICATE_TASK, + assertThrows(CommandException.class, String.format(Messages.MESSAGE_DUPLICATE_TASK_IN_PERSON, taskAlreadyAssigned.toString(), CARL.getName()), () -> command.execute(model)); } @@ -105,7 +108,7 @@ public void execute_personIsNotVendor_throwsCommandException() { AssignTaskCommand command = new AssignTaskCommand(Index.fromZeroBased(0), Set.of(INDEX_FIRST)); // Command should throw a CommandException for non-vendor person - assertThrows(CommandException.class, String.format(MESSAGE_ONLY_VENDOR_CAN_BE_ASSIGNED_TASK, + assertThrows(CommandException.class, String.format(Messages.MESSAGE_ONLY_VENDOR_CAN_BE_ASSIGNED_TASK, nonVendorPerson.getName()), () -> command.execute(model)); } diff --git a/src/test/java/seedu/address/logic/commands/task/CreateTaskCommandTest.java b/src/test/java/seedu/address/logic/commands/task/CreateTaskCommandTest.java index 21684b93a8e..8a00eb36211 100644 --- a/src/test/java/seedu/address/logic/commands/task/CreateTaskCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/task/CreateTaskCommandTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.util.StringUtil; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; @@ -42,7 +43,7 @@ public void execute_addValidTask_success() throws Exception { // Create a CreateTaskCommand with valid tasks CreateTaskCommand command = new CreateTaskCommand(tasksToAdd); - String expectedMessage = String.format(CreateTaskCommand.MESSAGE_SUCCESS, StringUtil.tasksString(tasksToAdd)); + String expectedMessage = String.format(Messages.MESSAGE_SUCCESS, StringUtil.tasksString(tasksToAdd)); CommandResult result = command.execute(model); @@ -60,7 +61,9 @@ public void execute_duplicateTask_throwsCommandException() { CreateTaskCommand command = new CreateTaskCommand(tasksToAdd); - assertThrows(CommandException.class, () -> command.execute(model), CreateTaskCommand.MESSAGE_DUPLICATE_TASK); + assertThrows( + CommandException.class, () -> command.execute(model), Messages.MESSAGE_DUPLICATE_TASK_IN_WEDLINKER + ); } @Test public void getTaskToAdd_validTaskSet_returnsCorrectSet() { diff --git a/src/test/java/seedu/address/logic/commands/task/DeleteTaskCommandTest.java b/src/test/java/seedu/address/logic/commands/task/DeleteTaskCommandTest.java index 00e262bb437..e50f5666db9 100644 --- a/src/test/java/seedu/address/logic/commands/task/DeleteTaskCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/task/DeleteTaskCommandTest.java @@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.ModelManager; @@ -41,7 +42,8 @@ public void execute_validIndex_success() throws Exception { CommandResult result = deleteTaskCommand.execute(model); - String expectedMessage = String.format(DeleteTaskCommand.MESSAGE_DELETE_TASK_SUCCESS, taskToDelete); + String expectedMessage = String.format( + Messages.MESSAGE_DELETE_TASK_SUCCESS, taskToDelete); assertEquals(expectedMessage, result.getFeedbackToUser()); // Ensure the task is removed from the model diff --git a/src/test/java/seedu/address/logic/commands/task/MarkTaskCommandTest.java b/src/test/java/seedu/address/logic/commands/task/MarkTaskCommandTest.java index 8f6c5c14f7f..6f075884f09 100644 --- a/src/test/java/seedu/address/logic/commands/task/MarkTaskCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/task/MarkTaskCommandTest.java @@ -53,7 +53,7 @@ public void execute_validTaskIndex_marksTaskSuccessfully() throws Exception { CommandResult result = command.execute(model); - assertEquals(String.format(MarkTaskCommand.MESSAGE_MARK_TASK_SUCCESS, Set.of(taskToMark)), + assertEquals(String.format(Messages.MESSAGE_MARK_TASK_SUCCESS, Set.of(taskToMark)), result.getFeedbackToUser()); assertTrue(taskToMark.getIsDone(), "The task should be marked as done."); } diff --git a/src/test/java/seedu/address/logic/commands/task/UnassignTaskCommandTest.java b/src/test/java/seedu/address/logic/commands/task/UnassignTaskCommandTest.java index 17729483dd8..447f8c2fdb2 100644 --- a/src/test/java/seedu/address/logic/commands/task/UnassignTaskCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/task/UnassignTaskCommandTest.java @@ -73,7 +73,10 @@ public void execute_invalidTaskIndex_throwsCommandException() { UnassignTaskCommand command = new UnassignTaskCommand(Index.fromZeroBased(0), Set.of(Index.fromOneBased(10))); // Command should throw a CommandException for invalid task index - assertThrows(CommandException.class, MESSAGE_INVALID_TASK_DISPLAYED_INDEX, () -> command.execute(model)); + assertThrows( + CommandException.class, + String.format(MESSAGE_INVALID_TASK_DISPLAYED_INDEX, 10, 1, 1), () -> command.execute(model) + ); } @Test diff --git a/src/test/java/seedu/address/logic/commands/task/UnmarkTaskCommandTest.java b/src/test/java/seedu/address/logic/commands/task/UnmarkTaskCommandTest.java index 0a2ee73bbb1..eb2e3de83da 100644 --- a/src/test/java/seedu/address/logic/commands/task/UnmarkTaskCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/task/UnmarkTaskCommandTest.java @@ -53,7 +53,7 @@ public void execute_validTaskIndex_unmarksTaskSuccessfully() throws Exception { CommandResult result = command.execute(model); - assertEquals(String.format(UnmarkTaskCommand.MESSAGE_UNMARK_TASK_SUCCESS, Set.of(taskToUnmark)), + assertEquals(String.format(Messages.MESSAGE_UNMARK_TASK_SUCCESS, Set.of(taskToUnmark)), result.getFeedbackToUser()); assertFalse(taskToUnmark.getIsDone(), "The task should be unmarked as not done."); } From 72cd31e54ae9dc7931b634fe42dda3c870ca6753 Mon Sep 17 00:00:00 2001 From: Han Bin Date: Fri, 8 Nov 2024 05:18:04 +0800 Subject: [PATCH 2/5] Refractor Message from Vendor Refractor message from Vendors. Fix formatting errors in messages. --- src/main/java/seedu/address/logic/Messages.java | 12 ++++++++++-- .../seedu/address/logic/commands/AddCommand.java | 7 ++----- .../logic/commands/task/AssignTaskCommand.java | 2 +- .../logic/commands/task/CreateTaskCommand.java | 2 +- .../logic/commands/task/MarkTaskCommand.java | 2 ++ .../logic/commands/vendor/AddVendorCommand.java | 10 ++-------- .../logic/commands/vendor/AssignVendorCommand.java | 8 ++------ .../commands/vendor/UnassignVendorCommand.java | 13 +++++-------- .../logic/commands/AddCommandIntegrationTest.java | 4 ++-- .../address/logic/commands/AddCommandTest.java | 4 ++-- .../logic/commands/task/AssignTaskCommandTest.java | 2 +- .../logic/commands/task/CreateTaskCommandTest.java | 2 +- .../logic/commands/vendor/AddVendorCommandTest.java | 3 ++- .../commands/vendor/AssignVendorCommandTest.java | 6 +++--- 14 files changed, 36 insertions(+), 41 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 27a3702957a..175e7e5f494 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -29,8 +29,10 @@ public class Messages { /** * Messages specific to People */ + public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid. \n" + MESSAGE_ENTER_VALID_INDEX; + public static final String MESSAGE_ADD_PERSON_SUCCESS = "New person added: %1$s"; /** * Messages specific to Tag @@ -61,7 +63,7 @@ public class Messages { /** * Messages specific to Task */ - public static final String MESSAGE_ADD_TASK_SUCCESS = "Added task(s) %1$s to %2$s."; + public static final String MESSAGE_ASSIGN_TASK_SUCCESS = "Added task(s) %1$s to %2$s."; public static final String MESSAGE_DUPLICATE_TASK_IN_PERSON = "Task '%s' is already assigned to %s"; public static final String MESSAGE_DUPLICATE_TASK_IN_WEDLINKER = "This task already exists in the address book"; public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted task: %1$s"; @@ -72,7 +74,7 @@ public class Messages { public static final String MESSAGE_MARK_TASK_SUCCESS = "Marked task: %1$s"; public static final String MESSAGE_ONLY_VENDOR_CAN_BE_ASSIGNED_TASK = "%1$s is not a Vendor, " + "tasks can only be assigned to vendors."; - public static final String MESSAGE_SUCCESS = "New task(s) added: %1$s"; + public static final String MESSAGE_TASK_ADDED_SUCCESS = "New task(s) added: %1$s"; public static final String MESSAGE_TASK_ALREADY_COMPLETED = "Some tasks specified are already completed."; public static final String MESSAGE_TASK_ALREADY_UNCOMPLETED = "Some tasks specified are already uncompleted."; public static final String MESSAGE_TASK_NOT_FOUND_IN_AB = "Task does not exist in the address book."; @@ -85,8 +87,14 @@ public class Messages { /** * Messages specific to Vendor */ + public static final String MESSAGE_ADD_VENDOR_SUCCESS = "%1$s has been added as a vendor."; + public static final String MESSAGE_DUPLICATE_VENDOR = "%1$s is already a vendor."; public static final String MESSAGE_FORCE_UNASSIGN_VENDOR = "Use f/ to force the unassignment of vendors." + " This will unassign all tasks currently with the Vendor."; + public static final String MESSAGE_UNASSIGN_VENDOR_FAILURE_TASK_EXISTS = "The Vendor: %1$s still has tasks" + + " assigned to them"; + public static final String MESSAGE_UNASSIGN_VENDOR_FAILURE_NOT_VENDOR = "%1$s is not a vendor."; + public static final String MESSAGE_UNASSIGN_VENDOR_SUCCESS = "%1$s has been unassigned and is no longer a vendor."; /** * Messages specific to Find diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 91a1bf046d3..b6f7e9aa5d9 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -39,9 +39,6 @@ public class AddCommand extends Command { + PREFIX_WEDDING + "Wedding March 20th 2027 " + PREFIX_WEDDING + "Amy's Wedding"; - public static final String MESSAGE_SUCCESS = "New person added: %1$s"; - public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; - private final Person toAdd; /** @@ -57,11 +54,11 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); if (model.hasPerson(toAdd)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); + throw new CommandException(Messages.MESSAGE_DUPLICATE_PERSON); } model.addPerson(toAdd); - return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd))); + return new CommandResult(String.format(Messages.MESSAGE_ADD_PERSON_SUCCESS, Messages.format(toAdd))); } @Override diff --git a/src/main/java/seedu/address/logic/commands/task/AssignTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/AssignTaskCommand.java index d508f73accf..99dd7fde1e5 100644 --- a/src/main/java/seedu/address/logic/commands/task/AssignTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/AssignTaskCommand.java @@ -61,7 +61,7 @@ private String generateSuccessMessage(Person personToEdit, Set taskToAdd) .map(task -> task.toString().replaceAll("[\\[\\]]", "")) .collect(Collectors.joining(", ")); return String.format( - Messages.MESSAGE_ADD_TASK_SUCCESS, addedTasks, personToEdit.getName().toString() + Messages.MESSAGE_ASSIGN_TASK_SUCCESS, addedTasks, personToEdit.getName().toString() ); } diff --git a/src/main/java/seedu/address/logic/commands/task/CreateTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/CreateTaskCommand.java index 64c219f36d8..865166c7b22 100644 --- a/src/main/java/seedu/address/logic/commands/task/CreateTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/CreateTaskCommand.java @@ -66,7 +66,7 @@ public CommandResult execute(Model model) throws CommandException { } return new CommandResult(String.format( - Messages.MESSAGE_SUCCESS, StringUtil.tasksString(tasksToAdd) + Messages.MESSAGE_TASK_ADDED_SUCCESS, StringUtil.tasksString(tasksToAdd) )); } diff --git a/src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java index f59c13a4cd7..fec5cce05f2 100644 --- a/src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java @@ -31,9 +31,11 @@ public class MarkTaskCommand extends Command { public MarkTaskCommand(Set targetIndexes) { this.taskStatusModifier = new TaskStatusModifier(targetIndexes, true); } + public Set getTargetIndexes() { return taskStatusModifier.getTargetIndexes(); } + @Override public CommandResult execute(Model model) throws CommandException { Set markedTasks = taskStatusModifier.modifyTasks(model); diff --git a/src/main/java/seedu/address/logic/commands/vendor/AddVendorCommand.java b/src/main/java/seedu/address/logic/commands/vendor/AddVendorCommand.java index eed33225562..cd83fb82c6c 100644 --- a/src/main/java/seedu/address/logic/commands/vendor/AddVendorCommand.java +++ b/src/main/java/seedu/address/logic/commands/vendor/AddVendorCommand.java @@ -46,12 +46,6 @@ public class AddVendorCommand extends Command { + PREFIX_WEDDING + "Wedding March 20th 2027 " + PREFIX_WEDDING + "Amy's Wedding"; - - public static final String MESSAGE_SUCCESS = "New person added: %1$s"; - public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; - public static final String MESSAGE_DUPLICATE_VENDOR = "This person already exists as a vendor in the address book"; - - private final Person toAdd; /** * Creates an AddVendorCommand to add the specified {@code Person} as a vendor @@ -66,12 +60,12 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); if (model.hasPerson(toAdd)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); + throw new CommandException(Messages.MESSAGE_DUPLICATE_PERSON); } model.addPerson(toAdd); model.assignVendor(toAdd); - return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd))); + return new CommandResult(String.format(Messages.MESSAGE_ADD_PERSON_SUCCESS, Messages.format(toAdd))); } @Override diff --git a/src/main/java/seedu/address/logic/commands/vendor/AssignVendorCommand.java b/src/main/java/seedu/address/logic/commands/vendor/AssignVendorCommand.java index a7115bfecaa..63c0b75a8ff 100644 --- a/src/main/java/seedu/address/logic/commands/vendor/AssignVendorCommand.java +++ b/src/main/java/seedu/address/logic/commands/vendor/AssignVendorCommand.java @@ -28,10 +28,6 @@ public class AssignVendorCommand extends Command { + "Parameters: INDEX (must be a positive integer) " + "Example: " + COMMAND_WORD + " 1 "; - public static final String MESSAGE_SUCCESS = "%1$s has been added as a vendor."; - - public static final String MESSAGE_DUPLICATE_VENDOR = "%1$s is already a vendor."; - private final Index targetIndex; @@ -59,12 +55,12 @@ public CommandResult execute(Model model) throws CommandException { // need to change to check if model already has vendor if (model.hasVendor(personToAssign)) { - throw new CommandException(String.format(MESSAGE_DUPLICATE_VENDOR, personToAssign.getName())); + throw new CommandException(String.format(Messages.MESSAGE_DUPLICATE_VENDOR, personToAssign.getName())); } model.assignVendor(personToAssign); assert model.hasVendor(personToAssign) : "Vendor was not assigned correctly"; - return new CommandResult(String.format(MESSAGE_SUCCESS, personToAssign.getName())); + return new CommandResult(String.format(Messages.MESSAGE_ADD_VENDOR_SUCCESS, personToAssign.getName())); } @Override diff --git a/src/main/java/seedu/address/logic/commands/vendor/UnassignVendorCommand.java b/src/main/java/seedu/address/logic/commands/vendor/UnassignVendorCommand.java index 73dbf45a291..bbe60a58529 100644 --- a/src/main/java/seedu/address/logic/commands/vendor/UnassignVendorCommand.java +++ b/src/main/java/seedu/address/logic/commands/vendor/UnassignVendorCommand.java @@ -29,11 +29,6 @@ public class UnassignVendorCommand extends Command { + "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 1"; - public static final String MESSAGE_SUCCESS = "%1$s has been unassigned and is no longer a vendor."; - - public static final String MESSAGE_UNASSIGN_VENDOR_FAILURE_TASK_EXISTS = "The Vendor: %1$s still has tasks" - + " assigned to them"; - public static final String MESSAGE_UNASSIGN_VENDOR_FAILURE_NOT_VENDOR = "%1$s is not a vendor."; private final Index targetIndex; private boolean force = false; @@ -72,7 +67,7 @@ public CommandResult execute(Model model) throws CommandException { // need to change to check if model has the vendor already existing if (!model.hasVendor(personToUnassign)) { - throw new CommandException(String.format(MESSAGE_UNASSIGN_VENDOR_FAILURE_NOT_VENDOR, + throw new CommandException(String.format(Messages.MESSAGE_UNASSIGN_VENDOR_FAILURE_NOT_VENDOR, personToUnassign.getName())); } @@ -80,7 +75,7 @@ public CommandResult execute(Model model) throws CommandException { if (this.force) { personToUnassign.clearTasks(); } else { - throw new CommandException(String.format(MESSAGE_UNASSIGN_VENDOR_FAILURE_TASK_EXISTS, + throw new CommandException(String.format(Messages.MESSAGE_UNASSIGN_VENDOR_FAILURE_TASK_EXISTS, personToUnassign.getName()) + ".\n" + Messages.MESSAGE_FORCE_UNASSIGN_VENDOR); @@ -90,7 +85,9 @@ public CommandResult execute(Model model) throws CommandException { model.unassignVendor(personToUnassign); assert !model.hasVendor(personToUnassign) : "Vendor was not unassigned correctly"; - return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(personToUnassign))); + return new CommandResult(String.format( + Messages.MESSAGE_UNASSIGN_TASK_SUCCESS, Messages.format(personToUnassign) + )); } @Override diff --git a/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java index 162a0c86031..65f99598f27 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java @@ -34,7 +34,7 @@ public void execute_newPerson_success() { expectedModel.addPerson(validPerson); assertCommandSuccess(new AddCommand(validPerson), model, - String.format(AddCommand.MESSAGE_SUCCESS, Messages.format(validPerson)), + String.format(Messages.MESSAGE_ADD_PERSON_SUCCESS, Messages.format(validPerson)), expectedModel); } @@ -42,7 +42,7 @@ public void execute_newPerson_success() { public void execute_duplicatePerson_throwsCommandException() { Person personInList = model.getAddressBook().getPersonList().get(0); assertCommandFailure(new AddCommand(personInList), model, - AddCommand.MESSAGE_DUPLICATE_PERSON); + Messages.MESSAGE_DUPLICATE_PERSON); } } diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 5bf719bfd45..cc45e903390 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -42,7 +42,7 @@ public void execute_personAcceptedByModel_addSuccessful() throws Exception { CommandResult commandResult = new AddCommand(validPerson).execute(modelStub); - assertEquals(String.format(AddCommand.MESSAGE_SUCCESS, Messages.format(validPerson)), + assertEquals(String.format(Messages.MESSAGE_ADD_PERSON_SUCCESS, Messages.format(validPerson)), commandResult.getFeedbackToUser()); assertEquals(Arrays.asList(validPerson), modelStub.personsAdded); } @@ -53,7 +53,7 @@ public void execute_duplicatePerson_throwsCommandException() { AddCommand addCommand = new AddCommand(validPerson); ModelStub modelStub = new ModelStubWithPerson(validPerson); - assertThrows(CommandException.class, AddCommand.MESSAGE_DUPLICATE_PERSON, () -> addCommand.execute(modelStub)); + assertThrows(CommandException.class, Messages.MESSAGE_DUPLICATE_PERSON, () -> addCommand.execute(modelStub)); } @Test diff --git a/src/test/java/seedu/address/logic/commands/task/AssignTaskCommandTest.java b/src/test/java/seedu/address/logic/commands/task/AssignTaskCommandTest.java index b30530d5b3d..85adc6713b0 100644 --- a/src/test/java/seedu/address/logic/commands/task/AssignTaskCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/task/AssignTaskCommandTest.java @@ -51,7 +51,7 @@ public void execute_validVendorAndTask_success() throws Exception { String addedTasks = taskToAssign.toString().replaceAll("[\\[\\]]", ""); String expectedMessage = String.format( - Messages.MESSAGE_ADD_TASK_SUCCESS, addedTasks, validPerson.getName() + Messages.MESSAGE_ASSIGN_TASK_SUCCESS, addedTasks, validPerson.getName() ); assertEquals(expectedMessage, result.getFeedbackToUser()); diff --git a/src/test/java/seedu/address/logic/commands/task/CreateTaskCommandTest.java b/src/test/java/seedu/address/logic/commands/task/CreateTaskCommandTest.java index 8a00eb36211..4747b162e0c 100644 --- a/src/test/java/seedu/address/logic/commands/task/CreateTaskCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/task/CreateTaskCommandTest.java @@ -43,7 +43,7 @@ public void execute_addValidTask_success() throws Exception { // Create a CreateTaskCommand with valid tasks CreateTaskCommand command = new CreateTaskCommand(tasksToAdd); - String expectedMessage = String.format(Messages.MESSAGE_SUCCESS, StringUtil.tasksString(tasksToAdd)); + String expectedMessage = String.format(Messages.MESSAGE_TASK_ADDED_SUCCESS, StringUtil.tasksString(tasksToAdd)); CommandResult result = command.execute(model); diff --git a/src/test/java/seedu/address/logic/commands/vendor/AddVendorCommandTest.java b/src/test/java/seedu/address/logic/commands/vendor/AddVendorCommandTest.java index 9ec24e7de66..5501bfa2596 100644 --- a/src/test/java/seedu/address/logic/commands/vendor/AddVendorCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/vendor/AddVendorCommandTest.java @@ -15,6 +15,7 @@ import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; +import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.AddressBook; import seedu.address.model.Model; @@ -42,7 +43,7 @@ public void execute_duplicatePerson_throwsCommandException() { AddVendorCommandTest.ModelStub modelStub = new AddVendorCommandTest.ModelStubWithPerson(validVendor); assertThrows(CommandException.class, - AddVendorCommand.MESSAGE_DUPLICATE_PERSON, () -> addVendorCommand.execute(modelStub)); + Messages.MESSAGE_DUPLICATE_PERSON, () -> addVendorCommand.execute(modelStub)); } @Test diff --git a/src/test/java/seedu/address/logic/commands/vendor/AssignVendorCommandTest.java b/src/test/java/seedu/address/logic/commands/vendor/AssignVendorCommandTest.java index 0cf577b70d2..1ea31baef77 100644 --- a/src/test/java/seedu/address/logic/commands/vendor/AssignVendorCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/vendor/AssignVendorCommandTest.java @@ -28,7 +28,7 @@ public void execute_validIndexUnfilteredList_success() { Person personToAssign = model.getFilteredPersonList().get(INDEX_FIRST.getZeroBased()); AssignVendorCommand assignVendorCommand = new AssignVendorCommand(INDEX_FIRST); - String expectedMessage = String.format(AssignVendorCommand.MESSAGE_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_ADD_VENDOR_SUCCESS, personToAssign.getName()); ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); @@ -52,7 +52,7 @@ public void execute_duplicateVendor_throwsCommandException() { AssignVendorCommand assignVendorCommand = new AssignVendorCommand(INDEX_FIRST); assertCommandFailure(assignVendorCommand, model, - String.format(AssignVendorCommand.MESSAGE_DUPLICATE_VENDOR, personToAssign.getName())); + String.format(Messages.MESSAGE_DUPLICATE_VENDOR, personToAssign.getName())); } @Test @@ -60,7 +60,7 @@ public void execute_validIndexFilteredList_success() { Person personToAssign = model.getFilteredPersonList().get(INDEX_FIRST.getZeroBased()); AssignVendorCommand assignVendorCommand = new AssignVendorCommand(INDEX_FIRST); - String expectedMessage = String.format(AssignVendorCommand.MESSAGE_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_ADD_VENDOR_SUCCESS, personToAssign.getName()); Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); From 742db12f63a50d283e1bbd1c0c97f57c9f6006d8 Mon Sep 17 00:00:00 2001 From: Han Bin Date: Fri, 8 Nov 2024 05:55:51 +0800 Subject: [PATCH 3/5] Refractor Message from Wedding Refractor message from Wedding. Fix formatting errors in messages. --- src/main/java/seedu/address/logic/Messages.java | 12 ++++++++++-- .../logic/commands/task/ListTasksCommand.java | 2 +- .../commands/vendor/UnassignVendorCommand.java | 2 +- .../commands/wedding/AssignWeddingCommand.java | 8 +++++--- .../commands/wedding/CreateWeddingCommand.java | 8 ++------ .../commands/wedding/DeleteWeddingCommand.java | 12 ++++-------- .../commands/wedding/EditWeddingCommand.java | 7 ++----- .../commands/wedding/ListWeddingsCommand.java | 5 ++--- .../parser/wedding/EditWeddingCommandParser.java | 3 ++- .../wedding/AssignWeddingCommandTest.java | 4 ++-- .../wedding/CreateWeddingCommandTest.java | 4 ++-- .../wedding/DeleteWeddingCommandTest.java | 4 ++-- .../commands/wedding/EditWeddingCommandTest.java | 16 ++++++++-------- .../wedding/EditWeddingCommandParserTest.java | 2 +- 14 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 175e7e5f494..c820ed9ca42 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -48,12 +48,20 @@ public class Messages { /** * Messages specific to Wedding */ - public static final String MESSAGE_ADD_WEDDING_SUCCESS = "Added wedding(s) %1$s to %2$s."; + public static final String MESSAGE_ASSIGN_WEDDING_SUCCESS = "Assigned wedding(s) %1$s to %2$s."; + public static final String MESSAGE_CREATE_WEDDING_SUCCESS = "New wedding created: %1$s"; + public static final String MESSAGE_DELETE_WEDDING_SUCCESS = "Deleted Wedding: %1$s"; + public static final String MESSAGE_DELETE_WEDDING_FAILURE_STILL_USED = "The Wedding: %1$s is still used"; + public static final String MESSAGE_DELETE_WEDDING_FAILURE_NOT_FOUND = "The Wedding: %1$s does not exist"; + public static final String MESSAGE_DUPLICATE_WEDDING = "This wedding already exists in the address book"; + public static final String MESSAGE_EDIT_WEDDING_SUCCESS = "Edited Wedding: %1$s"; + public static final String MESSAGE_WEDDING_NOT_EDITED = "At least one field to edit must be provided."; public static final String MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT = "Use f/ to force the assignment of wedding(s)." + " This will automatically help you create the wedding required."; public static final String MESSAGE_FORCE_DELETE_WEDDING = "Use f/ to force the deletion of wedding." + " This will unassign all people currently assigned to this Wedding."; public static final String MESSAGE_INVALID_WEDDING_DISPLAYED_INDEX = "The wedding index provided is invalid"; + public static final String MESSAGE_LIST_WEDDING_SUCCESS = "Listed all weddings"; public static final String MESSAGE_REMOVE_WEDDING_SUCCESS = "Removed wedding(s) %1$s from %2$s."; public static final String MESSAGE_WEDDING_NOT_FOUND = "One or more specified weddings do not exist in " + "the Wedlinker."; @@ -70,7 +78,7 @@ public class Messages { public static final String MESSAGE_INVALID_TASK_DISPLAYED_INDEX = "The task index provided (%d) is invalid. \n" + MESSAGE_ENTER_VALID_INDEX; public static final String MESSAGE_INVALID_DATE_FORMAT = "Invalid date format. Expected format: yyyy-MM-dd"; - public static final String MESSAGE_LIST_SUCCESS = "Listed all tasks"; + public static final String MESSAGE_LIST_TASK_SUCCESS = "Listed all tasks"; public static final String MESSAGE_MARK_TASK_SUCCESS = "Marked task: %1$s"; public static final String MESSAGE_ONLY_VENDOR_CAN_BE_ASSIGNED_TASK = "%1$s is not a Vendor, " + "tasks can only be assigned to vendors."; diff --git a/src/main/java/seedu/address/logic/commands/task/ListTasksCommand.java b/src/main/java/seedu/address/logic/commands/task/ListTasksCommand.java index 67145f949db..0b05e283b9f 100644 --- a/src/main/java/seedu/address/logic/commands/task/ListTasksCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/ListTasksCommand.java @@ -23,6 +23,6 @@ public class ListTasksCommand extends Command { public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS); - return new CommandResult(Messages.MESSAGE_LIST_SUCCESS, SwitchView.TASK); + return new CommandResult(Messages.MESSAGE_LIST_TASK_SUCCESS, SwitchView.TASK); } } diff --git a/src/main/java/seedu/address/logic/commands/vendor/UnassignVendorCommand.java b/src/main/java/seedu/address/logic/commands/vendor/UnassignVendorCommand.java index bbe60a58529..96957940105 100644 --- a/src/main/java/seedu/address/logic/commands/vendor/UnassignVendorCommand.java +++ b/src/main/java/seedu/address/logic/commands/vendor/UnassignVendorCommand.java @@ -86,7 +86,7 @@ public CommandResult execute(Model model) throws CommandException { assert !model.hasVendor(personToUnassign) : "Vendor was not unassigned correctly"; return new CommandResult(String.format( - Messages.MESSAGE_UNASSIGN_TASK_SUCCESS, Messages.format(personToUnassign) + Messages.MESSAGE_UNASSIGN_VENDOR_SUCCESS, Messages.format(personToUnassign) )); } diff --git a/src/main/java/seedu/address/logic/commands/wedding/AssignWeddingCommand.java b/src/main/java/seedu/address/logic/commands/wedding/AssignWeddingCommand.java index 1d948fecab0..a8f58a360e9 100644 --- a/src/main/java/seedu/address/logic/commands/wedding/AssignWeddingCommand.java +++ b/src/main/java/seedu/address/logic/commands/wedding/AssignWeddingCommand.java @@ -1,6 +1,6 @@ package seedu.address.logic.commands.wedding; -import static seedu.address.logic.Messages.MESSAGE_ADD_WEDDING_SUCCESS; +import static seedu.address.logic.Messages.MESSAGE_ASSIGN_WEDDING_SUCCESS; import static seedu.address.logic.Messages.MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT; import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; import static seedu.address.logic.Messages.MESSAGE_WEDDING_NOT_FOUND; @@ -65,7 +65,7 @@ private String generateSuccessMessage(Person personToEdit) { String addedWeddings = weddingsToAdd.keySet().stream() .map(wedding -> wedding.toString().replaceAll("[\\[\\]]", "")) .collect(Collectors.joining(", ")); - return String.format(MESSAGE_ADD_WEDDING_SUCCESS, addedWeddings, personToEdit.getName().toString()); + return String.format(MESSAGE_ASSIGN_WEDDING_SUCCESS, addedWeddings, personToEdit.getName().toString()); } @Override @@ -73,7 +73,9 @@ public CommandResult execute(Model model) throws CommandException { List lastShownList = model.getFilteredPersonList(); if (index.getZeroBased() >= lastShownList.size()) { - throw new CommandException(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException(String.format( + MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, 1, lastShownList.size() + 1 + )); } Person personToEdit = lastShownList.get(index.getZeroBased()); diff --git a/src/main/java/seedu/address/logic/commands/wedding/CreateWeddingCommand.java b/src/main/java/seedu/address/logic/commands/wedding/CreateWeddingCommand.java index 2a38312eba1..44665d16d15 100644 --- a/src/main/java/seedu/address/logic/commands/wedding/CreateWeddingCommand.java +++ b/src/main/java/seedu/address/logic/commands/wedding/CreateWeddingCommand.java @@ -27,10 +27,6 @@ public class CreateWeddingCommand extends Command { + "Example: " + COMMAND_WORD + " " + PREFIX_WEDDING + "Cheryl's Wedding"; - public static final String MESSAGE_SUCCESS = "New wedding added: %1$s"; - - public static final String MESSAGE_DUPLICATE_WEDDING = "This wedding already exists in the address book"; - private final Wedding weddingToAdd; /** @@ -47,11 +43,11 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); if (model.hasWedding(weddingToAdd)) { - throw new CommandException(MESSAGE_DUPLICATE_WEDDING); + throw new CommandException(Messages.MESSAGE_DUPLICATE_WEDDING); } model.addWedding(weddingToAdd); - return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(weddingToAdd))); + return new CommandResult(String.format(Messages.MESSAGE_CREATE_WEDDING_SUCCESS, Messages.format(weddingToAdd))); } @Override diff --git a/src/main/java/seedu/address/logic/commands/wedding/DeleteWeddingCommand.java b/src/main/java/seedu/address/logic/commands/wedding/DeleteWeddingCommand.java index 65b8c63c98c..1d9e54bbabf 100644 --- a/src/main/java/seedu/address/logic/commands/wedding/DeleteWeddingCommand.java +++ b/src/main/java/seedu/address/logic/commands/wedding/DeleteWeddingCommand.java @@ -29,10 +29,6 @@ public class DeleteWeddingCommand extends Command { + "Example: " + COMMAND_WORD + " " + PREFIX_WEDDING + " Timothy's Wedding"; - public static final String MESSAGE_DELETE_WEDDING_SUCCESS = "Deleted Wedding: %1$s"; - public static final String MESSAGE_DELETE_WEDDING_FAILURE_STILL_USED = "The Wedding: %1$s is still used"; - public static final String MESSAGE_DELETE_WEDDING_FAILURE_NOT_FOUND = "The Wedding: %1$s does not exist"; - private final Wedding targetWedding; private boolean force = false; @@ -63,7 +59,7 @@ public CommandResult execute(Model model) throws CommandException { if (wedding.getWeddingName().equals(targetWedding.getWeddingName())) { if (wedding.canBeDeleted()) { model.deleteWedding(wedding); - return new CommandResult(String.format(MESSAGE_DELETE_WEDDING_SUCCESS, + return new CommandResult(String.format(Messages.MESSAGE_DELETE_WEDDING_SUCCESS, Messages.format(targetWedding))); } else { if (this.force) { @@ -85,11 +81,11 @@ public CommandResult execute(Model model) throws CommandException { } } model.deleteWedding(wedding); - return new CommandResult(String.format(MESSAGE_DELETE_WEDDING_SUCCESS, + return new CommandResult(String.format(Messages.MESSAGE_DELETE_WEDDING_SUCCESS, Messages.format(targetWedding))); } else { throw new CommandException( - String.format(MESSAGE_DELETE_WEDDING_FAILURE_STILL_USED, + String.format(Messages.MESSAGE_DELETE_WEDDING_FAILURE_STILL_USED, Messages.format(targetWedding)) + ".\n" + Messages.MESSAGE_FORCE_DELETE_WEDDING @@ -99,7 +95,7 @@ public CommandResult execute(Model model) throws CommandException { } } model.updateFilteredWeddingList(Model.PREDICATE_SHOW_ALL_WEDDINGS); - throw new CommandException(String.format(MESSAGE_DELETE_WEDDING_FAILURE_NOT_FOUND, + throw new CommandException(String.format(Messages.MESSAGE_DELETE_WEDDING_FAILURE_NOT_FOUND, Messages.format(targetWedding))); } diff --git a/src/main/java/seedu/address/logic/commands/wedding/EditWeddingCommand.java b/src/main/java/seedu/address/logic/commands/wedding/EditWeddingCommand.java index d3229baa4f0..c39c7912b47 100644 --- a/src/main/java/seedu/address/logic/commands/wedding/EditWeddingCommand.java +++ b/src/main/java/seedu/address/logic/commands/wedding/EditWeddingCommand.java @@ -45,9 +45,6 @@ public class EditWeddingCommand extends Command { + PREFIX_WEDDING + "Mr and Mrs John Tan " + PREFIX_ADDRESS + "12 College Ave West"; - public static final String MESSAGE_EDIT_WEDDING_SUCCESS = "Edited Wedding: %1$s"; - public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; - public static final String MESSAGE_DUPLICATE_WEDDING = "This wedding already exists in the address book."; private final Index index; private final EditWeddingDescriptor editWeddingDescriptor; @@ -81,12 +78,12 @@ public CommandResult execute(Model model) throws CommandException { Wedding editedWedding = createEditedWedding(weddingToEdit, editWeddingDescriptor); if (!weddingToEdit.isSameWedding(editedWedding) && model.hasWedding(editedWedding)) { - throw new CommandException(MESSAGE_DUPLICATE_WEDDING); + throw new CommandException(Messages.MESSAGE_DUPLICATE_WEDDING); } model.setWedding(weddingToEdit, editedWedding); model.updateFilteredWeddingList(PREDICATE_SHOW_ALL_WEDDINGS); - return new CommandResult(String.format(MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding))); + return new CommandResult(String.format(Messages.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding))); } /** diff --git a/src/main/java/seedu/address/logic/commands/wedding/ListWeddingsCommand.java b/src/main/java/seedu/address/logic/commands/wedding/ListWeddingsCommand.java index f0367d970d2..f9d29c6a293 100644 --- a/src/main/java/seedu/address/logic/commands/wedding/ListWeddingsCommand.java +++ b/src/main/java/seedu/address/logic/commands/wedding/ListWeddingsCommand.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_WEDDINGS; +import seedu.address.logic.Messages; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.CommandResult.SwitchView; @@ -16,12 +17,10 @@ public class ListWeddingsCommand extends Command { public static final String COMMAND_WORD = "list-weddings"; public static final String COMMAND_KEYWORD = "lw"; - public static final String MESSAGE_SUCCESS = "Listed all weddings"; - @Override public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredWeddingList(PREDICATE_SHOW_ALL_WEDDINGS); - return new CommandResult(MESSAGE_SUCCESS, SwitchView.WEDDING); + return new CommandResult(Messages.MESSAGE_LIST_WEDDING_SUCCESS, SwitchView.WEDDING); } } diff --git a/src/main/java/seedu/address/logic/parser/wedding/EditWeddingCommandParser.java b/src/main/java/seedu/address/logic/parser/wedding/EditWeddingCommandParser.java index 9ed0a281487..bde1e5af8c9 100644 --- a/src/main/java/seedu/address/logic/parser/wedding/EditWeddingCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/wedding/EditWeddingCommandParser.java @@ -7,6 +7,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_WEDDING; import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; import seedu.address.logic.commands.wedding.EditWeddingCommand; import seedu.address.logic.commands.wedding.EditWeddingCommand.EditWeddingDescriptor; import seedu.address.logic.parser.ArgumentMultimap; @@ -66,7 +67,7 @@ public EditWeddingCommand parse(String args) throws ParseException { } //if no edits, throw error if (!editWeddingDescriptor.isAnyFieldEdited()) { - throw new ParseException(EditWeddingCommand.MESSAGE_NOT_EDITED); + throw new ParseException(Messages.MESSAGE_WEDDING_NOT_EDITED); } return new EditWeddingCommand(index, editWeddingDescriptor); } diff --git a/src/test/java/seedu/address/logic/commands/wedding/AssignWeddingCommandTest.java b/src/test/java/seedu/address/logic/commands/wedding/AssignWeddingCommandTest.java index bf78d52a3b1..ffd98f90eb7 100644 --- a/src/test/java/seedu/address/logic/commands/wedding/AssignWeddingCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/wedding/AssignWeddingCommandTest.java @@ -37,7 +37,7 @@ public void assignWedding_success() { AssignWeddingCommand assignWeddingCommand = new AssignWeddingCommand( INDEX_FIRST, weddingsToAdd, false); - String expectedMessage = String.format(Messages.MESSAGE_ADD_WEDDING_SUCCESS, "Amy's Wedding", + String expectedMessage = String.format(Messages.MESSAGE_ASSIGN_WEDDING_SUCCESS, "Amy's Wedding", personToEdit.getName().toString()); Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); @@ -121,7 +121,7 @@ public void forceAssignWedding_success() { .map(wedding -> wedding.toString().replaceAll("[\\[\\]]", "")) .collect(Collectors.joining(", ")); String expectedMessage = String.format( - Messages.MESSAGE_ADD_WEDDING_SUCCESS, + Messages.MESSAGE_ASSIGN_WEDDING_SUCCESS, addedWeddings, personToEdit.getName().toString()); CommandTestUtil.assertCommandSuccess(assignWeddingCommand, model, expectedMessage, model); diff --git a/src/test/java/seedu/address/logic/commands/wedding/CreateWeddingCommandTest.java b/src/test/java/seedu/address/logic/commands/wedding/CreateWeddingCommandTest.java index e5caad1e001..95086b38abc 100644 --- a/src/test/java/seedu/address/logic/commands/wedding/CreateWeddingCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/wedding/CreateWeddingCommandTest.java @@ -41,7 +41,7 @@ public void execute_weddingAcceptedByModel_addSuccessful() throws Exception { Wedding validWedding = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); CommandResult commandResult = new CreateWeddingCommand(validWedding).execute(modelStub); - assertEquals(String.format(CreateWeddingCommand.MESSAGE_SUCCESS, Messages.format(validWedding)), + assertEquals(String.format(Messages.MESSAGE_CREATE_WEDDING_SUCCESS, Messages.format(validWedding)), commandResult.getFeedbackToUser()); assertEquals(Arrays.asList(validWedding), modelStub.weddingsAdded); } @@ -53,7 +53,7 @@ public void execute_duplicateWedding_throwsCommandException() { ModelStub modelStub = new ModelStubWithWedding(validWedding); assertThrows(CommandException.class, - CreateWeddingCommand.MESSAGE_DUPLICATE_WEDDING, () -> createWeddingCommand.execute(modelStub)); + Messages.MESSAGE_DUPLICATE_WEDDING, () -> createWeddingCommand.execute(modelStub)); } @Test diff --git a/src/test/java/seedu/address/logic/commands/wedding/DeleteWeddingCommandTest.java b/src/test/java/seedu/address/logic/commands/wedding/DeleteWeddingCommandTest.java index 175cc019148..795cfe313a8 100644 --- a/src/test/java/seedu/address/logic/commands/wedding/DeleteWeddingCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/wedding/DeleteWeddingCommandTest.java @@ -28,7 +28,7 @@ public void execute_validDeleteWeddingCommand() { Wedding weddingToDelete = model.getFilteredWeddingList().get(2); DeleteWeddingCommand deleteWeddingCommand = new DeleteWeddingCommand(weddingToDelete, true); - String expectedMessage = String.format(DeleteWeddingCommand.MESSAGE_DELETE_WEDDING_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_DELETE_WEDDING_SUCCESS, Messages.format(weddingToDelete)); ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); @@ -59,7 +59,7 @@ public void execute_validDeleteWeddingCommand() { public void execute_invalidNotFoundDeleteWeddingCommand() { Wedding weddingToDelete = model.getFilteredWeddingList().get(0); - String expectedMessage = String.format(DeleteWeddingCommand.MESSAGE_DELETE_WEDDING_FAILURE_NOT_FOUND, + String expectedMessage = String.format(Messages.MESSAGE_DELETE_WEDDING_FAILURE_NOT_FOUND, Messages.format(weddingToDelete)); ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); diff --git a/src/test/java/seedu/address/logic/commands/wedding/EditWeddingCommandTest.java b/src/test/java/seedu/address/logic/commands/wedding/EditWeddingCommandTest.java index 48929f1e40a..8211cbed04e 100644 --- a/src/test/java/seedu/address/logic/commands/wedding/EditWeddingCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/wedding/EditWeddingCommandTest.java @@ -43,7 +43,7 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() { EditWeddingCommand editCommand = new EditWeddingCommand(INDEX_FIRST, descriptor); String expectedMessage = String.format( - EditWeddingCommand.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); + Messages.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setWedding(model.getFilteredWeddingList().get(0), editedWedding); @@ -68,7 +68,7 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { EditWeddingCommand editCommand = new EditWeddingCommand(indexLast, descriptor); String expectedMessage = String.format( - EditWeddingCommand.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); + Messages.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setWedding(lastWedding, editedWedding); @@ -82,7 +82,7 @@ public void execute_noFieldSpecifiedUnfilteredList_success() { Wedding editedWedding = model.getFilteredWeddingList().get(INDEX_FIRST.getZeroBased()); String expectedMessage = String.format( - EditWeddingCommand.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); + Messages.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); @@ -99,7 +99,7 @@ public void execute_filteredList_success() { new EditWeddingDescriptorBuilder().withName(VALID_WEDDING_CLIVE).build()); String expectedMessage = String.format( - EditWeddingCommand.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); + Messages.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setWedding(model.getFilteredWeddingList().get(0), editedWedding); @@ -113,7 +113,7 @@ public void execute_duplicateWeddingUnfilteredList_failure() { EditWeddingDescriptor descriptor = new EditWeddingDescriptorBuilder(firstWedding).build(); EditWeddingCommand editCommand = new EditWeddingCommand(INDEX_SECOND, descriptor); - assertCommandFailure(editCommand, model, EditWeddingCommand.MESSAGE_DUPLICATE_WEDDING); + assertCommandFailure(editCommand, model, Messages.MESSAGE_DUPLICATE_WEDDING); } @Test @@ -125,7 +125,7 @@ public void execute_duplicateWeddingFilteredList_failure() { EditWeddingCommand editCommand = new EditWeddingCommand(INDEX_FIRST, new EditWeddingDescriptorBuilder(weddingInList).build()); - assertCommandFailure(editCommand, model, EditWeddingCommand.MESSAGE_DUPLICATE_WEDDING); + assertCommandFailure(editCommand, model, Messages.MESSAGE_DUPLICATE_WEDDING); } @Test @@ -165,7 +165,7 @@ public void execute_addressOnlySpecifiedUnfilteredList_success() { EditWeddingCommand editCommand = new EditWeddingCommand(INDEX_SECOND, descriptor); String expectedMessage = String.format( - EditWeddingCommand.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); + Messages.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setWedding(lastWedding, editedWedding); @@ -184,7 +184,7 @@ public void execute_nameOnlySpecifiedUnfilteredList_success() { EditWeddingCommand editCommand = new EditWeddingCommand(INDEX_FIRST, descriptor); String expectedMessage = String.format( - EditWeddingCommand.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); + Messages.MESSAGE_EDIT_WEDDING_SUCCESS, Messages.format(editedWedding)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setWedding(lastWedding, editedWedding); diff --git a/src/test/java/seedu/address/logic/parser/wedding/EditWeddingCommandParserTest.java b/src/test/java/seedu/address/logic/parser/wedding/EditWeddingCommandParserTest.java index 21b0d971d00..eca6dc77b96 100644 --- a/src/test/java/seedu/address/logic/parser/wedding/EditWeddingCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/wedding/EditWeddingCommandParserTest.java @@ -33,7 +33,7 @@ public void parse_missingParts_failure() { assertParseFailure(parser, VALID_WEDDING_AMY, MESSAGE_INVALID_FORMAT); // no field specified - assertParseFailure(parser, "1", EditWeddingCommand.MESSAGE_NOT_EDITED); + assertParseFailure(parser, "1", Messages.MESSAGE_WEDDING_NOT_EDITED); // no index and no field specified assertParseFailure(parser, "", MESSAGE_INVALID_FORMAT); From 6516c58fc14e7b8258c88d74015ca0a055993f62 Mon Sep 17 00:00:00 2001 From: Han Bin Date: Fri, 8 Nov 2024 06:16:19 +0800 Subject: [PATCH 4/5] Refractor Message from Person and Tag Refractor Messages from Person and Tag. Fix bugs for certain messages with wrong formatting. --- .../java/seedu/address/logic/Messages.java | 25 ++++++++++++++++--- .../address/logic/commands/ClearCommand.java | 5 ++-- .../logic/commands/CreateTagCommand.java | 7 ++---- .../address/logic/commands/DeleteCommand.java | 6 ++--- .../logic/commands/DeleteTagCommand.java | 19 ++++++++------ .../address/logic/commands/EditCommand.java | 8 ++---- .../address/logic/commands/ExitCommand.java | 5 ++-- .../address/logic/commands/HelpCommand.java | 5 ++-- .../address/logic/commands/ListCommand.java | 6 ++--- .../logic/commands/ListTagsCommand.java | 5 ++-- .../address/logic/commands/TagCommand.java | 15 ++++++----- .../address/logic/commands/UntagCommand.java | 17 +++++++------ .../logic/parser/EditCommandParser.java | 8 +++--- .../seedu/address/logic/LogicManagerTest.java | 2 +- .../logic/commands/ClearCommandTest.java | 5 ++-- .../logic/commands/CreateTagCommandTest.java | 4 +-- .../logic/commands/DeleteCommandTest.java | 4 +-- .../logic/commands/DeleteTagCommandTest.java | 8 +++--- .../logic/commands/EditCommandTest.java | 12 ++++----- .../logic/commands/ExitCommandTest.java | 4 +-- .../logic/commands/HelpCommandTest.java | 4 +-- .../logic/commands/TagCommandTest.java | 6 ++--- .../logic/commands/UntagCommandTest.java | 4 +-- .../logic/parser/EditCommandParserTest.java | 12 +++------ 24 files changed, 103 insertions(+), 93 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index c820ed9ca42..27c2b3c32d2 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -5,6 +5,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import seedu.address.logic.commands.EditCommand; import seedu.address.logic.parser.Prefix; import seedu.address.model.person.Person; import seedu.address.model.tag.Tag; @@ -19,30 +20,46 @@ public class Messages { /** * General Messages */ + public static final String MESSAGE_CLEAR_SUCCESS = "Address book has been cleared!"; public static final String MESSAGE_ENTER_VALID_INDEX = "Please enter a valid index from %d to %d."; public static final String MESSAGE_DUPLICATE_FIELDS = "Multiple values specified for the following single-valued field(s): "; + public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ..."; + public static final String SHOWING_HELP_MESSAGE = "Opened help window."; public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; public static final String MESSAGE_NOTHING_TO_PERFORM_ON = "There are no %s to %s."; public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command"; /** - * Messages specific to People + * Messages specific to Person */ + public static final String MESSAGE_ADD_PERSON_SUCCESS = "New person added: %1$s"; + public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; + public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; + public static final String MESSAGE_INVALID_EDIT_PERSON_FORMAT = + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE); + public static final String MESSAGE_LIST_PERSON_SUCCESS = "Listed all persons"; public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid. \n" + MESSAGE_ENTER_VALID_INDEX; - public static final String MESSAGE_ADD_PERSON_SUCCESS = "New person added: %1$s"; + public static final String MESSAGE_PERSON_NOT_EDITED = "At least one field to edit must be provided."; + /** * Messages specific to Tag */ - public static final String MESSAGE_ADD_TAG_SUCCESS = "Added tag(s) %1$s to %2$s."; + public static final String MESSAGE_ASSIGN_TAG_SUCCESS = "Added tag(s) %1$s to %2$s."; + public static final String MESSAGE_CREATE_TAG_SUCCESS = "New tag added: %1$s"; + public static final String MESSAGE_DELETE_TAG_SUCCESS = "Deleted Tag: %1$s."; + public static final String MESSAGE_DELETE_TAG_FAILURE_STILL_TAGGED = "The Tag: %1$s is still used."; + public static final String MESSAGE_DELETE_TAG_FAILURE_NOT_FOUND = "The Tag: %1$s does not exist."; + public static final String MESSAGE_DUPLICATE_TAG = "This tag already exists in the address book"; public static final String MESSAGE_FORCE_TAG_TO_CONTACT = "Use f/ to force the tagging of contacts." + " This will create the require Tags."; public static final String MESSAGE_FORCE_DELETE_TAG = "Use f/ to force the deletion of tags." + " This will unassign all people currently with the Tag."; - + public static final String MESSAGE_LIST_TAG_SUCCESS = "Listed all tags"; + public static final String MESSAGE_REMOVE_TAG_SUCCESS = "Removed tag(s) %1$s from %2$s."; public static final String MESSAGE_TAG_NOT_FOUND = "One or more specified tags do not exist in the Wedlinker."; public static final String MESSAGE_TAG_NOT_FOUND_IN_CONTACT = "Some tags were not found in the person's tag list."; /** diff --git a/src/main/java/seedu/address/logic/commands/ClearCommand.java b/src/main/java/seedu/address/logic/commands/ClearCommand.java index 9c86b1fa6e4..abf5b3bf012 100644 --- a/src/main/java/seedu/address/logic/commands/ClearCommand.java +++ b/src/main/java/seedu/address/logic/commands/ClearCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import seedu.address.logic.Messages; import seedu.address.model.AddressBook; import seedu.address.model.Model; @@ -11,13 +12,11 @@ public class ClearCommand extends Command { public static final String COMMAND_WORD = "clear"; - public static final String MESSAGE_SUCCESS = "Address book has been cleared!"; - @Override public CommandResult execute(Model model) { requireNonNull(model); model.setAddressBook(new AddressBook()); - return new CommandResult(MESSAGE_SUCCESS); + return new CommandResult(Messages.MESSAGE_CLEAR_SUCCESS); } } diff --git a/src/main/java/seedu/address/logic/commands/CreateTagCommand.java b/src/main/java/seedu/address/logic/commands/CreateTagCommand.java index e923abc0f69..c4186c96378 100644 --- a/src/main/java/seedu/address/logic/commands/CreateTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/CreateTagCommand.java @@ -23,9 +23,6 @@ public class CreateTagCommand extends Command { + PREFIX_TAG + "TAG\n" + "Example: " + COMMAND_WORD + " " + PREFIX_TAG + "florist"; - public static final String MESSAGE_SUCCESS = "New tag added: %1$s"; - public static final String MESSAGE_DUPLICATE_TAG = "This tag already exists in the address book"; - private final Tag toAdd; /** @@ -41,11 +38,11 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); if (model.hasTag(toAdd)) { - throw new CommandException(MESSAGE_DUPLICATE_TAG); + throw new CommandException(Messages.MESSAGE_DUPLICATE_TAG); } model.addTag(toAdd); - return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd))); + return new CommandResult(String.format(Messages.MESSAGE_CREATE_TAG_SUCCESS, Messages.format(toAdd))); } @Override diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 2d773fac928..cd00df85447 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -23,8 +23,6 @@ public class DeleteCommand extends Command { + "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 1"; - public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; - private final Index targetIndex; public DeleteCommand(Index targetIndex) { @@ -45,7 +43,9 @@ public CommandResult execute(Model model) throws CommandException { Person personToDelete = lastShownList.get(targetIndex.getZeroBased()); model.deletePerson(personToDelete); - return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete))); + return new CommandResult(String.format( + Messages.MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete) + )); } @Override diff --git a/src/main/java/seedu/address/logic/commands/DeleteTagCommand.java b/src/main/java/seedu/address/logic/commands/DeleteTagCommand.java index a84f0f68036..4f90e07e8b1 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteTagCommand.java @@ -26,10 +26,6 @@ public class DeleteTagCommand extends Command { + "Parameters: " + PREFIX_TAG + "TAG (must exist in the AddressBook)\n" + "Example: " + COMMAND_WORD + " " + PREFIX_TAG + "florist"; - public static final String MESSAGE_DELETE_TAG_SUCCESS = "Deleted Tag: %1$s."; - public static final String MESSAGE_DELETE_TAG_FAILURE_STILL_TAGGED = "The Tag: %1$s is still used."; - public static final String MESSAGE_DELETE_TAG_FAILURE_NOT_FOUND = "The Tag: %1$s does not exist."; - private final Tag targetTag; private boolean force = false; @@ -60,7 +56,9 @@ public CommandResult execute(Model model) throws CommandException { if (tag.getTagName().equals(targetTag.getTagName())) { if (tag.canBeDeleted()) { model.deleteTag(tag); - return new CommandResult(String.format(MESSAGE_DELETE_TAG_SUCCESS, Messages.format(targetTag))); + return new CommandResult(String.format( + Messages.MESSAGE_DELETE_TAG_SUCCESS, Messages.format(targetTag) + )); } else { if (this.force) { for (Person person : model.getFilteredPersonList()) { @@ -81,10 +79,13 @@ public CommandResult execute(Model model) throws CommandException { } } model.deleteTag(tag); - return new CommandResult(String.format(MESSAGE_DELETE_TAG_SUCCESS, Messages.format(targetTag))); + return new CommandResult(String.format( + Messages.MESSAGE_DELETE_TAG_SUCCESS, Messages.format(targetTag) + )); } else { throw new CommandException( - String.format(MESSAGE_DELETE_TAG_FAILURE_STILL_TAGGED, Messages.format(targetTag)) + String.format( + Messages.MESSAGE_DELETE_TAG_FAILURE_STILL_TAGGED, Messages.format(targetTag)) + "\n" + Messages.MESSAGE_FORCE_DELETE_TAG); } @@ -92,7 +93,9 @@ public CommandResult execute(Model model) throws CommandException { } } model.updateFilteredTagList(Model.PREDICATE_SHOW_ALL_TAGS); - throw new CommandException(String.format(MESSAGE_DELETE_TAG_FAILURE_NOT_FOUND, Messages.format(targetTag))); + throw new CommandException(String.format( + Messages.MESSAGE_DELETE_TAG_FAILURE_NOT_FOUND, Messages.format(targetTag) + )); } @Override diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index a2d043a10ad..01bd0281b78 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -53,10 +53,6 @@ public class EditCommand extends Command { + PREFIX_PHONE + "91234567 " + PREFIX_EMAIL + "johndoe@example.com"; - public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; - public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; - public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; - private final Index index; private final EditPersonDescriptor editPersonDescriptor; @@ -101,12 +97,12 @@ public CommandResult execute(Model model) throws CommandException { Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); + throw new CommandException(Messages.MESSAGE_DUPLICATE_PERSON); } model.setPerson(personToEdit, editedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); + return new CommandResult(String.format(Messages.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); } private Person getPerson(Model model) throws CommandException { diff --git a/src/main/java/seedu/address/logic/commands/ExitCommand.java b/src/main/java/seedu/address/logic/commands/ExitCommand.java index 3dd85a8ba90..14ec8e85567 100644 --- a/src/main/java/seedu/address/logic/commands/ExitCommand.java +++ b/src/main/java/seedu/address/logic/commands/ExitCommand.java @@ -1,5 +1,6 @@ package seedu.address.logic.commands; +import seedu.address.logic.Messages; import seedu.address.model.Model; /** @@ -9,11 +10,9 @@ public class ExitCommand extends Command { public static final String COMMAND_WORD = "exit"; - public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ..."; - @Override public CommandResult execute(Model model) { - return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true); + return new CommandResult(Messages.MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true); } } diff --git a/src/main/java/seedu/address/logic/commands/HelpCommand.java b/src/main/java/seedu/address/logic/commands/HelpCommand.java index bf824f91bd0..7ae8fa46f43 100644 --- a/src/main/java/seedu/address/logic/commands/HelpCommand.java +++ b/src/main/java/seedu/address/logic/commands/HelpCommand.java @@ -1,5 +1,6 @@ package seedu.address.logic.commands; +import seedu.address.logic.Messages; import seedu.address.model.Model; /** @@ -12,10 +13,8 @@ public class HelpCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows program usage instructions.\n" + "Example: " + COMMAND_WORD; - public static final String SHOWING_HELP_MESSAGE = "Opened help window."; - @Override public CommandResult execute(Model model) { - return new CommandResult(SHOWING_HELP_MESSAGE, true, false); + return new CommandResult(Messages.SHOWING_HELP_MESSAGE, true, false); } } diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index 84be6ad2596..019f12a4a7a 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import seedu.address.logic.Messages; import seedu.address.model.Model; /** @@ -12,13 +13,10 @@ public class ListCommand extends Command { public static final String COMMAND_WORD = "list"; - public static final String MESSAGE_SUCCESS = "Listed all persons"; - - @Override public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(MESSAGE_SUCCESS); + return new CommandResult(Messages.MESSAGE_LIST_PERSON_SUCCESS); } } diff --git a/src/main/java/seedu/address/logic/commands/ListTagsCommand.java b/src/main/java/seedu/address/logic/commands/ListTagsCommand.java index 34fcc8424da..596786501e5 100644 --- a/src/main/java/seedu/address/logic/commands/ListTagsCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListTagsCommand.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_TAGS; +import seedu.address.logic.Messages; import seedu.address.logic.commands.CommandResult.SwitchView; import seedu.address.model.Model; @@ -16,12 +17,10 @@ public class ListTagsCommand extends Command { public static final String COMMAND_KEYWORD = "ltags"; - public static final String MESSAGE_SUCCESS = "Listed all tags"; - @Override public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredTagList(PREDICATE_SHOW_ALL_TAGS); - return new CommandResult(MESSAGE_SUCCESS, SwitchView.TAG); + return new CommandResult(Messages.MESSAGE_LIST_TAG_SUCCESS, SwitchView.TAG); } } diff --git a/src/main/java/seedu/address/logic/commands/TagCommand.java b/src/main/java/seedu/address/logic/commands/TagCommand.java index 8242e585a61..8ab07bc3adf 100644 --- a/src/main/java/seedu/address/logic/commands/TagCommand.java +++ b/src/main/java/seedu/address/logic/commands/TagCommand.java @@ -1,9 +1,6 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.address.logic.Messages.MESSAGE_ADD_TAG_SUCCESS; -import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; -import static seedu.address.logic.Messages.MESSAGE_TAG_NOT_FOUND; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import java.util.HashSet; @@ -75,7 +72,9 @@ private String generateSuccessMessage(Person personToEdit) { String addedTags = tagsToAdd.stream() .map(tag -> tag.toString().replaceAll("[\\[\\]]", "")) .collect(Collectors.joining(", ")); - return String.format(MESSAGE_ADD_TAG_SUCCESS, addedTags, personToEdit.getName().toString()); + return String.format( + Messages.MESSAGE_ASSIGN_TAG_SUCCESS, addedTags, personToEdit.getName().toString() + ); } @Override @@ -85,7 +84,9 @@ public CommandResult execute(Model model) throws CommandException { if (lastShownList.isEmpty()) { throw new CommandException(String.format(Messages.MESSAGE_NOTHING_TO_PERFORM_ON, "contacts", COMMAND_WORD)); } else if (index.getZeroBased() >= lastShownList.size() || index.getZeroBased() < 0) { - throw new CommandException(String.format(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, 1, lastShownList.size())); + throw new CommandException(String.format( + Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, 1, lastShownList.size() + )); } Person personToEdit = lastShownList.get(index.getZeroBased()); @@ -99,7 +100,9 @@ public CommandResult execute(Model model) throws CommandException { tag.increaseTaggedCount(); updatedTags.add(tag); } else { - throw new CommandException(MESSAGE_TAG_NOT_FOUND + "\n" + Messages.MESSAGE_FORCE_TAG_TO_CONTACT); + throw new CommandException( + Messages.MESSAGE_TAG_NOT_FOUND + "\n" + Messages.MESSAGE_FORCE_TAG_TO_CONTACT + ); } } else { Tag tagToEdit = model.getTag(tag); diff --git a/src/main/java/seedu/address/logic/commands/UntagCommand.java b/src/main/java/seedu/address/logic/commands/UntagCommand.java index 3ae57f661a6..1833eeec692 100644 --- a/src/main/java/seedu/address/logic/commands/UntagCommand.java +++ b/src/main/java/seedu/address/logic/commands/UntagCommand.java @@ -1,8 +1,6 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; -import static seedu.address.logic.Messages.MESSAGE_TAG_NOT_FOUND_IN_CONTACT; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import java.util.HashSet; @@ -23,7 +21,6 @@ public class UntagCommand extends Command { public static final String COMMAND_WORD = "untag"; - public static final String MESSAGE_REMOVE_TAG_SUCCESS = "Removed tag(s) %1$s from %2$s."; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Removes one or multiple tags from the person identified " @@ -59,7 +56,9 @@ private String generateSuccessMessage(Person personToEdit) { String removedTags = tagsToRemove.stream() .map(tag -> tag.toString().replaceAll("[\\[\\]]", "")) .collect(Collectors.joining(", ")); - return String.format(MESSAGE_REMOVE_TAG_SUCCESS, removedTags, personToEdit.getName().toString()); + return String.format( + Messages.MESSAGE_REMOVE_TAG_SUCCESS, removedTags, personToEdit.getName().toString() + ); } @Override @@ -69,22 +68,24 @@ public CommandResult execute(Model model) throws CommandException { if (lastShownList.isEmpty()) { throw new CommandException(String.format(Messages.MESSAGE_NOTHING_TO_PERFORM_ON, "contacts", COMMAND_WORD)); } else if (index.getZeroBased() >= lastShownList.size() || index.getZeroBased() < 0) { - throw new CommandException(String.format(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, 1, lastShownList.size())); + throw new CommandException(String.format( + Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, 1, lastShownList.size() + )); } Person personToEdit = lastShownList.get(index.getZeroBased()); Set updatedTags = new HashSet<>(personToEdit.getTags()); if (personToEdit.getTags().isEmpty()) { - throw new CommandException(MESSAGE_TAG_NOT_FOUND_IN_CONTACT); + throw new CommandException(Messages.MESSAGE_TAG_NOT_FOUND_IN_CONTACT); } if (tagsToRemove.isEmpty()) { - throw new CommandException(MESSAGE_TAG_NOT_FOUND_IN_CONTACT); + throw new CommandException(Messages.MESSAGE_TAG_NOT_FOUND_IN_CONTACT); } if (!updatedTags.containsAll(tagsToRemove)) { - throw new CommandException(MESSAGE_TAG_NOT_FOUND_IN_CONTACT); + throw new CommandException(Messages.MESSAGE_TAG_NOT_FOUND_IN_CONTACT); } for (Tag tag : updatedTags) { diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index f00b1684292..2a73ee5fba7 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -1,7 +1,6 @@ package seedu.address.logic.parser; import static java.util.Objects.requireNonNull; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; @@ -15,6 +14,7 @@ import java.util.Set; import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; import seedu.address.logic.parser.exceptions.ParseException; @@ -42,7 +42,9 @@ public EditCommand parse(String args) throws ParseException { try { index = Index.oneBasedNoConstraints(Integer.parseInt(argMultimap.getPreamble().trim())); } catch (NumberFormatException pe) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); + throw new ParseException(String.format( + Messages.MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe + ); } argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS); @@ -67,7 +69,7 @@ public EditCommand parse(String args) throws ParseException { parseWeddingsForEdit(argMultimap.getAllValues(PREFIX_WEDDING)).ifPresent(editPersonDescriptor::setWeddings); if (!editPersonDescriptor.isAnyFieldEdited()) { - throw new ParseException(EditCommand.MESSAGE_NOT_EDITED); + throw new ParseException(Messages.MESSAGE_PERSON_NOT_EDITED); } return new EditCommand(index, editPersonDescriptor); diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index f50845c5979..fa329508f6b 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -66,7 +66,7 @@ public void execute_commandExecutionError_throwsCommandException() { @Test public void execute_validCommand_success() throws Exception { String listCommand = ListCommand.COMMAND_WORD; - assertCommandSuccess(listCommand, ListCommand.MESSAGE_SUCCESS, model); + assertCommandSuccess(listCommand, Messages.MESSAGE_LIST_PERSON_SUCCESS, model); } @Test diff --git a/src/test/java/seedu/address/logic/commands/ClearCommandTest.java b/src/test/java/seedu/address/logic/commands/ClearCommandTest.java index 80d9110c03a..77a18849b1a 100644 --- a/src/test/java/seedu/address/logic/commands/ClearCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ClearCommandTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; import seedu.address.model.AddressBook; import seedu.address.model.Model; import seedu.address.model.ModelManager; @@ -17,7 +18,7 @@ public void execute_emptyAddressBook_success() { Model model = new ModelManager(); Model expectedModel = new ModelManager(); - assertCommandSuccess(new ClearCommand(), model, ClearCommand.MESSAGE_SUCCESS, expectedModel); + assertCommandSuccess(new ClearCommand(), model, Messages.MESSAGE_CLEAR_SUCCESS, expectedModel); } @Test @@ -26,7 +27,7 @@ public void execute_nonEmptyAddressBook_success() { Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); expectedModel.setAddressBook(new AddressBook()); - assertCommandSuccess(new ClearCommand(), model, ClearCommand.MESSAGE_SUCCESS, expectedModel); + assertCommandSuccess(new ClearCommand(), model, Messages.MESSAGE_CLEAR_SUCCESS, expectedModel); } } diff --git a/src/test/java/seedu/address/logic/commands/CreateTagCommandTest.java b/src/test/java/seedu/address/logic/commands/CreateTagCommandTest.java index a2b4f44431f..11723b56dad 100644 --- a/src/test/java/seedu/address/logic/commands/CreateTagCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/CreateTagCommandTest.java @@ -41,7 +41,7 @@ public void execute_tagAcceptedByModel_addSuccessful() throws Exception { Tag validTag = new Tag(new TagName(VALID_TAG_FLORIST)); CommandResult commandResult = new CreateTagCommand(validTag).execute(modelStub); - assertEquals(String.format(CreateTagCommand.MESSAGE_SUCCESS, Messages.format(validTag)), + assertEquals(String.format(Messages.MESSAGE_CREATE_TAG_SUCCESS, Messages.format(validTag)), commandResult.getFeedbackToUser()); assertEquals(Arrays.asList(validTag), modelStub.tagsAdded); } @@ -53,7 +53,7 @@ public void execute_duplicateTag_throwsCommandException() { ModelStub modelStub = new ModelStubWithTag(validTag); assertThrows(CommandException.class, - CreateTagCommand.MESSAGE_DUPLICATE_TAG, () -> createTagCommand.execute(modelStub)); + Messages.MESSAGE_DUPLICATE_TAG, () -> createTagCommand.execute(modelStub)); } @Test diff --git a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java index f8a70897497..3d697e90fee 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java @@ -32,7 +32,7 @@ public void execute_validIndexUnfilteredList_success() { Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST.getZeroBased()); DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST); - String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)); ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); @@ -57,7 +57,7 @@ public void execute_validIndexFilteredList_success() { Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST.getZeroBased()); DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST); - String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)); Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); diff --git a/src/test/java/seedu/address/logic/commands/DeleteTagCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteTagCommandTest.java index e07907f444d..a90a8e7818e 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteTagCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteTagCommandTest.java @@ -24,7 +24,7 @@ public void execute_validDeleteTagCommand_success() { Tag tagToDelete = model.getFilteredTagList().get(0); DeleteTagCommand deleteTagCommand = new DeleteTagCommand(tagToDelete, true); - String expectedMessage = String.format(DeleteTagCommand.MESSAGE_DELETE_TAG_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_DELETE_TAG_SUCCESS, Messages.format(tagToDelete)); ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); @@ -37,7 +37,7 @@ public void execute_validDeleteTagCommandStillInUse_failure() { Tag tagToDelete = model.getFilteredTagList().get(1); DeleteTagCommand deleteTagCommand = new DeleteTagCommand(tagToDelete); String expectedMessage = String.format( - DeleteTagCommand.MESSAGE_DELETE_TAG_FAILURE_STILL_TAGGED, Messages.format(tagToDelete)) + Messages.MESSAGE_DELETE_TAG_FAILURE_STILL_TAGGED, Messages.format(tagToDelete)) + "\n" + Messages.MESSAGE_FORCE_DELETE_TAG; assertCommandFailure(deleteTagCommand, model, expectedMessage); @@ -48,7 +48,7 @@ public void execute_validDeleteTagCommandStillInUseForce_success() { Tag tagToDelete = model.getFilteredTagList().get(1); DeleteTagCommand deleteTagCommand = new DeleteTagCommand(tagToDelete, true); String expectedMessage = String.format( - DeleteTagCommand.MESSAGE_DELETE_TAG_SUCCESS, Messages.format(tagToDelete)); + Messages.MESSAGE_DELETE_TAG_SUCCESS, Messages.format(tagToDelete)); assertCommandSuccess(deleteTagCommand, model, expectedMessage, model); } @@ -56,7 +56,7 @@ public void execute_validDeleteTagCommandStillInUseForce_success() { public void execute_invalidNotFoundDeleteTagCommand() { Tag tagToDelete = model.getFilteredTagList().get(0); - String expectedMessage = String.format(DeleteTagCommand.MESSAGE_DELETE_TAG_FAILURE_NOT_FOUND, + String expectedMessage = String.format(Messages.MESSAGE_DELETE_TAG_FAILURE_NOT_FOUND, Messages.format(tagToDelete)); ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 16fcbe253df..c26f149f323 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -43,7 +43,7 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() { EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedPerson).build(); EditCommand editCommand = new EditCommand(INDEX_FIRST, descriptor); - String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); + String expectedMessage = String.format(Messages.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson); @@ -65,7 +65,7 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { .withPhone(VALID_PHONE_BOB).withTags(VALID_TAG_HUSBAND).build(); EditCommand editCommand = new EditCommand(indexLastPerson, descriptor); - String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); + String expectedMessage = String.format(Messages.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setPerson(lastPerson, editedPerson); @@ -78,7 +78,7 @@ public void execute_noFieldSpecifiedUnfilteredList_success() { EditCommand editCommand = new EditCommand(INDEX_FIRST, new EditPersonDescriptor()); Person editedPerson = model.getFilteredPersonList().get(INDEX_FIRST.getZeroBased()); - String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); + String expectedMessage = String.format(Messages.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); @@ -94,7 +94,7 @@ public void execute_filteredList_success() { EditCommand editCommand = new EditCommand(INDEX_FIRST, new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build()); - String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); + String expectedMessage = String.format(Messages.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson); @@ -108,7 +108,7 @@ public void execute_duplicatePersonUnfilteredList_failure() { EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(firstPerson).build(); EditCommand editCommand = new EditCommand(INDEX_SECOND, descriptor); - assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON); + assertCommandFailure(editCommand, model, Messages.MESSAGE_DUPLICATE_PERSON); } @Test @@ -120,7 +120,7 @@ public void execute_duplicatePersonFilteredList_failure() { EditCommand editCommand = new EditCommand(INDEX_FIRST, new EditPersonDescriptorBuilder(personInList).build()); - assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON); + assertCommandFailure(editCommand, model, Messages.MESSAGE_DUPLICATE_PERSON); } @Test diff --git a/src/test/java/seedu/address/logic/commands/ExitCommandTest.java b/src/test/java/seedu/address/logic/commands/ExitCommandTest.java index 9533c473875..6f9c8d8501e 100644 --- a/src/test/java/seedu/address/logic/commands/ExitCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ExitCommandTest.java @@ -1,10 +1,10 @@ package seedu.address.logic.commands; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.ExitCommand.MESSAGE_EXIT_ACKNOWLEDGEMENT; import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; import seedu.address.model.Model; import seedu.address.model.ModelManager; @@ -14,7 +14,7 @@ public class ExitCommandTest { @Test public void execute_exit_success() { - CommandResult expectedCommandResult = new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true); + CommandResult expectedCommandResult = new CommandResult(Messages.MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true); assertCommandSuccess(new ExitCommand(), model, expectedCommandResult, expectedModel); } } diff --git a/src/test/java/seedu/address/logic/commands/HelpCommandTest.java b/src/test/java/seedu/address/logic/commands/HelpCommandTest.java index 4904fc4352e..d0337830a49 100644 --- a/src/test/java/seedu/address/logic/commands/HelpCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/HelpCommandTest.java @@ -1,10 +1,10 @@ package seedu.address.logic.commands; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.HelpCommand.SHOWING_HELP_MESSAGE; import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; import seedu.address.model.Model; import seedu.address.model.ModelManager; @@ -14,7 +14,7 @@ public class HelpCommandTest { @Test public void execute_help_success() { - CommandResult expectedCommandResult = new CommandResult(SHOWING_HELP_MESSAGE, true, false); + CommandResult expectedCommandResult = new CommandResult(Messages.SHOWING_HELP_MESSAGE, true, false); assertCommandSuccess(new HelpCommand(), model, expectedCommandResult, expectedModel); } } diff --git a/src/test/java/seedu/address/logic/commands/TagCommandTest.java b/src/test/java/seedu/address/logic/commands/TagCommandTest.java index 61a1b8f7d18..e1d8cf9d655 100644 --- a/src/test/java/seedu/address/logic/commands/TagCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/TagCommandTest.java @@ -41,7 +41,7 @@ public void execute_validTagsUnfilteredList_success() { TagCommand tagCommand = new TagCommand(INDEX_FIRST, tagsToAdd); - String expectedMessage = String.format(Messages.MESSAGE_ADD_TAG_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_ASSIGN_TAG_SUCCESS, "colleague", personToEdit.getName().toString()); Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); @@ -69,7 +69,7 @@ public void execute_validTagsUnfilteredListWithForce_success() { TagCommand tagCommand = new TagCommand(INDEX_FIRST, tagsToAdd, true); - String expectedMessage = String.format(Messages.MESSAGE_ADD_TAG_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_ASSIGN_TAG_SUCCESS, "colleague", personToEdit.getName().toString()); Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); @@ -108,7 +108,7 @@ public void execute_validMultipleTagsUnfilteredList_success() { HashSet tagsToAdd = new HashSet<>(Arrays.asList(new Tag(new TagName("colleague")), new Tag(new TagName("gym")))); TagCommand tagCommand = new TagCommand(INDEX_FIRST, tagsToAdd); - String expectedMessage = String.format(Messages.MESSAGE_ADD_TAG_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_ASSIGN_TAG_SUCCESS, "gym, colleague", personWithTags.getName().toString()); // Create the expected model with the updated tags diff --git a/src/test/java/seedu/address/logic/commands/UntagCommandTest.java b/src/test/java/seedu/address/logic/commands/UntagCommandTest.java index 054268522c1..b21ae765548 100644 --- a/src/test/java/seedu/address/logic/commands/UntagCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/UntagCommandTest.java @@ -38,7 +38,7 @@ public void execute_validTagsUnfilteredList_success() { UntagCommand untagCommand = new UntagCommand(INDEX_FIRST, tagsToRemove); - String expectedMessage = String.format(UntagCommand.MESSAGE_REMOVE_TAG_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_REMOVE_TAG_SUCCESS, "photographer", personToEdit.getName().toString()); Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); @@ -73,7 +73,7 @@ public void execute_validMultipleTagsUnfilteredList_success() { HashSet tagsToRemove = new HashSet<>(Arrays.asList(new Tag(new TagName("florist")), new Tag(new TagName("photographer")))); UntagCommand untagCommand = new UntagCommand(INDEX_FIRST, tagsToRemove); - String expectedMessage = String.format(UntagCommand.MESSAGE_REMOVE_TAG_SUCCESS, + String expectedMessage = String.format(Messages.MESSAGE_REMOVE_TAG_SUCCESS, "florist, photographer", personWithTags.getName().toString()); // Create the expected model with the updated tags (i.e., an empty set of tags) diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index 33eb6cf9de5..4ecfbd283e5 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -1,6 +1,5 @@ package seedu.address.logic.parser; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; @@ -47,27 +46,24 @@ public class EditCommandParserTest { private static final String TAG_EMPTY = " " + PREFIX_TAG; - private static final String MESSAGE_INVALID_FORMAT = - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE); - private final EditCommandParser parser = new EditCommandParser(); @Test public void parse_missingParts_failure() { // no index specified - assertParseFailure(parser, VALID_NAME_AMY, MESSAGE_INVALID_FORMAT); + assertParseFailure(parser, VALID_NAME_AMY, Messages.MESSAGE_INVALID_EDIT_PERSON_FORMAT); // no field specified - assertParseFailure(parser, "1", EditCommand.MESSAGE_NOT_EDITED); + assertParseFailure(parser, "1", Messages.MESSAGE_PERSON_NOT_EDITED); // no index and no field specified - assertParseFailure(parser, "", MESSAGE_INVALID_FORMAT); + assertParseFailure(parser, "", Messages.MESSAGE_INVALID_EDIT_PERSON_FORMAT); } @Test public void parse_invalidPreamble_failure() { // invalid arguments being parsed as preamble - assertParseFailure(parser, "abc some random string", MESSAGE_INVALID_FORMAT); + assertParseFailure(parser, "abc some random string", Messages.MESSAGE_INVALID_EDIT_PERSON_FORMAT); } @Test From 54e43ed2e447d9b3c61bc9df215c1f18ecd45e6e Mon Sep 17 00:00:00 2001 From: Han Bin Date: Fri, 8 Nov 2024 06:25:56 +0800 Subject: [PATCH 5/5] Refractor Message from Storage Refractor message from Storage. Fix formatting errors in messages. --- src/main/java/seedu/address/logic/Messages.java | 1 + .../storage/JsonSerializableAddressBook.java | 15 +++++---------- .../storage/JsonSerializableAddressBookTest.java | 9 +++++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 27c2b3c32d2..d35080a11ff 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -62,6 +62,7 @@ public class Messages { public static final String MESSAGE_REMOVE_TAG_SUCCESS = "Removed tag(s) %1$s from %2$s."; public static final String MESSAGE_TAG_NOT_FOUND = "One or more specified tags do not exist in the Wedlinker."; public static final String MESSAGE_TAG_NOT_FOUND_IN_CONTACT = "Some tags were not found in the person's tag list."; + /** * Messages specific to Wedding */ diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index 41d6334f542..b6b9dfc70c4 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonRootName; import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.logic.Messages; import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.person.Person; @@ -26,12 +27,6 @@ @JsonRootName(value = "addressbook") class JsonSerializableAddressBook { - public static final String MESSAGE_DUPLICATE_PERSON = "Persons list contains duplicate person(s)."; - public static final String MESSAGE_DUPLICATE_VENDOR = "Vendors list contains duplicate vendor(s)."; - public static final String MESSAGE_DUPLICATE_TAG = "Tags list contains duplicate tag(s)."; - public static final String MESSAGE_DUPLICATE_WEDDING = "Weddings list contains duplicate wedding(s)."; - public static final String MESSAGE_DUPLICATE_TASK = "Tasks list contains duplicate task(s)."; - private final List persons = new ArrayList<>(); private final List tags = new ArrayList<>(); private final List weddings = new ArrayList<>(); @@ -74,7 +69,7 @@ public AddressBook toModelType() throws IllegalValueException { for (JsonAdaptedPerson jsonAdaptedPerson : persons) { Person person = jsonAdaptedPerson.toModelType(); if (addressBook.hasPerson(person)) { - throw new IllegalValueException(MESSAGE_DUPLICATE_PERSON); + throw new IllegalValueException(Messages.MESSAGE_DUPLICATE_PERSON); } addressBook.addPerson(person); if (jsonAdaptedPerson.isVendor()) { @@ -87,21 +82,21 @@ public AddressBook toModelType() throws IllegalValueException { for (JsonAdaptedTag jsonAdaptedTag : tags) { Tag tag = jsonAdaptedTag.toModelType(); if (addressBook.hasTag(tag)) { - throw new IllegalValueException(MESSAGE_DUPLICATE_TAG); + throw new IllegalValueException(Messages.MESSAGE_DUPLICATE_TAG); } addressBook.addTag(tag); } for (JsonAdaptedTask jsonAdaptedTask : tasks) { Task task = jsonAdaptedTask.toModelType(); if (addressBook.hasTask(task)) { - throw new IllegalValueException(MESSAGE_DUPLICATE_TASK); + throw new IllegalValueException(Messages.MESSAGE_DUPLICATE_TASK_IN_WEDLINKER); } addressBook.addTask(task); } for (JsonAdaptedWedding jsonAdaptedWedding : weddings) { Wedding wedding = jsonAdaptedWedding.toModelType(); if (addressBook.hasWedding(wedding)) { - throw new IllegalValueException(MESSAGE_DUPLICATE_WEDDING); + throw new IllegalValueException(Messages.MESSAGE_DUPLICATE_WEDDING); } addressBook.addWedding(wedding); } diff --git a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java index 9ebd2ca997a..826feb6ec7c 100644 --- a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java +++ b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java @@ -11,6 +11,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.commons.util.JsonUtil; +import seedu.address.logic.Messages; import seedu.address.model.AddressBook; import seedu.address.model.person.Vendor; import seedu.address.testutil.TypicalPersons; @@ -75,7 +76,7 @@ public void toModelType_invalidWeddingFile_throwsIllegalValueException() throws public void toModelType_duplicatePersons_throwsIllegalValueException() throws Exception { JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(DUPLICATE_PERSON_FILE, JsonSerializableAddressBook.class).get(); - assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_PERSON, + assertThrows(IllegalValueException.class, Messages.MESSAGE_DUPLICATE_PERSON, dataFromFile::toModelType); } @@ -83,7 +84,7 @@ public void toModelType_duplicatePersons_throwsIllegalValueException() throws Ex public void toModelType_duplicateTags_throwsIllegalValueException() throws Exception { JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(DUPLICATE_TAG_FILE, JsonSerializableAddressBook.class).get(); - assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_TAG, + assertThrows(IllegalValueException.class, Messages.MESSAGE_DUPLICATE_TAG, dataFromFile::toModelType); } @@ -91,7 +92,7 @@ public void toModelType_duplicateTags_throwsIllegalValueException() throws Excep public void toModelType_duplicateTasks_throwsIllegalValueException() throws Exception { JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(DUPLICATE_TASK_FILE, JsonSerializableAddressBook.class).get(); - assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_TASK, + assertThrows(IllegalValueException.class, Messages.MESSAGE_DUPLICATE_TASK_IN_WEDLINKER, dataFromFile::toModelType); } @@ -99,7 +100,7 @@ public void toModelType_duplicateTasks_throwsIllegalValueException() throws Exce public void toModelType_duplicateWeddings_throwsIllegalValueException() throws Exception { JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(DUPLICATE_WEDDING_FILE, JsonSerializableAddressBook.class).get(); - assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_WEDDING, + assertThrows(IllegalValueException.class, Messages.MESSAGE_DUPLICATE_WEDDING, dataFromFile::toModelType); }