diff --git a/src/main/java/seedu/address/commons/core/Messages.java b/src/main/java/seedu/address/commons/core/Messages.java index e194a8594e4..cd2d9ea3de1 100644 --- a/src/main/java/seedu/address/commons/core/Messages.java +++ b/src/main/java/seedu/address/commons/core/Messages.java @@ -11,5 +11,7 @@ public class Messages { public static final String MESSAGE_PROJECTS_LISTED_OVERVIEW = "%1$d projects listed!"; public static final String MESSAGE_INVALID_SCOPE_COMMAND = "The scope status is expected to be %s but you are" + " now in %s"; - + public static final String MESSAGE_MEMBER_NOT_PRESENT = "%s is not a team member of this project."; + public static final String MESSAGE_REASSIGNMENT_OF_SAME_TASK_TO_SAME_PERSON = + "%s is already an assignee of the task."; } diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/catalogue/AddCommand.java similarity index 94% rename from src/main/java/seedu/address/logic/commands/AddCommand.java rename to src/main/java/seedu/address/logic/commands/catalogue/AddCommand.java index 9369cbe6927..527f02087f1 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/catalogue/AddCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_DEADLINE; @@ -8,6 +8,8 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_REPOURL; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.project.Project; diff --git a/src/main/java/seedu/address/logic/commands/ClearCommand.java b/src/main/java/seedu/address/logic/commands/catalogue/ClearCommand.java similarity index 79% rename from src/main/java/seedu/address/logic/commands/ClearCommand.java rename to src/main/java/seedu/address/logic/commands/catalogue/ClearCommand.java index 2e9a792603d..3cd3fc909bf 100644 --- a/src/main/java/seedu/address/logic/commands/ClearCommand.java +++ b/src/main/java/seedu/address/logic/commands/catalogue/ClearCommand.java @@ -1,7 +1,9 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static java.util.Objects.requireNonNull; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.model.MainCatalogue; import seedu.address.model.Model; diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/catalogue/DeleteCommand.java similarity index 92% rename from src/main/java/seedu/address/logic/commands/DeleteCommand.java rename to src/main/java/seedu/address/logic/commands/catalogue/DeleteCommand.java index e1a8519d06a..9cd356c4081 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/catalogue/DeleteCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static java.util.Objects.requireNonNull; @@ -6,6 +6,8 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.project.Project; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/catalogue/EditCommand.java similarity index 98% rename from src/main/java/seedu/address/logic/commands/EditCommand.java rename to src/main/java/seedu/address/logic/commands/catalogue/EditCommand.java index 4ca3da93413..176a2f3c225 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/catalogue/EditCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_DEADLINE; @@ -19,6 +19,8 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; import seedu.address.commons.util.CollectionUtil; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.project.Deadline; diff --git a/src/main/java/seedu/address/logic/commands/FindCommand.java b/src/main/java/seedu/address/logic/commands/catalogue/FindCommand.java similarity index 91% rename from src/main/java/seedu/address/logic/commands/FindCommand.java rename to src/main/java/seedu/address/logic/commands/catalogue/FindCommand.java index c9b3ca776b5..4d38a061861 100644 --- a/src/main/java/seedu/address/logic/commands/FindCommand.java +++ b/src/main/java/seedu/address/logic/commands/catalogue/FindCommand.java @@ -1,8 +1,10 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static java.util.Objects.requireNonNull; import seedu.address.commons.core.Messages; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.project.NameContainsKeywordsPredicate; diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/catalogue/ListCommand.java similarity index 81% rename from src/main/java/seedu/address/logic/commands/ListCommand.java rename to src/main/java/seedu/address/logic/commands/catalogue/ListCommand.java index d3a99e04321..4b60dfa1f9f 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/catalogue/ListCommand.java @@ -1,8 +1,10 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static java.util.Objects.requireNonNull; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PROJECTS; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; /** diff --git a/src/main/java/seedu/address/logic/commands/StartCommand.java b/src/main/java/seedu/address/logic/commands/catalogue/StartCommand.java similarity index 93% rename from src/main/java/seedu/address/logic/commands/StartCommand.java rename to src/main/java/seedu/address/logic/commands/catalogue/StartCommand.java index 3fc118d7f01..c3b6b089f99 100644 --- a/src/main/java/seedu/address/logic/commands/StartCommand.java +++ b/src/main/java/seedu/address/logic/commands/catalogue/StartCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static java.util.Objects.requireNonNull; @@ -6,6 +6,8 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.exceptions.InvalidScopeException; diff --git a/src/main/java/seedu/address/logic/commands/ExitCommand.java b/src/main/java/seedu/address/logic/commands/global/ExitCommand.java similarity index 75% rename from src/main/java/seedu/address/logic/commands/ExitCommand.java rename to src/main/java/seedu/address/logic/commands/global/ExitCommand.java index 13ea993b54e..51960980a79 100644 --- a/src/main/java/seedu/address/logic/commands/ExitCommand.java +++ b/src/main/java/seedu/address/logic/commands/global/ExitCommand.java @@ -1,5 +1,7 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.global; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; /** diff --git a/src/main/java/seedu/address/logic/commands/HelpCommand.java b/src/main/java/seedu/address/logic/commands/global/HelpCommand.java similarity index 80% rename from src/main/java/seedu/address/logic/commands/HelpCommand.java rename to src/main/java/seedu/address/logic/commands/global/HelpCommand.java index bf824f91bd0..8523057145e 100644 --- a/src/main/java/seedu/address/logic/commands/HelpCommand.java +++ b/src/main/java/seedu/address/logic/commands/global/HelpCommand.java @@ -1,5 +1,7 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.global; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; /** diff --git a/src/main/java/seedu/address/logic/commands/project/AssignCommand.java b/src/main/java/seedu/address/logic/commands/project/AssignCommand.java new file mode 100644 index 00000000000..bdacf91715d --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/project/AssignCommand.java @@ -0,0 +1,77 @@ +package seedu.address.logic.commands.project; + +import static java.util.Objects.requireNonNull; + +import java.util.List; + +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.project.Participation; +import seedu.address.model.project.Project; +import seedu.address.model.task.Task; + +/** + * Assigns a task to a person with participation in the current project. + */ +public class AssignCommand extends Command { + + public static final String COMMAND_WORD = "assign"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Assigns the task identified by the index number used in the displayed task list to the team member" + + "that participates in the current project with his/her name.\n" + + "Parameters: INDEX (must be a positive integer), NAME (must be present in the project)\n" + + "Example: " + COMMAND_WORD + " 1 Lucas"; + + public static final String MESSAGE_ASSIGN_TASK_SUCCESS = "Assigns task: %1$s to %s"; + + private final Index targetIndex; + private final String assignee; + + /** + * Creates an AssignCommand that assigns the task of the given index to the intended assignee. + */ + public AssignCommand(Index targetIndex, String assignee) { + this.targetIndex = targetIndex; + this.assignee = assignee; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + Project project = model.getFilteredProjectList().get(0); + List lastShownTaskList = project.getFilteredTaskList(); + + if (targetIndex.getZeroBased() >= lastShownTaskList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PROJECT_DISPLAYED_INDEX); + } + + Task taskToAssociate = lastShownTaskList.get(targetIndex.getZeroBased()); + + if (!project.hasParticipation(assignee)) { + throw new CommandException(String.format(Messages.MESSAGE_MEMBER_NOT_PRESENT, assignee)); + } + + Participation assignee = project.getParticipation(this.assignee); + + if (assignee.hasTask(taskToAssociate)) { + throw new CommandException(String.format(Messages.MESSAGE_REASSIGNMENT_OF_SAME_TASK_TO_SAME_PERSON, + assignee.getPerson().getPersonName())); + } + assignee.addTask(taskToAssociate); + + return new CommandResult(String.format(MESSAGE_ASSIGN_TASK_SUCCESS, taskToAssociate, assignee)); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof AssignCommand // instanceof handles nulls + && targetIndex.equals(((AssignCommand) other).targetIndex) + && assignee.equals(((AssignCommand) ((AssignCommand) other)).assignee)); // state check + } +} diff --git a/src/main/java/seedu/address/logic/commands/LeaveCommand.java b/src/main/java/seedu/address/logic/commands/project/LeaveCommand.java similarity index 90% rename from src/main/java/seedu/address/logic/commands/LeaveCommand.java rename to src/main/java/seedu/address/logic/commands/project/LeaveCommand.java index 3460afb8a66..4a7856ebefa 100644 --- a/src/main/java/seedu/address/logic/commands/LeaveCommand.java +++ b/src/main/java/seedu/address/logic/commands/project/LeaveCommand.java @@ -1,8 +1,10 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.project; import static java.util.Objects.requireNonNull; import seedu.address.commons.core.Messages; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.exceptions.InvalidScopeException; diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index f81ce1d0780..8712283b707 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -12,7 +12,7 @@ import java.util.Set; import java.util.stream.Stream; -import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.catalogue.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.project.Deadline; import seedu.address.model.project.Project; diff --git a/src/main/java/seedu/address/logic/parser/AssignCommandParser.java b/src/main/java/seedu/address/logic/parser/AssignCommandParser.java new file mode 100644 index 00000000000..73266a7cf08 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/AssignCommandParser.java @@ -0,0 +1,36 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.project.AssignCommand; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new AssignCommand object + */ +public class AssignCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the DeleteCommand + * and returns a DeleteCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public AssignCommand parse(String args) throws ParseException { + try { + String input = args.trim(); + int divider = input.indexOf(" "); + if (divider <= 0) { + throw new ParseException(""); + } + String indexString = input.substring(0, divider); + Index index = ParserUtil.parseIndex(indexString); + String name = input.substring(divider + 1); + return new AssignCommand(index, name); + } catch (ParseException pe) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, AssignCommand.MESSAGE_USAGE), pe); + } + } + +} diff --git a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java index 522b93081cc..c4dccab2c8a 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java @@ -3,7 +3,7 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.catalogue.DeleteCommand; import seedu.address.logic.parser.exceptions.ParseException; /** diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index e4fbeb8567f..1c69dc56d9d 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -15,8 +15,8 @@ import java.util.Set; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.EditCommand.EditProjectDescriptor; +import seedu.address.logic.commands.catalogue.EditCommand; +import seedu.address.logic.commands.catalogue.EditCommand.EditProjectDescriptor; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.tag.ProjectTag; import seedu.address.model.task.Task; diff --git a/src/main/java/seedu/address/logic/parser/FindCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java index a962b70cbac..81256b46422 100644 --- a/src/main/java/seedu/address/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -4,7 +4,7 @@ import java.util.Arrays; -import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.catalogue.FindCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.project.NameContainsKeywordsPredicate; diff --git a/src/main/java/seedu/address/logic/parser/MainCatalogueParser.java b/src/main/java/seedu/address/logic/parser/MainCatalogueParser.java index ff943ee03a1..fe96e95372a 100644 --- a/src/main/java/seedu/address/logic/parser/MainCatalogueParser.java +++ b/src/main/java/seedu/address/logic/parser/MainCatalogueParser.java @@ -6,17 +6,18 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import seedu.address.logic.commands.AddCommand; -import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.Command; -import seedu.address.logic.commands.DeleteCommand; -import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.ExitCommand; -import seedu.address.logic.commands.FindCommand; -import seedu.address.logic.commands.HelpCommand; -import seedu.address.logic.commands.LeaveCommand; -import seedu.address.logic.commands.ListCommand; -import seedu.address.logic.commands.StartCommand; +import seedu.address.logic.commands.catalogue.AddCommand; +import seedu.address.logic.commands.catalogue.ClearCommand; +import seedu.address.logic.commands.catalogue.DeleteCommand; +import seedu.address.logic.commands.catalogue.EditCommand; +import seedu.address.logic.commands.catalogue.FindCommand; +import seedu.address.logic.commands.catalogue.ListCommand; +import seedu.address.logic.commands.catalogue.StartCommand; +import seedu.address.logic.commands.global.ExitCommand; +import seedu.address.logic.commands.global.HelpCommand; +import seedu.address.logic.commands.project.AssignCommand; +import seedu.address.logic.commands.project.LeaveCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.exceptions.InvalidScopeException; import seedu.address.model.project.Status; @@ -78,6 +79,7 @@ public Command parseCommand(String userInput, Status status) throws ParseExcepti return new StartCommandParser().parse(arguments); case LeaveCommand.COMMAND_WORD: + case AssignCommand.COMMAND_WORD: throw new InvalidScopeException(Status.PROJECT, Status.CATALOGUE); default: @@ -89,6 +91,9 @@ public Command parseCommand(String userInput, Status status) throws ParseExcepti case LeaveCommand.COMMAND_WORD: return new LeaveCommand(); + case AssignCommand.COMMAND_WORD: + return new AssignCommandParser().parse(arguments); + case ExitCommand.COMMAND_WORD: return new ExitCommand(); diff --git a/src/main/java/seedu/address/logic/parser/StartCommandParser.java b/src/main/java/seedu/address/logic/parser/StartCommandParser.java index 43665bced0b..ca1ebb487c9 100644 --- a/src/main/java/seedu/address/logic/parser/StartCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/StartCommandParser.java @@ -3,7 +3,7 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.StartCommand; +import seedu.address.logic.commands.catalogue.StartCommand; import seedu.address.logic.parser.exceptions.ParseException; /** diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 6133128155a..a90d2b67a21 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -2,16 +2,12 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.Objects; -import java.util.Set; import seedu.address.model.project.Participation; import seedu.address.model.project.Project; import seedu.address.model.project.ProjectName; -import seedu.address.model.tag.ProjectTag; /** * Represents a Teammate in the team. @@ -26,19 +22,17 @@ public class Person { // Data fields private Address address; - private final Set projectTags = new HashSet<>(); private HashMap listOfParticipations = new HashMap<>(); /** * Every field must be present and not null. */ - public Person(PersonName personName, Phone phone, Email email, Address address, Set projectTags) { - requireAllNonNull(personName, phone, email, address, projectTags); + public Person(PersonName personName, Phone phone, Email email, Address address) { + requireAllNonNull(personName, phone, email, address); this.personName = personName; this.phone = phone; this.email = email; this.address = address; - this.projectTags.addAll(projectTags); } public PersonName getPersonName() { @@ -77,14 +71,6 @@ public void addProject(Project p) { listOfParticipations.put(p.getProjectName(), new Participation(this, p)); } - /** - * Returns an immutable tag set, which throws {@code UnsupportedOperationException} - * if modification is attempted. - */ - public Set getTags() { - return Collections.unmodifiableSet(projectTags); - } - /** * Returns true if both teammates of the same name have at least one other identity field that is the same. * This defines a weaker notion of equality between two projects. @@ -119,14 +105,13 @@ public boolean equals(Object other) { return otherProject.getPersonName().equals(getPersonName()) && otherProject.getPhone().equals(getPhone()) && otherProject.getEmail().equals(getEmail()) - && otherProject.getAddress().equals(getAddress()) - && otherProject.getTags().equals(getTags()); + && otherProject.getAddress().equals(getAddress()); } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(personName, phone, email, address, projectTags); + return Objects.hash(personName, phone, email, address); } @Override @@ -139,9 +124,7 @@ public String toString() { .append(" Email: ") .append(getEmail()) .append(" Address: ") - .append(getAddress()) - .append(" Tags: "); - getTags().forEach(builder::append); + .append(getAddress()); return builder.toString(); } diff --git a/src/main/java/seedu/address/model/project/Project.java b/src/main/java/seedu/address/model/project/Project.java index 06982f14676..f48832f2bc6 100644 --- a/src/main/java/seedu/address/model/project/Project.java +++ b/src/main/java/seedu/address/model/project/Project.java @@ -2,9 +2,11 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -109,6 +111,27 @@ public void addParticipation(Person p) { p.getPersonName(), new Participation(p, this)); } + /** + * Checks whether the project contains a member of the given name. + */ + public boolean hasParticipation(String name) { + return listOfParticipations.containsKey(new PersonName(name)); + } + + /** + * Gets the Participation with the member name. + */ + public Participation getParticipation(String name) { + return listOfParticipations.get(new PersonName(name)); + } + + /** + * Returns the list of tasks that is last shown. + */ + public List getFilteredTaskList() { + return new ArrayList<>(tasks); + } // TODO: May update when adding filters + /** * Returns true if both projects of the same projectName have at least one other identity field that is the same. * This defines a weaker notion of equality between two projects. diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 886c255a403..0eccf196663 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -17,9 +17,9 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import seedu.address.logic.commands.AddCommand; import seedu.address.logic.commands.CommandResult; -import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.catalogue.AddCommand; +import seedu.address.logic.commands.catalogue.ListCommand; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.Model; diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 49a5b148964..f43ba353e48 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -15,6 +15,7 @@ import java.util.List; import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.catalogue.EditCommand; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.MainCatalogue; import seedu.address.model.Model; diff --git a/src/test/java/seedu/address/logic/commands/EditProjectDescriptorTest.java b/src/test/java/seedu/address/logic/commands/EditProjectDescriptorTest.java index d535230e5de..de8d3bd3a9c 100644 --- a/src/test/java/seedu/address/logic/commands/EditProjectDescriptorTest.java +++ b/src/test/java/seedu/address/logic/commands/EditProjectDescriptorTest.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.EditCommand.EditProjectDescriptor; +import seedu.address.logic.commands.catalogue.EditCommand.EditProjectDescriptor; import seedu.address.testutil.EditProjectDescriptorBuilder; public class EditProjectDescriptorTest { diff --git a/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/catalogue/AddCommandIntegrationTest.java similarity index 96% rename from src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java rename to src/test/java/seedu/address/logic/commands/catalogue/AddCommandIntegrationTest.java index acaff65e756..85c0a3b0100 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java +++ b/src/test/java/seedu/address/logic/commands/catalogue/AddCommandIntegrationTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/catalogue/AddCommandTest.java similarity index 98% rename from src/test/java/seedu/address/logic/commands/AddCommandTest.java rename to src/test/java/seedu/address/logic/commands/catalogue/AddCommandTest.java index 6a3d02542d3..690bdee94ca 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/catalogue/AddCommandTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static java.util.Objects.requireNonNull; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -15,6 +15,7 @@ import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.MainCatalogue; import seedu.address.model.Model; diff --git a/src/test/java/seedu/address/logic/commands/ClearCommandTest.java b/src/test/java/seedu/address/logic/commands/catalogue/ClearCommandTest.java similarity index 95% rename from src/test/java/seedu/address/logic/commands/ClearCommandTest.java rename to src/test/java/seedu/address/logic/commands/catalogue/ClearCommandTest.java index 4a7309bea89..5eddb095606 100644 --- a/src/test/java/seedu/address/logic/commands/ClearCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/catalogue/ClearCommandTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.testutil.TypicalProjects.getTypicalMainCatalogue; diff --git a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/catalogue/DeleteCommandTest.java similarity index 98% rename from src/test/java/seedu/address/logic/commands/DeleteCommandTest.java rename to src/test/java/seedu/address/logic/commands/catalogue/DeleteCommandTest.java index 794c4b9992e..18dc64c849e 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/catalogue/DeleteCommandTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/catalogue/EditCommandTest.java similarity index 98% rename from src/test/java/seedu/address/logic/commands/EditCommandTest.java rename to src/test/java/seedu/address/logic/commands/catalogue/EditCommandTest.java index 85d0768dec2..d04e31e3e64 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/catalogue/EditCommandTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -18,7 +18,7 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.EditCommand.EditProjectDescriptor; +import seedu.address.logic.commands.catalogue.EditCommand.EditProjectDescriptor; import seedu.address.model.MainCatalogue; import seedu.address.model.Model; import seedu.address.model.ModelManager; diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/catalogue/FindCommandTest.java similarity index 98% rename from src/test/java/seedu/address/logic/commands/FindCommandTest.java rename to src/test/java/seedu/address/logic/commands/catalogue/FindCommandTest.java index 5a0eb7612e9..3695d517a4c 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/catalogue/FindCommandTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/src/test/java/seedu/address/logic/commands/ListCommandTest.java b/src/test/java/seedu/address/logic/commands/catalogue/ListCommandTest.java similarity index 96% rename from src/test/java/seedu/address/logic/commands/ListCommandTest.java rename to src/test/java/seedu/address/logic/commands/catalogue/ListCommandTest.java index 3015b6297c9..bf61c41c7e6 100644 --- a/src/test/java/seedu/address/logic/commands/ListCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/catalogue/ListCommandTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showProjectAtIndex; diff --git a/src/test/java/seedu/address/logic/commands/StartCommandTest.java b/src/test/java/seedu/address/logic/commands/catalogue/StartCommandTest.java similarity index 99% rename from src/test/java/seedu/address/logic/commands/StartCommandTest.java rename to src/test/java/seedu/address/logic/commands/catalogue/StartCommandTest.java index 60ebb0280db..cb77936b2a3 100644 --- a/src/test/java/seedu/address/logic/commands/StartCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/catalogue/StartCommandTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.catalogue; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/src/test/java/seedu/address/logic/commands/ExitCommandTest.java b/src/test/java/seedu/address/logic/commands/global/ExitCommandTest.java similarity index 75% rename from src/test/java/seedu/address/logic/commands/ExitCommandTest.java rename to src/test/java/seedu/address/logic/commands/global/ExitCommandTest.java index 9533c473875..58812fece2c 100644 --- a/src/test/java/seedu/address/logic/commands/ExitCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/global/ExitCommandTest.java @@ -1,10 +1,11 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.global; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.ExitCommand.MESSAGE_EXIT_ACKNOWLEDGEMENT; +import static seedu.address.logic.commands.global.ExitCommand.MESSAGE_EXIT_ACKNOWLEDGEMENT; import org.junit.jupiter.api.Test; +import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.ModelManager; diff --git a/src/test/java/seedu/address/logic/commands/HelpCommandTest.java b/src/test/java/seedu/address/logic/commands/global/HelpCommandTest.java similarity index 76% rename from src/test/java/seedu/address/logic/commands/HelpCommandTest.java rename to src/test/java/seedu/address/logic/commands/global/HelpCommandTest.java index 4904fc4352e..4f7a57d1443 100644 --- a/src/test/java/seedu/address/logic/commands/HelpCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/global/HelpCommandTest.java @@ -1,10 +1,11 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.global; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.HelpCommand.SHOWING_HELP_MESSAGE; +import static seedu.address.logic.commands.global.HelpCommand.SHOWING_HELP_MESSAGE; import org.junit.jupiter.api.Test; +import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; import seedu.address.model.ModelManager; diff --git a/src/test/java/seedu/address/logic/commands/project/AssignCommandTest.java b/src/test/java/seedu/address/logic/commands/project/AssignCommandTest.java new file mode 100644 index 00000000000..0143853577a --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/project/AssignCommandTest.java @@ -0,0 +1,127 @@ +package seedu.address.logic.commands.project; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PROJECT; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_TASK; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_TASK; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalProjects.getTypicalMainCatalogue; + +import java.util.HashMap; + +import org.junit.jupiter.api.Test; + +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.project.Participation; +import seedu.address.model.project.Project; +import seedu.address.model.task.Task; + +/** + * Contains integration tests (interaction with the Model, UndoCommand and RedoCommand) and unit tests for + * {@code DeleteCommand}. + */ +public class AssignCommandTest { + @Test + public void execute_validIndexInvalidPerson_throwsCommandException() { + Model model = new ModelManager(getTypicalMainCatalogue(), new UserPrefs()); + Project project = model.getFilteredProjectList().get(INDEX_FIRST_PROJECT.getZeroBased()); + Project projectCopy = new Project(project.getProjectName(), project.getDeadline(), project.getRepoUrl(), + project.getProjectDescription(), project.getProjectTags(), new HashMap<>(), project.getTasks()); + model.enter(project); + model.setProject(project, projectCopy); + + AssignCommand assignCommand = new AssignCommand(INDEX_FIRST_TASK, ALICE.getPersonName().fullPersonName); + assertCommandFailure(assignCommand, model, + String.format(Messages.MESSAGE_MEMBER_NOT_PRESENT, ALICE.getPersonName())); + } + + @Test + public void execute_invalidIndexValidPerson_throwsCommandException() { + Model model = new ModelManager(getTypicalMainCatalogue(), new UserPrefs()); + Project project = model.getFilteredProjectList().get(INDEX_FIRST_PROJECT.getZeroBased()); + Index outOfBoundIndex = Index.fromOneBased(project.getFilteredTaskList().size() + 1); + model.enter(project); + project.addParticipation(ALICE); + AssignCommand assignCommand = new AssignCommand(outOfBoundIndex, ALICE.getPersonName().fullPersonName); + + assertCommandFailure(assignCommand, model, Messages.MESSAGE_INVALID_PROJECT_DISPLAYED_INDEX); + } + + @Test + public void execute_validIndexPersonInvalidAssign_throwsCommandException() { + Model model = new ModelManager(getTypicalMainCatalogue(), new UserPrefs()); + Project project = model.getFilteredProjectList().get(INDEX_FIRST_PROJECT.getZeroBased()); + model.enter(project); + project.addParticipation(ALICE); + Task taskToAssign = project.getFilteredTaskList().get(INDEX_FIRST_TASK.getZeroBased()); + Participation assignee = project.getParticipation(ALICE.getPersonName().fullPersonName); + assignee.addTask(taskToAssign); + AssignCommand assignCommand = new AssignCommand(INDEX_FIRST_TASK, ALICE.getPersonName().fullPersonName); + + assertCommandFailure(assignCommand, model, String.format( + Messages.MESSAGE_REASSIGNMENT_OF_SAME_TASK_TO_SAME_PERSON, assignee.getPerson().getPersonName())); + } + + @Test + public void execute_validIndexValidPerson_success() { + Model model = new ModelManager(getTypicalMainCatalogue(), new UserPrefs()); + Project project = model.getFilteredProjectList().get(INDEX_FIRST_PROJECT.getZeroBased()); + model.enter(project); + project.addParticipation(ALICE); + ModelManager expectedModel = new ModelManager(model.getProjectCatalogue(), new UserPrefs()); + + Task taskToAssign = project.getFilteredTaskList().get(INDEX_FIRST_TASK.getZeroBased()); + Participation assignee = project.getParticipation(ALICE.getPersonName().fullPersonName); + AssignCommand assignCommand = new AssignCommand(INDEX_FIRST_TASK, ALICE.getPersonName().fullPersonName); + + + String expectedMessage = String.format(AssignCommand.MESSAGE_ASSIGN_TASK_SUCCESS, taskToAssign, assignee); + + Project projectCopy = new Project(project.getProjectName(), project.getDeadline(), project.getRepoUrl(), + project.getProjectDescription(), project.getProjectTags(), new HashMap<>(), project.getTasks()); + projectCopy.addParticipation(ALICE); + // TODO: After refining Participation getters and setters this part can be done fully via getters + expectedModel.setProject(project, projectCopy); + expectedModel.enter(projectCopy); + expectedModel.getFilteredProjectList().get(INDEX_FIRST_PROJECT.getZeroBased()) + .getParticipation(ALICE.getPersonName().fullPersonName).addTask(taskToAssign); + + assertCommandSuccess(assignCommand, model, expectedMessage, expectedModel); + } + + // TODO: May add test cases for filtered/unfiltered list of tasks after filters are implemented + + @Test + public void equals() { + String name = ALICE.getPersonName().fullPersonName; + AssignCommand assignFirstCommand = new AssignCommand(INDEX_FIRST_TASK, name); + AssignCommand assignSecondCommand = new AssignCommand(INDEX_SECOND_TASK, name); + AssignCommand assignNullPerson = new AssignCommand(INDEX_FIRST_TASK, ""); + + // same object -> returns true + assertTrue(assignFirstCommand.equals(assignFirstCommand)); + + // same values -> returns true + AssignCommand assignFirstCommandCopy = new AssignCommand(INDEX_FIRST_TASK, name); + assertTrue(assignFirstCommand.equals(assignFirstCommandCopy)); + + // different types -> returns false + assertFalse(assignFirstCommand.equals(1)); + + // null -> returns false + assertFalse(assignFirstCommand.equals(null)); + + // different task -> returns false + assertFalse(assignFirstCommand.equals(assignSecondCommand)); + + // different person -> returns false + assertFalse(assignFirstCommand.equals(assignNullPerson)); + } +} diff --git a/src/test/java/seedu/address/logic/commands/LeaveCommandTest.java b/src/test/java/seedu/address/logic/commands/project/LeaveCommandTest.java similarity index 97% rename from src/test/java/seedu/address/logic/commands/LeaveCommandTest.java rename to src/test/java/seedu/address/logic/commands/project/LeaveCommandTest.java index 25ff3fdad5a..6d7e598a547 100644 --- a/src/test/java/seedu/address/logic/commands/LeaveCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/project/LeaveCommandTest.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.project; import static org.junit.jupiter.api.Assertions.assertEquals; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java index aa47d868bee..b4e83ed31be 100644 --- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java @@ -35,7 +35,7 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.catalogue.AddCommand; import seedu.address.model.project.Deadline; import seedu.address.model.project.Project; import seedu.address.model.project.ProjectDescription; diff --git a/src/test/java/seedu/address/logic/parser/AssignCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AssignCommandParserTest.java new file mode 100644 index 00000000000..2c6861eba45 --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/AssignCommandParserTest.java @@ -0,0 +1,34 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_TASK; +import static seedu.address.testutil.TypicalPersons.ALICE; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.project.AssignCommand; + +/** + * As we are only doing white-box testing, our test cases do not cover path variations + * outside of the DeleteCommand code. For example, inputs "1" and "1 abc" take the + * same path through the DeleteCommand, and therefore we test only one of them. + * The path variation for those two cases occur inside the ParserUtil, and + * therefore should be covered by the ParserUtilTest. + */ +public class AssignCommandParserTest { + + private AssignCommandParser parser = new AssignCommandParser(); + + @Test + public void parse_validArgs_returnsAssignCommand() { + assertParseSuccess(parser, "1 Alice Pauline", + new AssignCommand(INDEX_FIRST_TASK, ALICE.getPersonName().toString())); + } + + @Test + public void parse_invalidArgs_throwsParseException() { + assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, AssignCommand.MESSAGE_USAGE)); + } +} diff --git a/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java b/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java index 333d09326d1..b21d9f66db9 100644 --- a/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.catalogue.DeleteCommand; /** * As we are only doing white-box testing, our test cases do not cover path variations diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index 6205c1cccf4..329235216a9 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -38,8 +38,8 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.EditCommand.EditProjectDescriptor; +import seedu.address.logic.commands.catalogue.EditCommand; +import seedu.address.logic.commands.catalogue.EditCommand.EditProjectDescriptor; import seedu.address.model.project.Deadline; import seedu.address.model.project.ProjectDescription; import seedu.address.model.project.ProjectName; diff --git a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index 7cd763b7532..8cf041c0137 100644 --- a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.catalogue.FindCommand; import seedu.address.model.project.NameContainsKeywordsPredicate; public class FindCommandParserTest { diff --git a/src/test/java/seedu/address/logic/parser/MainCatalogueParserTest.java b/src/test/java/seedu/address/logic/parser/MainCatalogueParserTest.java index ff6af9ae5fe..804d4d9e91b 100644 --- a/src/test/java/seedu/address/logic/parser/MainCatalogueParserTest.java +++ b/src/test/java/seedu/address/logic/parser/MainCatalogueParserTest.java @@ -6,6 +6,8 @@ import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PROJECT; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_TASK; +import static seedu.address.testutil.TypicalPersons.ALICE; import java.util.Arrays; import java.util.List; @@ -13,17 +15,18 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.AddCommand; -import seedu.address.logic.commands.ClearCommand; -import seedu.address.logic.commands.DeleteCommand; -import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.EditCommand.EditProjectDescriptor; -import seedu.address.logic.commands.ExitCommand; -import seedu.address.logic.commands.FindCommand; -import seedu.address.logic.commands.HelpCommand; -import seedu.address.logic.commands.LeaveCommand; -import seedu.address.logic.commands.ListCommand; -import seedu.address.logic.commands.StartCommand; +import seedu.address.logic.commands.catalogue.AddCommand; +import seedu.address.logic.commands.catalogue.ClearCommand; +import seedu.address.logic.commands.catalogue.DeleteCommand; +import seedu.address.logic.commands.catalogue.EditCommand; +import seedu.address.logic.commands.catalogue.EditCommand.EditProjectDescriptor; +import seedu.address.logic.commands.catalogue.FindCommand; +import seedu.address.logic.commands.catalogue.ListCommand; +import seedu.address.logic.commands.catalogue.StartCommand; +import seedu.address.logic.commands.global.ExitCommand; +import seedu.address.logic.commands.global.HelpCommand; +import seedu.address.logic.commands.project.AssignCommand; +import seedu.address.logic.commands.project.LeaveCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.exceptions.InvalidScopeException; import seedu.address.model.project.NameContainsKeywordsPredicate; @@ -110,6 +113,14 @@ public void parseCommand_leave() throws Exception { assertTrue(parser.parseCommand(LeaveCommand.COMMAND_WORD + " 3", Status.PROJECT) instanceof LeaveCommand); } + @Test + public void parseCommand_assign() throws Exception { + AssignCommand command = (AssignCommand) parser.parseCommand( + AssignCommand.COMMAND_WORD + " " + INDEX_FIRST_TASK.getOneBased() + " " + ALICE.getPersonName(), + Status.PROJECT); + assertEquals(new AssignCommand(INDEX_FIRST_TASK, ALICE.getPersonName().toString()), command); + } + @Test public void parseCommand_unrecognisedInput_throwsParseException() { assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), () @@ -181,5 +192,13 @@ public void parseCommand_invalidScope_throwsInvalidScopeException() { } catch (Exception e) { assertEquals(new InvalidScopeException(Status.PROJECT, Status.CATALOGUE), e); } + + try { + parser.parseCommand( + AssignCommand.COMMAND_WORD + " " + INDEX_FIRST_TASK.getOneBased() + " " + ALICE.getPersonName(), + Status.CATALOGUE); + } catch (Exception e) { + assertEquals(new InvalidScopeException(Status.PROJECT, Status.CATALOGUE), e); + } } } diff --git a/src/test/java/seedu/address/logic/parser/StartCommandParserTest.java b/src/test/java/seedu/address/logic/parser/StartCommandParserTest.java index 6bbff19e10b..5f96981ce2f 100644 --- a/src/test/java/seedu/address/logic/parser/StartCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/StartCommandParserTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.StartCommand; +import seedu.address.logic.commands.catalogue.StartCommand; /** * As we are only doing white-box testing, our test cases do not cover path variations diff --git a/src/test/java/seedu/address/testutil/EditProjectDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditProjectDescriptorBuilder.java index 60589b3ed25..c1297a50d13 100644 --- a/src/test/java/seedu/address/testutil/EditProjectDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditProjectDescriptorBuilder.java @@ -4,7 +4,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import seedu.address.logic.commands.EditCommand.EditProjectDescriptor; +import seedu.address.logic.commands.catalogue.EditCommand.EditProjectDescriptor; import seedu.address.model.project.Deadline; import seedu.address.model.project.Project; import seedu.address.model.project.ProjectDescription; diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java new file mode 100644 index 00000000000..2397d2c5402 --- /dev/null +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -0,0 +1,80 @@ +package seedu.address.testutil; + +import seedu.address.model.person.Address; +import seedu.address.model.person.Email; +import seedu.address.model.person.Person; +import seedu.address.model.person.PersonName; +import seedu.address.model.person.Phone; + +/** + * A utility class to help with building Project objects. + */ +public class PersonBuilder { + + public static final String DEFAULT_PERSON_NAME = "Alice Pauline"; + public static final String DEFAULT_PHONE = "88888888"; + public static final String DEFAULT_EMAIL = "alicepauline@sample.com"; + public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111"; + + private PersonName personName; + private Phone phone; + private Email email; + private Address address; + + /** + * Creates a {@code PersonBuilder} with the default details. + */ + public PersonBuilder() { + personName = new PersonName(DEFAULT_PERSON_NAME); + phone = new Phone(DEFAULT_PHONE); + email = new Email(DEFAULT_EMAIL); + address = new Address(DEFAULT_ADDRESS); + } + + /** + * Initializes the PersonBuilder with the data of {@code personToCopy}. + */ + public PersonBuilder(Person personToCopy) { + personName = personToCopy.getPersonName(); + phone = personToCopy.getPhone(); + email = personToCopy.getEmail(); + address = personToCopy.getAddress(); + } + + /** + * Sets the {@code PersonName} of the {@code Person} that we are building. + */ + public PersonBuilder withPersonName(String personName) { + this.personName = new PersonName(personName); + return this; + } + + /** + * Sets the {@code Phone} of the {@code Person} that we are building. + */ + public PersonBuilder withPhone(String phone) { + this.phone = new Phone(phone); + return this; + } + + /** + * Sets the {@code Email} of the {@code Person} that we are building. + */ + public PersonBuilder withEmail(String email) { + this.email = new Email(email); + return this; + } + + /** + * Sets the {@code Address} of the {@code Person} that we are building. + */ + public PersonBuilder withAddress(String address) { + this.address = new Address(address); + return this; + } + + public Person build() { + return new Person(personName, phone, email, address); + } + +} diff --git a/src/test/java/seedu/address/testutil/ProjectUtil.java b/src/test/java/seedu/address/testutil/ProjectUtil.java index c8025bb7de4..9253fff77ac 100644 --- a/src/test/java/seedu/address/testutil/ProjectUtil.java +++ b/src/test/java/seedu/address/testutil/ProjectUtil.java @@ -9,8 +9,8 @@ import java.util.Set; -import seedu.address.logic.commands.AddCommand; -import seedu.address.logic.commands.EditCommand.EditProjectDescriptor; +import seedu.address.logic.commands.catalogue.AddCommand; +import seedu.address.logic.commands.catalogue.EditCommand.EditProjectDescriptor; import seedu.address.model.project.Project; import seedu.address.model.tag.ProjectTag; import seedu.address.model.task.Task; diff --git a/src/test/java/seedu/address/testutil/TypicalIndexes.java b/src/test/java/seedu/address/testutil/TypicalIndexes.java index 02359c1a59e..36de66cdeef 100644 --- a/src/test/java/seedu/address/testutil/TypicalIndexes.java +++ b/src/test/java/seedu/address/testutil/TypicalIndexes.java @@ -9,4 +9,6 @@ public class TypicalIndexes { public static final Index INDEX_FIRST_PROJECT = Index.fromOneBased(1); public static final Index INDEX_SECOND_PROJECT = Index.fromOneBased(2); public static final Index INDEX_THIRD_PROJECT = Index.fromOneBased(3); + public static final Index INDEX_FIRST_TASK = Index.fromOneBased(1); + public static final Index INDEX_SECOND_TASK = Index.fromOneBased(2); } diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java new file mode 100644 index 00000000000..be7a1e1cd27 --- /dev/null +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -0,0 +1,13 @@ +package seedu.address.testutil; + +import seedu.address.model.person.Person; + +/** + * A utility class containing a list of {@code Persons} objects to be used in tests. + */ +public class TypicalPersons { + public static final Person ALICE = new PersonBuilder().withPersonName("Alice Pauline").withPhone("12345678") + .withEmail("alicepauline@sample.com").withAddress("123, Jurong West Ave 6, #08-111").build(); + + // TODO: May add more instances +}