From e14df6ee2daa5bce9fc849fbacae51859a6e0cd9 Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 13 Oct 2023 19:32:27 +0800 Subject: [PATCH 01/10] Add pinned contacts interface --- README.md | 17 ++++--- build.gradle | 2 +- .../java/seedu/address/ui/MainWindow.java | 7 +++ .../address/ui/PinnedPersonListPanel.java | 49 ++++++++++++++++++ src/main/resources/view/MainWindow.fxml | 50 +++++++++++-------- .../resources/view/PinnedPersonListPanel.fxml | 8 +++ 6 files changed, 103 insertions(+), 30 deletions(-) create mode 100644 src/main/java/seedu/address/ui/PinnedPersonListPanel.java create mode 100644 src/main/resources/view/PinnedPersonListPanel.fxml diff --git a/README.md b/README.md index 1671c13b778..9b572a3183e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ -[![Java CI](https://github.com/AY2324S1-CS2103T-T12-4/tp/actions/workflows/gradle.yml/badge.svg)](https://github.com/AY2324S1-CS2103T-T12-4/tp/actions/workflows/gradle.yml) +[![CI Status](https://github.com/AY2324S1-CS2103T-T12-4/tp/actions/workflows/gradle.yml/badge.svg)](https://github.com/AY2324S1-CS2103T-T12-4/tp/actions) +[![codecov](https://codecov.io/gh/AY2324S1-CS2103T-T12-4/tp/graph/badge.svg?token=XRD2EIUJ8H)](https://codecov.io/gh/AY2324S1-CS2103T-T12-4/tp) ![Ui](docs/images/Ui.png) -* This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org). +- This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org). -* It is named MedBook, a brownfield project from the AddressBook-Level3. -* It can: - * streamline patient management for healthcare professionals - * simplify the process of accessing patients' contact information and medical records -* To access the User Guide, click [here](/docs/UserGuide.md) -* To access the Developer Guide, click [here](/docs/DeveloperGuide.md) +- It is named MedBook, a brownfield project from the AddressBook-Level3. +- It can: + - streamline patient management for healthcare professionals + - simplify the process of accessing patients' contact information and medical records +- To access the User Guide, click [here](/docs/UserGuide.md) +- To access the Developer Guide, click [here](/docs/DeveloperGuide.md) diff --git a/build.gradle b/build.gradle index a2951cc709e..81a62eac72c 100644 --- a/build.gradle +++ b/build.gradle @@ -66,7 +66,7 @@ dependencies { } shadowJar { - archiveFileName = 'addressbook.jar' + archiveFileName = 'medbook.jar' } defaultTasks 'clean', 'test' diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 79e74ef37c0..4f235c9ee44 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -34,6 +34,7 @@ public class MainWindow extends UiPart { private PersonListPanel personListPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; + private PinnedPersonListPanel pinnedPersonListPanel; @FXML private StackPane commandBoxPlaceholder; @@ -44,6 +45,9 @@ public class MainWindow extends UiPart { @FXML private StackPane personListPanelPlaceholder; + @FXML + private StackPane pinnedPersonListPanelPlaceholder; + @FXML private StackPane resultDisplayPlaceholder; @@ -113,6 +117,9 @@ void fillInnerParts() { personListPanel = new PersonListPanel(logic.getFilteredPersonList()); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + pinnedPersonListPanel = new PinnedPersonListPanel(logic.getFilteredPersonList()); + pinnedPersonListPanelPlaceholder.getChildren().add(pinnedPersonListPanel.getRoot()); + resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); diff --git a/src/main/java/seedu/address/ui/PinnedPersonListPanel.java b/src/main/java/seedu/address/ui/PinnedPersonListPanel.java new file mode 100644 index 00000000000..112f1dec360 --- /dev/null +++ b/src/main/java/seedu/address/ui/PinnedPersonListPanel.java @@ -0,0 +1,49 @@ +package seedu.address.ui; + +import java.util.logging.Logger; + +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.layout.Region; +import seedu.address.commons.core.LogsCenter; +import seedu.address.model.person.Person; + +/** + * Panel containing the list of pinned persons. + */ +public class PinnedPersonListPanel extends UiPart { + private static final String FXML = "PinnedPersonListPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(PinnedPersonListPanel.class); + + @FXML + private ListView pinnedPersonListView; + + /** + * Creates a {@code PinnedPersonListPanel} with the given {@code ObservableList}. + */ + public PinnedPersonListPanel(ObservableList pinnedPersonList) { + super(FXML); + pinnedPersonListView.setItems(pinnedPersonList); + pinnedPersonListView.setCellFactory(listView -> new PinnedPersonListViewCell()); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}. + */ + class PinnedPersonListViewCell extends ListCell { + @Override + protected void updateItem(Person person, boolean empty) { + super.updateItem(person, empty); + + if (empty || person == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(new PersonCard(person, getIndex() + 1).getRoot()); + } + } + } + +} diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index 7778f666a0a..17686881222 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -33,27 +33,35 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/PinnedPersonListPanel.fxml b/src/main/resources/view/PinnedPersonListPanel.fxml new file mode 100644 index 00000000000..e29159ec918 --- /dev/null +++ b/src/main/resources/view/PinnedPersonListPanel.fxml @@ -0,0 +1,8 @@ + + + + + + + + From d6e5e800c1aba0afaaf922b9e21fe9e644d2e96b Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 13 Oct 2023 22:11:32 +0800 Subject: [PATCH 02/10] Add pin and unpin logic and commands --- src/main/java/seedu/address/logic/Logic.java | 3 + .../seedu/address/logic/LogicManager.java | 5 ++ .../address/logic/commands/PinCommand.java | 73 +++++++++++++++++++ .../address/logic/commands/UnpinCommand.java | 73 +++++++++++++++++++ .../logic/parser/AddressBookParser.java | 8 ++ .../logic/parser/PinCommandParser.java | 29 ++++++++ .../logic/parser/UnpinCommandParser.java | 29 ++++++++ src/main/java/seedu/address/model/Model.java | 3 + .../seedu/address/model/ModelManager.java | 9 +++ .../seedu/address/model/person/Person.java | 19 +++++ .../java/seedu/address/ui/MainWindow.java | 2 +- .../logic/commands/AddCommandTest.java | 5 ++ 12 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 src/main/java/seedu/address/logic/commands/PinCommand.java create mode 100644 src/main/java/seedu/address/logic/commands/UnpinCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/PinCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/UnpinCommandParser.java diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 92cd8fa605a..5a11824ccc4 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -33,6 +33,9 @@ public interface Logic { /** Returns an unmodifiable view of the filtered list of persons */ ObservableList getFilteredPersonList(); + /** Returns an unmodifiable view of the pinned list of persons */ + ObservableList getPinnedPersonList(); + /** * Returns the user prefs' address book file path. */ diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 5aa3b91c7d0..8a15a15010b 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -71,6 +71,11 @@ public ObservableList getFilteredPersonList() { return model.getFilteredPersonList(); } + @Override + public ObservableList getPinnedPersonList() { + return model.getPinnedPersonList(); + } + @Override public Path getAddressBookFilePath() { return model.getAddressBookFilePath(); diff --git a/src/main/java/seedu/address/logic/commands/PinCommand.java b/src/main/java/seedu/address/logic/commands/PinCommand.java new file mode 100644 index 00000000000..716da16156a --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/PinCommand.java @@ -0,0 +1,73 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; + +import java.util.List; + +import seedu.address.commons.core.index.Index; +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.logic.Messages; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.person.Person; + +/** + * Pins the person identified using it's displayed index from the address book. + */ +public class PinCommand extends Command { + + public static final String COMMAND_WORD = "pin"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Pins the person identified by the index number used in the displayed person list.\n" + + "Parameters: INDEX (must be a positive integer)\n" + + "Example: " + COMMAND_WORD + " 1"; + + public static final String MESSAGE_PIN_PERSON_SUCCESS = "Pinned Person: %1$s"; + + private final Index targetIndex; + + public PinCommand(Index targetIndex) { + this.targetIndex = targetIndex; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredPersonList(); + + if (targetIndex.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + Person personToPin = lastShownList.get(targetIndex.getZeroBased()); + Person pinnedPerson = new Person(personToPin); + pinnedPerson.setPinned(true); + + model.setPerson(personToPin, pinnedPerson); + return new CommandResult(String.format(MESSAGE_PIN_PERSON_SUCCESS, Messages.format(personToPin))); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof PinCommand)) { + return false; + } + + PinCommand otherPinCommand = (PinCommand) other; + return targetIndex.equals(otherPinCommand.targetIndex); + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .add("targetIndex", targetIndex) + .toString(); + } +} + diff --git a/src/main/java/seedu/address/logic/commands/UnpinCommand.java b/src/main/java/seedu/address/logic/commands/UnpinCommand.java new file mode 100644 index 00000000000..5e3e98619f4 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/UnpinCommand.java @@ -0,0 +1,73 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; + +import java.util.List; + +import seedu.address.commons.core.index.Index; +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.logic.Messages; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.person.Person; + +/** + * Unpins the person identified using it's displayed index from the address book. + */ +public class UnpinCommand extends Command { + + public static final String COMMAND_WORD = "unpin"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Unpins the person identified by the index number used in the displayed pinned list.\n" + + "Parameters: INDEX (must be a positive integer)\n" + + "Example: " + COMMAND_WORD + " 1"; + + public static final String MESSAGE_UNPIN_PERSON_SUCCESS = "Unpinned Person: %1$s"; + + private final Index targetIndex; + + public UnpinCommand(Index targetIndex) { + this.targetIndex = targetIndex; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownPinnedList = model.getPinnedPersonList(); + + if (targetIndex.getZeroBased() >= lastShownPinnedList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + Person personToUnpin = lastShownPinnedList.get(targetIndex.getZeroBased()); + Person unpinnedPerson = new Person(personToUnpin); + unpinnedPerson.setPinned(false); + + model.setPerson(personToUnpin, unpinnedPerson); + return new CommandResult(String.format(MESSAGE_UNPIN_PERSON_SUCCESS, Messages.format(personToUnpin))); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof UnpinCommand)) { + return false; + } + + UnpinCommand otherUnpinCommand = (UnpinCommand) other; + return targetIndex.equals(otherUnpinCommand.targetIndex); + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .add("targetIndex", targetIndex) + .toString(); + } +} + diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 3149ee07e0b..5d9e4020c88 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -17,6 +17,8 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.PinCommand; +import seedu.address.logic.commands.UnpinCommand; import seedu.address.logic.parser.exceptions.ParseException; /** @@ -62,6 +64,12 @@ public Command parseCommand(String userInput) throws ParseException { case DeleteCommand.COMMAND_WORD: return new DeleteCommandParser().parse(arguments); + case PinCommand.COMMAND_WORD: + return new PinCommandParser().parse(arguments); + + case UnpinCommand.COMMAND_WORD: + return new UnpinCommandParser().parse(arguments); + case ClearCommand.COMMAND_WORD: return new ClearCommand(); diff --git a/src/main/java/seedu/address/logic/parser/PinCommandParser.java b/src/main/java/seedu/address/logic/parser/PinCommandParser.java new file mode 100644 index 00000000000..8ed7846388a --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/PinCommandParser.java @@ -0,0 +1,29 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.PinCommand; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new PinCommand object + */ +public class PinCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the PinCommand + * and returns a PinCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public PinCommand parse(String args) throws ParseException { + try { + Index index = ParserUtil.parseIndex(args); + return new PinCommand(index); + } catch (ParseException pe) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, PinCommand.MESSAGE_USAGE), pe); + } + } + +} diff --git a/src/main/java/seedu/address/logic/parser/UnpinCommandParser.java b/src/main/java/seedu/address/logic/parser/UnpinCommandParser.java new file mode 100644 index 00000000000..462f994f6f6 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/UnpinCommandParser.java @@ -0,0 +1,29 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.UnpinCommand; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new UnpinCommand object + */ +public class UnpinCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the UnpinCommand + * and returns a UnpinCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public UnpinCommand parse(String args) throws ParseException { + try { + Index index = ParserUtil.parseIndex(args); + return new UnpinCommand(index); + } catch (ParseException pe) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, UnpinCommand.MESSAGE_USAGE), pe); + } + } + +} diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index d54df471c1f..4c386b0c85e 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -84,4 +84,7 @@ public interface Model { * @throws NullPointerException if {@code predicate} is null. */ void updateFilteredPersonList(Predicate predicate); + + /** Returns an unmodifiable view of the pinned person list */ + ObservableList getPinnedPersonList(); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 57bc563fde6..d76ce954cfa 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -128,6 +128,13 @@ public void updateFilteredPersonList(Predicate predicate) { filteredPersons.setPredicate(predicate); } + @Override + public ObservableList getPinnedPersonList() { + FilteredList pinnedPersons = new FilteredList<>(this.addressBook.getPersonList()); + pinnedPersons.setPredicate(person -> person.isPinned()); + return pinnedPersons; + } + @Override public boolean equals(Object other) { if (other == this) { @@ -145,4 +152,6 @@ public boolean equals(Object other) { && filteredPersons.equals(otherModelManager.filteredPersons); } + + } diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index abe8c46b535..3fa84b6be07 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -24,6 +24,7 @@ public class Person { // Data fields private final Address address; private final Set tags = new HashSet<>(); + private boolean isPinned; /** * Every field must be present and not null. @@ -35,6 +36,16 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag this.email = email; this.address = address; this.tags.addAll(tags); + this.isPinned = false; + } + + public Person(Person otherPerson) { + this.name = otherPerson.getName(); + this.phone = otherPerson.getPhone(); + this.email = otherPerson.getEmail(); + this.address = otherPerson.getAddress(); + this.isPinned = otherPerson.isPinned(); + this.tags.addAll(otherPerson.getTags()); } public Name getName() { @@ -53,6 +64,14 @@ public Address getAddress() { return address; } + public boolean isPinned() { + return isPinned; + } + + public void setPinned(boolean isPinned) { + this.isPinned = isPinned; + } + /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 4f235c9ee44..9ad728a3e3a 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -117,7 +117,7 @@ void fillInnerParts() { personListPanel = new PersonListPanel(logic.getFilteredPersonList()); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); - pinnedPersonListPanel = new PinnedPersonListPanel(logic.getFilteredPersonList()); + pinnedPersonListPanel = new PinnedPersonListPanel(logic.getPinnedPersonList()); pinnedPersonListPanelPlaceholder.getChildren().add(pinnedPersonListPanel.getRoot()); resultDisplay = new ResultDisplay(); diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 90e8253f48e..812c4a99f59 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -157,6 +157,11 @@ public ObservableList getFilteredPersonList() { public void updateFilteredPersonList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + + @Override + public ObservableList getPinnedPersonList() { + throw new AssertionError("This method should not be called."); + } } /** From 6339334d0f962206f106d0bd2d46d7ea41738e16 Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 13 Oct 2023 23:30:44 +0800 Subject: [PATCH 03/10] Add documentation for Person copy constructor --- src/main/java/seedu/address/model/person/Person.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 3fa84b6be07..a8946bef899 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -39,6 +39,9 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag this.isPinned = false; } + /** + * Copy constructor. + */ public Person(Person otherPerson) { this.name = otherPerson.getName(); this.phone = otherPerson.getPhone(); From 45d094589f04c207467c186eb48e85ba3ad0ae1a Mon Sep 17 00:00:00 2001 From: Darren Date: Sat, 14 Oct 2023 15:44:37 +0800 Subject: [PATCH 04/10] Add Pin command tests --- .../address/logic/commands/EditCommand.java | 2 +- .../address/logic/commands/PinCommand.java | 4 +- .../address/logic/commands/UnpinCommand.java | 4 +- .../logic/parser/AddCommandParser.java | 2 +- .../seedu/address/model/person/Person.java | 23 +--- .../address/model/util/SampleDataUtil.java | 12 +- .../address/storage/JsonAdaptedPerson.java | 2 +- .../logic/commands/PinCommandTest.java | 113 ++++++++++++++++++ .../seedu/address/testutil/PersonBuilder.java | 13 +- 9 files changed, 142 insertions(+), 33 deletions(-) create mode 100644 src/test/java/seedu/address/logic/commands/PinCommandTest.java diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 4b581c7331e..7db62f264a9 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -101,7 +101,7 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); + return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, personToEdit.isPinned()); } @Override diff --git a/src/main/java/seedu/address/logic/commands/PinCommand.java b/src/main/java/seedu/address/logic/commands/PinCommand.java index 716da16156a..f8bf2632705 100644 --- a/src/main/java/seedu/address/logic/commands/PinCommand.java +++ b/src/main/java/seedu/address/logic/commands/PinCommand.java @@ -41,8 +41,8 @@ public CommandResult execute(Model model) throws CommandException { } Person personToPin = lastShownList.get(targetIndex.getZeroBased()); - Person pinnedPerson = new Person(personToPin); - pinnedPerson.setPinned(true); + Person pinnedPerson = new Person(personToPin.getName(), personToPin.getPhone(), personToPin.getEmail(), + personToPin.getAddress(), personToPin.getTags(), true); model.setPerson(personToPin, pinnedPerson); return new CommandResult(String.format(MESSAGE_PIN_PERSON_SUCCESS, Messages.format(personToPin))); diff --git a/src/main/java/seedu/address/logic/commands/UnpinCommand.java b/src/main/java/seedu/address/logic/commands/UnpinCommand.java index 5e3e98619f4..ce1db2dc5b1 100644 --- a/src/main/java/seedu/address/logic/commands/UnpinCommand.java +++ b/src/main/java/seedu/address/logic/commands/UnpinCommand.java @@ -41,8 +41,8 @@ public CommandResult execute(Model model) throws CommandException { } Person personToUnpin = lastShownPinnedList.get(targetIndex.getZeroBased()); - Person unpinnedPerson = new Person(personToUnpin); - unpinnedPerson.setPinned(false); + Person unpinnedPerson = new Person(personToUnpin.getName(), personToUnpin.getPhone(), personToUnpin.getEmail(), + personToUnpin.getAddress(), personToUnpin.getTags(), false); model.setPerson(personToUnpin, unpinnedPerson); return new CommandResult(String.format(MESSAGE_UNPIN_PERSON_SUCCESS, Messages.format(personToUnpin))); diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 4ff1a97ed77..a318f36ddd6 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -45,7 +45,7 @@ public AddCommand parse(String args) throws ParseException { Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person person = new Person(name, phone, email, address, tagList); + Person person = new Person(name, phone, email, address, tagList, false); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index a8946bef899..64b2ac7bd8b 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -29,26 +29,14 @@ public class Person { /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags) { + public Person(Name name, Phone phone, Email email, Address address, Set tags, boolean isPinned) { requireAllNonNull(name, phone, email, address, tags); this.name = name; this.phone = phone; this.email = email; this.address = address; this.tags.addAll(tags); - this.isPinned = false; - } - - /** - * Copy constructor. - */ - public Person(Person otherPerson) { - this.name = otherPerson.getName(); - this.phone = otherPerson.getPhone(); - this.email = otherPerson.getEmail(); - this.address = otherPerson.getAddress(); - this.isPinned = otherPerson.isPinned(); - this.tags.addAll(otherPerson.getTags()); + this.isPinned = isPinned; } public Name getName() { @@ -71,10 +59,6 @@ public boolean isPinned() { return isPinned; } - public void setPinned(boolean isPinned) { - this.isPinned = isPinned; - } - /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. @@ -116,7 +100,8 @@ public boolean equals(Object other) { && phone.equals(otherPerson.phone) && email.equals(otherPerson.email) && address.equals(otherPerson.address) - && tags.equals(otherPerson.tags); + && tags.equals(otherPerson.tags) + && isPinned == otherPerson.isPinned; } @Override diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 1806da4facf..45f8a3023cd 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -21,22 +21,22 @@ public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"), - getTagSet("friends")), + getTagSet("friends"), true), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends")), + getTagSet("colleagues", "friends"), false), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours")), + getTagSet("neighbours"), false), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family")), + getTagSet("family"), false), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates")), + getTagSet("classmates"), false), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues")) + getTagSet("colleagues"), false) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index bd1ca0f56c8..e47bc835da9 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -103,7 +103,7 @@ public Person toModelType() throws IllegalValueException { final Address modelAddress = new Address(address); final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags); + return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, false); } } diff --git a/src/test/java/seedu/address/logic/commands/PinCommandTest.java b/src/test/java/seedu/address/logic/commands/PinCommandTest.java new file mode 100644 index 00000000000..9080fc176ba --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/PinCommandTest.java @@ -0,0 +1,113 @@ +package seedu.address.logic.commands; + +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.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.Test; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; +import seedu.address.model.AddressBook; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.Person; +import seedu.address.testutil.PersonBuilder; + +/** + * Contains integration tests (interaction with the Model) and unit tests for PinCommand. + */ +public class PinCommandTest { + + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void execute_validIndexUnfilteredList_success() { + Person personToPin = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + Person pinnedPerson = new PersonBuilder(personToPin).withIsPinned(true).build(); + PinCommand pinCommand = new PinCommand(INDEX_FIRST_PERSON); + + String expectedMessage = String.format(PinCommand.MESSAGE_PIN_PERSON_SUCCESS, Messages.format(personToPin)); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.setPerson(model.getFilteredPersonList().get(0), pinnedPerson); + + assertCommandSuccess(pinCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_invalidIndexUnfilteredList_throwsCommandException() { + Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); + PinCommand pinCommand = new PinCommand(outOfBoundIndex); + + assertCommandFailure(pinCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + @Test + public void execute_validIndexFilteredList_success() { + showPersonAtIndex(model, INDEX_FIRST_PERSON); + + Person personToPin = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + Person pinnedPerson = new PersonBuilder(personToPin).withIsPinned(true).build(); + PinCommand pinCommand = new PinCommand(INDEX_FIRST_PERSON); + + String expectedMessage = String.format(PinCommand.MESSAGE_PIN_PERSON_SUCCESS, Messages.format(personToPin)); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + showPersonAtIndex(expectedModel, INDEX_FIRST_PERSON); + expectedModel.setPerson(model.getFilteredPersonList().get(0), pinnedPerson); + assertCommandSuccess(pinCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_invalidIndexFilteredList_throwsCommandException() { + showPersonAtIndex(model, INDEX_FIRST_PERSON); + + Index outOfBoundIndex = INDEX_SECOND_PERSON; + // ensures that outOfBoundIndex is still in bounds of address book list + assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getPersonList().size()); + + PinCommand pinCommand = new PinCommand(outOfBoundIndex); + + assertCommandFailure(pinCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + + @Test + public void equals() { + PinCommand pinFirstCommand = new PinCommand(INDEX_FIRST_PERSON); + PinCommand pinSecondCommand = new PinCommand(INDEX_SECOND_PERSON); + + // same object -> returns true + assertTrue(pinFirstCommand.equals(pinFirstCommand)); + + // same values -> returns true + PinCommand deleteFirstCommandCopy = new PinCommand(INDEX_FIRST_PERSON); + assertTrue(pinFirstCommand.equals(deleteFirstCommandCopy)); + + // different types -> returns false + assertFalse(pinFirstCommand.equals(1)); + + // null -> returns false + assertFalse(pinFirstCommand.equals(null)); + + // different person -> returns false + assertFalse(pinFirstCommand.equals(pinSecondCommand)); + } + + @Test + public void toStringMethod() { + Index targetIndex = Index.fromOneBased(1); + PinCommand pinCommand = new PinCommand(targetIndex); + String expected = PinCommand.class.getCanonicalName() + "{targetIndex=" + targetIndex + "}"; + assertEquals(expected, pinCommand.toString()); + } + +} diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index 6be381d39ba..e92c97db508 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -26,6 +26,7 @@ public class PersonBuilder { private Email email; private Address address; private Set tags; + private boolean isPinned; /** * Creates a {@code PersonBuilder} with the default details. @@ -36,6 +37,7 @@ public PersonBuilder() { email = new Email(DEFAULT_EMAIL); address = new Address(DEFAULT_ADDRESS); tags = new HashSet<>(); + isPinned = false; } /** @@ -47,6 +49,7 @@ public PersonBuilder(Person personToCopy) { email = personToCopy.getEmail(); address = personToCopy.getAddress(); tags = new HashSet<>(personToCopy.getTags()); + isPinned = personToCopy.isPinned(); } /** @@ -89,8 +92,16 @@ public PersonBuilder withEmail(String email) { return this; } + /** + * Sets the {@code isPinned} of the {@code Person} that we are building. + */ + public PersonBuilder withIsPinned(boolean isPinned) { + this.isPinned = isPinned; + return this; + } + public Person build() { - return new Person(name, phone, email, address, tags); + return new Person(name, phone, email, address, tags, isPinned); } } From 71a4bcc576f472b4987bbacd94017bb86e2555cc Mon Sep 17 00:00:00 2001 From: Darren Date: Sat, 14 Oct 2023 16:02:34 +0800 Subject: [PATCH 05/10] Add Unpin command tests --- .../logic/commands/PinCommandTest.java | 4 +- .../logic/commands/UnpinCommandTest.java | 82 +++++++++++++++++++ .../logic/parser/PinCommandParserTest.java | 32 ++++++++ .../logic/parser/UnpinCommandParserTest.java | 32 ++++++++ .../seedu/address/model/ModelManagerTest.java | 5 ++ .../address/testutil/TypicalPersons.java | 2 +- 6 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 src/test/java/seedu/address/logic/commands/UnpinCommandTest.java create mode 100644 src/test/java/seedu/address/logic/parser/PinCommandParserTest.java create mode 100644 src/test/java/seedu/address/logic/parser/UnpinCommandParserTest.java diff --git a/src/test/java/seedu/address/logic/commands/PinCommandTest.java b/src/test/java/seedu/address/logic/commands/PinCommandTest.java index 9080fc176ba..d25c7640305 100644 --- a/src/test/java/seedu/address/logic/commands/PinCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/PinCommandTest.java @@ -89,8 +89,8 @@ public void equals() { assertTrue(pinFirstCommand.equals(pinFirstCommand)); // same values -> returns true - PinCommand deleteFirstCommandCopy = new PinCommand(INDEX_FIRST_PERSON); - assertTrue(pinFirstCommand.equals(deleteFirstCommandCopy)); + PinCommand unpinFirstCommandCopy = new PinCommand(INDEX_FIRST_PERSON); + assertTrue(pinFirstCommand.equals(unpinFirstCommandCopy)); // different types -> returns false assertFalse(pinFirstCommand.equals(1)); diff --git a/src/test/java/seedu/address/logic/commands/UnpinCommandTest.java b/src/test/java/seedu/address/logic/commands/UnpinCommandTest.java new file mode 100644 index 00000000000..1faaff9ef43 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/UnpinCommandTest.java @@ -0,0 +1,82 @@ +package seedu.address.logic.commands; + +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.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.Test; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; +import seedu.address.model.AddressBook; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.Person; +import seedu.address.testutil.PersonBuilder; + +/** + * Contains integration tests (interaction with the Model) and unit tests for UnpinCommand. + */ +public class UnpinCommandTest { + + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void execute_validIndex_success() { + Person personToUnpin = model.getPinnedPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + Person unpinnedPerson = new PersonBuilder(personToUnpin).withIsPinned(false).build(); + UnpinCommand unpinCommand = new UnpinCommand(INDEX_FIRST_PERSON); + + String expectedMessage = String.format(UnpinCommand.MESSAGE_UNPIN_PERSON_SUCCESS, Messages.format(personToUnpin)); + + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.setPerson(model.getPinnedPersonList().get(0), unpinnedPerson); + + assertCommandSuccess(unpinCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_invalidIndexUnfilteredList_throwsCommandException() { + Index outOfBoundIndex = Index.fromOneBased(model.getPinnedPersonList().size() + 1); + UnpinCommand unpinCommand = new UnpinCommand(outOfBoundIndex); + + assertCommandFailure(unpinCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + @Test + public void equals() { + UnpinCommand unpinFirstCommand = new UnpinCommand(INDEX_FIRST_PERSON); + UnpinCommand unpinSecondCommand = new UnpinCommand(INDEX_SECOND_PERSON); + + // same object -> returns true + assertTrue(unpinFirstCommand.equals(unpinFirstCommand)); + + // same values -> returns true + UnpinCommand unpinFirstCommandCopy = new UnpinCommand(INDEX_FIRST_PERSON); + assertTrue(unpinFirstCommand.equals(unpinFirstCommandCopy)); + + // different types -> returns false + assertFalse(unpinFirstCommand.equals(1)); + + // null -> returns false + assertFalse(unpinFirstCommand.equals(null)); + + // different person -> returns false + assertFalse(unpinFirstCommand.equals(unpinSecondCommand)); + } + + @Test + public void toStringMethod() { + Index targetIndex = Index.fromOneBased(1); + UnpinCommand unpinCommand = new UnpinCommand(targetIndex); + String expected = UnpinCommand.class.getCanonicalName() + "{targetIndex=" + targetIndex + "}"; + assertEquals(expected, unpinCommand.toString()); + } + +} diff --git a/src/test/java/seedu/address/logic/parser/PinCommandParserTest.java b/src/test/java/seedu/address/logic/parser/PinCommandParserTest.java new file mode 100644 index 00000000000..fe50be9d097 --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/PinCommandParserTest.java @@ -0,0 +1,32 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.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_PERSON; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.PinCommand; + +/** + * As we are only doing white-box testing, our test cases do not cover path variations + * outside of the PinCommand code. For example, inputs "1" and "1 abc" take the + * same path through the PinCommand, 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 PinCommandParserTest { + + private PinCommandParser parser = new PinCommandParser(); + + @Test + public void parse_validArgs_returnsPinCommand() { + assertParseSuccess(parser, "1", new PinCommand(INDEX_FIRST_PERSON)); + } + + @Test + public void parse_invalidArgs_throwsParseException() { + assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, PinCommand.MESSAGE_USAGE)); + } +} diff --git a/src/test/java/seedu/address/logic/parser/UnpinCommandParserTest.java b/src/test/java/seedu/address/logic/parser/UnpinCommandParserTest.java new file mode 100644 index 00000000000..84e1759f77e --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/UnpinCommandParserTest.java @@ -0,0 +1,32 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.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_PERSON; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.UnpinCommand; + +/** + * As we are only doing white-box testing, our test cases do not cover path variations + * outside of the UnpinCommand code. For example, inputs "1" and "1 abc" take the + * same path through the UnpinCommand, 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 UnpinCommandParserTest { + + private UnpinCommandParser parser = new UnpinCommandParser(); + + @Test + public void parse_validArgs_returnsUnpinCommand() { + assertParseSuccess(parser, "1", new UnpinCommand(INDEX_FIRST_PERSON)); + } + + @Test + public void parse_invalidArgs_throwsParseException() { + assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, UnpinCommand.MESSAGE_USAGE)); + } +} diff --git a/src/test/java/seedu/address/model/ModelManagerTest.java b/src/test/java/seedu/address/model/ModelManagerTest.java index 2cf1418d116..b89dbb4f344 100644 --- a/src/test/java/seedu/address/model/ModelManagerTest.java +++ b/src/test/java/seedu/address/model/ModelManagerTest.java @@ -93,6 +93,11 @@ public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException assertThrows(UnsupportedOperationException.class, () -> modelManager.getFilteredPersonList().remove(0)); } + @Test + public void getPinnedPersonList_modifyList_throwsUnsupportedOperationException() { + assertThrows(UnsupportedOperationException.class, () -> modelManager.getPinnedPersonList().remove(0)); + } + @Test public void equals() { AddressBook addressBook = new AddressBookBuilder().withPerson(ALICE).withPerson(BENSON).build(); diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java index fec76fb7129..f80354178fd 100644 --- a/src/test/java/seedu/address/testutil/TypicalPersons.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -26,7 +26,7 @@ public class TypicalPersons { public static final Person ALICE = new PersonBuilder().withName("Alice Pauline") .withAddress("123, Jurong West Ave 6, #08-111").withEmail("alice@example.com") .withPhone("94351253") - .withTags("friends").build(); + .withTags("friends").withIsPinned(true).build(); public static final Person BENSON = new PersonBuilder().withName("Benson Meier") .withAddress("311, Clementi Ave 2, #02-25") .withEmail("johnd@example.com").withPhone("98765432") From f91649c58d88b724703e902b169820cce689d7e0 Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 15 Oct 2023 20:03:23 +0800 Subject: [PATCH 06/10] Modify existing command parameters --- .../java/seedu/address/logic/commands/EditCommand.java | 2 +- .../java/seedu/address/logic/commands/PinCommand.java | 4 ++-- .../java/seedu/address/logic/commands/UnpinCommand.java | 4 ++-- src/main/java/seedu/address/model/person/Person.java | 4 ---- .../address/testutil/EditPersonDescriptorBuilder.java | 1 - src/test/java/seedu/address/testutil/PersonBuilder.java | 9 --------- 6 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index f5b8acbc16d..3c76edd2044 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -38,7 +38,7 @@ */ public class EditCommand extends Command { - public static final String COMMAND_WORD = "editPatient"; + public static final String COMMAND_WORD = "editpatient"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " + "by the index number used in the displayed person list. " diff --git a/src/main/java/seedu/address/logic/commands/PinCommand.java b/src/main/java/seedu/address/logic/commands/PinCommand.java index f8bf2632705..5634e02b2c3 100644 --- a/src/main/java/seedu/address/logic/commands/PinCommand.java +++ b/src/main/java/seedu/address/logic/commands/PinCommand.java @@ -41,8 +41,8 @@ public CommandResult execute(Model model) throws CommandException { } Person personToPin = lastShownList.get(targetIndex.getZeroBased()); - Person pinnedPerson = new Person(personToPin.getName(), personToPin.getPhone(), personToPin.getEmail(), - personToPin.getAddress(), personToPin.getTags(), true); + Person pinnedPerson = new Person(personToPin.getName(), personToPin.getEmail(), personToPin.getPhone(), personToPin.getGender(), + personToPin.getAge(), personToPin.getBloodType(), personToPin.getAllergies(), true); model.setPerson(personToPin, pinnedPerson); return new CommandResult(String.format(MESSAGE_PIN_PERSON_SUCCESS, Messages.format(personToPin))); diff --git a/src/main/java/seedu/address/logic/commands/UnpinCommand.java b/src/main/java/seedu/address/logic/commands/UnpinCommand.java index ce1db2dc5b1..d78aea25e30 100644 --- a/src/main/java/seedu/address/logic/commands/UnpinCommand.java +++ b/src/main/java/seedu/address/logic/commands/UnpinCommand.java @@ -41,8 +41,8 @@ public CommandResult execute(Model model) throws CommandException { } Person personToUnpin = lastShownPinnedList.get(targetIndex.getZeroBased()); - Person unpinnedPerson = new Person(personToUnpin.getName(), personToUnpin.getPhone(), personToUnpin.getEmail(), - personToUnpin.getAddress(), personToUnpin.getTags(), false); + Person unpinnedPerson = new Person(personToUnpin.getName(), personToUnpin.getEmail(), personToUnpin.getPhone(), personToUnpin.getGender(), + personToUnpin.getAge(), personToUnpin.getBloodType(), personToUnpin.getAllergies(), false); model.setPerson(personToUnpin, unpinnedPerson); return new CommandResult(String.format(MESSAGE_UNPIN_PERSON_SUCCESS, Messages.format(personToUnpin))); diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index c07afe2c172..e60e614efb4 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -60,10 +60,6 @@ public boolean isPinned() { return isPinned; } - public boolean isPinned() { - return isPinned; - } - public Age getAge() { return age; } diff --git a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java index 5aac3358e8e..25ff4b60992 100644 --- a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java @@ -6,7 +6,6 @@ import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; import seedu.address.model.person.*; -import seedu.address.model.tag.Tag; /** * A utility class to help with building EditPersonDescriptor objects. diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index 5b5d0afab09..aa5304068a8 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -4,7 +4,6 @@ import java.util.Set; import seedu.address.model.person.*; -import seedu.address.model.tag.Tag; import seedu.address.model.util.SampleDataUtil; /** @@ -121,14 +120,6 @@ public PersonBuilder withIsPinned(boolean isPinned) { return this; } - /** - * Sets the {@code isPinned} of the {@code Person} that we are building. - */ - public PersonBuilder withIsPinned(boolean isPinned) { - this.isPinned = isPinned; - return this; - } - public Person build() { return new Person(name, email, phone, gender, age, bloodType, allergies, isPinned); } From 43446c60d14ef0a54a69aa23c1b366c0caa83db4 Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 15 Oct 2023 20:49:59 +0800 Subject: [PATCH 07/10] Fix editcommand --- src/main/java/seedu/address/logic/commands/EditCommand.java | 2 +- .../java/seedu/address/logic/parser/ParserUtilTest.java | 2 +- src/test/java/seedu/address/testutil/PersonBuilder.java | 2 +- src/test/java/seedu/address/testutil/PersonUtil.java | 1 - src/test/java/seedu/address/testutil/TypicalPersons.java | 6 +++--- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 3c76edd2044..ec8fc7f9be4 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -150,7 +150,7 @@ public static class EditPersonDescriptor { private Gender gender; private Age age; private BloodType bloodType; - private Set allergies = new HashSet<>(); + private Set allergies; public EditPersonDescriptor() {} diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index a0770025633..6d8ddceaccc 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -38,7 +38,7 @@ public class ParserUtilTest { private static final String VALID_GENDER = "M"; private static final int VALID_AGE = 10; private static final String VALID_AGE_STRING = "10"; - private static final String VALID_BLOODTYPE = "A"; + private static final String VALID_BLOODTYPE = "A+"; private static final String VALID_ALLERGY_1 = "Nuts"; private static final String VALID_ALLERGY_2 = "Coconut"; diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index aa5304068a8..59dc339303b 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -16,7 +16,7 @@ public class PersonBuilder { public static final String DEFAULT_PHONE = "85355255"; public static final String DEFAULT_GENDER = "F"; public static final int DEFAULT_AGE = 21; - public static final String DEFAULT_BLOODTYPE = "O"; + public static final String DEFAULT_BLOODTYPE = "O+"; public static final String DEFAULT_ALLERGY = "Ants"; private Name name; diff --git a/src/test/java/seedu/address/testutil/PersonUtil.java b/src/test/java/seedu/address/testutil/PersonUtil.java index 87c1d88dfa5..aa71fad9bd2 100644 --- a/src/test/java/seedu/address/testutil/PersonUtil.java +++ b/src/test/java/seedu/address/testutil/PersonUtil.java @@ -6,7 +6,6 @@ import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; import seedu.address.model.person.Allergy; import seedu.address.model.person.Person; -import seedu.address.model.tag.Tag; import static seedu.address.logic.parser.CliSyntax.*; diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java index 58dd5b15d1f..049d5b99dad 100644 --- a/src/test/java/seedu/address/testutil/TypicalPersons.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -60,7 +60,7 @@ public class TypicalPersons { .withPhone("9482442") .withGender("M") .withAge(30) - .withBloodType("O").build(); + .withBloodType("O+").build(); // Manually added public static final Person HOON = new PersonBuilder().withName("Hoon Meier") @@ -68,13 +68,13 @@ public class TypicalPersons { .withPhone("8482424") .withGender("M") .withAge(30) - .withBloodType("A").build(); + .withBloodType("A+").build(); public static final Person IDA = new PersonBuilder().withName("Ida Mueller") .withEmail("hans@example.com") .withPhone("8482131") .withGender("M") .withAge(33) - .withBloodType("B").build(); + .withBloodType("B+").build(); // Manually added - Person's details found in {@code CommandTestUtil} public static final Person AMY = new PersonBuilder().withName(VALID_NAME_AMY) From dee3ed22aaf81c6dbacfe8a38b96b384ea34a69c Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 15 Oct 2023 20:52:35 +0800 Subject: [PATCH 08/10] Fix styling --- docs/team/ryanongwx.md | 14 +++++++------- src/main/resources/view/PersonListCard.fxml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/team/ryanongwx.md b/docs/team/ryanongwx.md index 19d95953f5c..82f615df893 100644 --- a/docs/team/ryanongwx.md +++ b/docs/team/ryanongwx.md @@ -5,16 +5,16 @@ ### Project: MedBook -* **New Feature**: +- **New Feature**: -* **Code contributed**: +- **Code contributed**: -* **Project management**: +- **Project management**: -* **Enhancements to existing features**: +- **Enhancements to existing features**: -* **Documentation**: +- **Documentation**: -* **Community**: +- **Community**: -* **Tools**: +- **Tools**: diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index 2b4548da331..33e6540854d 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -52,4 +52,4 @@ - \ No newline at end of file + From 7d1929ea8989b9f395b2241417a920487f2d9249 Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 15 Oct 2023 20:55:33 +0800 Subject: [PATCH 09/10] Fix styling --- src/main/java/seedu/address/logic/commands/PinCommand.java | 5 +++-- src/main/java/seedu/address/logic/commands/UnpinCommand.java | 5 +++-- src/main/java/seedu/address/storage/JsonAdaptedPerson.java | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/PinCommand.java b/src/main/java/seedu/address/logic/commands/PinCommand.java index 5634e02b2c3..cd3c3bb5d8c 100644 --- a/src/main/java/seedu/address/logic/commands/PinCommand.java +++ b/src/main/java/seedu/address/logic/commands/PinCommand.java @@ -41,8 +41,9 @@ public CommandResult execute(Model model) throws CommandException { } Person personToPin = lastShownList.get(targetIndex.getZeroBased()); - Person pinnedPerson = new Person(personToPin.getName(), personToPin.getEmail(), personToPin.getPhone(), personToPin.getGender(), - personToPin.getAge(), personToPin.getBloodType(), personToPin.getAllergies(), true); + Person pinnedPerson = new Person(personToPin.getName(), personToPin.getEmail(), personToPin.getPhone(), + personToPin.getGender(), personToPin.getAge(), personToPin.getBloodType(), personToPin.getAllergies(), + true); model.setPerson(personToPin, pinnedPerson); return new CommandResult(String.format(MESSAGE_PIN_PERSON_SUCCESS, Messages.format(personToPin))); diff --git a/src/main/java/seedu/address/logic/commands/UnpinCommand.java b/src/main/java/seedu/address/logic/commands/UnpinCommand.java index d78aea25e30..e4d90ac9df3 100644 --- a/src/main/java/seedu/address/logic/commands/UnpinCommand.java +++ b/src/main/java/seedu/address/logic/commands/UnpinCommand.java @@ -41,8 +41,9 @@ public CommandResult execute(Model model) throws CommandException { } Person personToUnpin = lastShownPinnedList.get(targetIndex.getZeroBased()); - Person unpinnedPerson = new Person(personToUnpin.getName(), personToUnpin.getEmail(), personToUnpin.getPhone(), personToUnpin.getGender(), - personToUnpin.getAge(), personToUnpin.getBloodType(), personToUnpin.getAllergies(), false); + Person unpinnedPerson = new Person(personToUnpin.getName(), personToUnpin.getEmail(), personToUnpin.getPhone(), + personToUnpin.getGender(), personToUnpin.getAge(), personToUnpin.getBloodType(), + personToUnpin.getAllergies(), false); model.setPerson(personToUnpin, unpinnedPerson); return new CommandResult(String.format(MESSAGE_UNPIN_PERSON_SUCCESS, Messages.format(personToUnpin))); diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index 5ee4d1f66ef..1def40fb6af 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -130,7 +130,8 @@ public Person toModelType() throws IllegalValueException { final BloodType modelBloodType = new BloodType(bloodType); final Set modelAllergies = new HashSet<>(allergiesList); - return new Person(modelName, modelEmail, modelPhone, modelGender, modelAge, modelBloodType, modelAllergies, false); + return new Person(modelName, modelEmail, modelPhone, modelGender, modelAge, modelBloodType, modelAllergies, + false); } } From e29024257fe2157a7995e7a1c52c74aee0a84db7 Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 15 Oct 2023 21:19:01 +0800 Subject: [PATCH 10/10] Fix test styling --- .../seedu/address/logic/LogicManagerTest.java | 10 ++--- .../logic/commands/CommandTestUtil.java | 12 +++-- .../logic/commands/EditCommandTest.java | 2 - .../commands/EditPersonDescriptorTest.java | 10 ++--- .../logic/commands/UnpinCommandTest.java | 3 +- .../logic/parser/AddCommandParserTest.java | 44 +++++++++++++++++-- .../logic/parser/EditCommandParserTest.java | 15 ++++--- .../address/logic/parser/ParserUtilTest.java | 6 ++- .../seedu/address/model/AddressBookTest.java | 2 +- .../address/model/person/PersonTest.java | 8 +++- .../model/person/UniquePersonListTest.java | 3 +- .../storage/JsonAdaptedPersonTest.java | 2 +- .../testutil/EditPersonDescriptorBuilder.java | 9 +++- .../seedu/address/testutil/PersonBuilder.java | 9 +++- .../seedu/address/testutil/PersonUtil.java | 14 ++++-- .../address/testutil/TypicalPersons.java | 18 ++++++-- 16 files changed, 126 insertions(+), 41 deletions(-) diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index a3d3944ddcb..8758ba16f88 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -3,13 +3,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; -import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.GENDER_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.AGE_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.BLOODTYPE_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.ALLERGY_DESC_DUST; +import static seedu.address.logic.commands.CommandTestUtil.BLOODTYPE_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.GENDER_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalPersons.AMY; diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 0d4fbfb4935..2469f4f86a8 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -2,7 +2,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.parser.CliSyntax.*; +import static seedu.address.logic.parser.CliSyntax.PREFIX_AGE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ALLERGIES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_BLOODTYPE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.testutil.Assert.assertThrows; import java.util.ArrayList; @@ -58,7 +64,7 @@ public class CommandTestUtil { public static final String INVALID_GENDER_DESC = " " + PREFIX_GENDER + "A"; // 'A' not allowed in gender public static final String INVALID_AGE_DESC = " " + PREFIX_AGE + "0"; // age must be more than 0 public static final String INVALID_BLOODTYPE_DESC = " " + PREFIX_BLOODTYPE + "G"; // 'G' not allowed in bloodtype - public static final String INVALID_ALLERGY_DESC = " " + PREFIX_ALLERGIES + "Peanuts*"; // '*' not allowed in allergies + public static final String INVALID_ALLERGY_DESC = " " + PREFIX_ALLERGIES + "Peanuts*"; public static final String PREAMBLE_WHITESPACE = "\t \r \n"; public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble"; @@ -74,7 +80,7 @@ public class CommandTestUtil { DESC_BOB = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB) .withEmail(VALID_EMAIL_BOB).withPhone(VALID_PHONE_BOB).withGender(VALID_GENDER_BOB) .withAge(VALID_AGE_BOB).withBloodType(VALID_BLOODTYPE_BOB) - .withAllergies(VALID_ALLERGY_DUST ,VALID_ALLERGY_PEANUTS).build(); + .withAllergies(VALID_ALLERGY_DUST, VALID_ALLERGY_PEANUTS).build(); } /** diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 68ac6787158..73338768062 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -3,7 +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.commands.CommandTestUtil.DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_ALLERGY_DUST; @@ -12,7 +11,6 @@ import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; - import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; diff --git a/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java b/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java index 45f9c221d4e..4fc9ca65a86 100644 --- a/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java +++ b/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java @@ -5,13 +5,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_AGE_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_BLOODTYPE_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_ALLERGY_PEANUTS; +import static seedu.address.logic.commands.CommandTestUtil.VALID_BLOODTYPE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; import org.junit.jupiter.api.Test; diff --git a/src/test/java/seedu/address/logic/commands/UnpinCommandTest.java b/src/test/java/seedu/address/logic/commands/UnpinCommandTest.java index 1faaff9ef43..53839b7ebda 100644 --- a/src/test/java/seedu/address/logic/commands/UnpinCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/UnpinCommandTest.java @@ -33,7 +33,8 @@ public void execute_validIndex_success() { Person unpinnedPerson = new PersonBuilder(personToUnpin).withIsPinned(false).build(); UnpinCommand unpinCommand = new UnpinCommand(INDEX_FIRST_PERSON); - String expectedMessage = String.format(UnpinCommand.MESSAGE_UNPIN_PERSON_SUCCESS, Messages.format(personToUnpin)); + String expectedMessage = String.format(UnpinCommand.MESSAGE_UNPIN_PERSON_SUCCESS, + Messages.format(personToUnpin)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setPerson(model.getPinnedPersonList().get(0), unpinnedPerson); diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java index 95dd7bca00c..29209279b20 100644 --- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java @@ -1,7 +1,37 @@ package seedu.address.logic.parser; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.commands.CommandTestUtil.*; +import static seedu.address.logic.commands.CommandTestUtil.AGE_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.AGE_DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.ALLERGY_DESC_DUST; +import static seedu.address.logic.commands.CommandTestUtil.ALLERGY_DESC_PEANUTS; +import static seedu.address.logic.commands.CommandTestUtil.BLOODTYPE_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.BLOODTYPE_DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.GENDER_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.GENDER_DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_AGE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_ALLERGY_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_BLOODTYPE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_GENDER_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_PHONE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY; +import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_WHITESPACE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_AGE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_ALLERGY_DUST; +import static seedu.address.logic.commands.CommandTestUtil.VALID_ALLERGY_PEANUTS; +import static seedu.address.logic.commands.CommandTestUtil.VALID_BLOODTYPE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; import static seedu.address.logic.parser.CliSyntax.PREFIX_AGE; import static seedu.address.logic.parser.CliSyntax.PREFIX_BLOODTYPE; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; @@ -17,7 +47,14 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.AddCommand; -import seedu.address.model.person.*; +import seedu.address.model.person.Age; +import seedu.address.model.person.Allergy; +import seedu.address.model.person.BloodType; +import seedu.address.model.person.Email; +import seedu.address.model.person.Gender; +import seedu.address.model.person.Name; +import seedu.address.model.person.Person; +import seedu.address.model.person.Phone; import seedu.address.testutil.PersonBuilder; public class AddCommandParserTest { @@ -34,7 +71,8 @@ public void parse_allFieldsPresent_success() { // multiple tags - all accepted - Person expectedPersonMultipleTags = new PersonBuilder(BOB).withAllergies(VALID_ALLERGY_DUST, VALID_ALLERGY_PEANUTS) + Person expectedPersonMultipleTags = new PersonBuilder(BOB).withAllergies(VALID_ALLERGY_DUST, + VALID_ALLERGY_PEANUTS) .build(); assertParseSuccess(parser, NAME_DESC_BOB + EMAIL_DESC_BOB + PHONE_DESC_BOB + GENDER_DESC_BOB diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index 19a1b7e6496..13f945b2dbf 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -1,8 +1,8 @@ package seedu.address.logic.parser; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.commands.CommandTestUtil.AGE_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.ALLERGY_DESC_DUST; import static seedu.address.logic.commands.CommandTestUtil.ALLERGY_DESC_PEANUTS; -import static seedu.address.logic.commands.CommandTestUtil.AGE_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.BLOODTYPE_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_BOB; @@ -25,7 +25,6 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_AMY; - import static seedu.address.logic.parser.CliSyntax.PREFIX_ALLERGIES; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; @@ -49,7 +48,6 @@ import seedu.address.model.person.Gender; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; - import seedu.address.testutil.EditPersonDescriptorBuilder; public class EditCommandParserTest { @@ -103,13 +101,16 @@ public void parse_invalidValue_failure() { // while parsing {@code PREFIX_TAG} alone will reset the tags of the {@code Person} being edited, // parsing it together with a valid tag results in error - assertParseFailure(parser, "1" + ALLERGY_DESC_DUST + ALLERGY_DESC_PEANUTS + ALLERGY_EMPTY, Allergy.MESSAGE_CONSTRAINTS); - assertParseFailure(parser, "1" + ALLERGY_DESC_DUST + ALLERGY_EMPTY + ALLERGY_DESC_PEANUTS, Allergy.MESSAGE_CONSTRAINTS); - assertParseFailure(parser, "1" + ALLERGY_EMPTY + ALLERGY_DESC_DUST + ALLERGY_DESC_PEANUTS, Allergy.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + ALLERGY_DESC_DUST + ALLERGY_DESC_PEANUTS + ALLERGY_EMPTY, + Allergy.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + ALLERGY_DESC_DUST + ALLERGY_EMPTY + ALLERGY_DESC_PEANUTS, + Allergy.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + ALLERGY_EMPTY + ALLERGY_DESC_DUST + ALLERGY_DESC_PEANUTS, + Allergy.MESSAGE_CONSTRAINTS); // multiple invalid values, but only the first invalid value is captured assertParseFailure(parser, "1" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_PHONE_AMY - + VALID_GENDER_AMY + VALID_AGE_AMY + VALID_BLOODTYPE_AMY, + + VALID_GENDER_AMY + VALID_AGE_AMY + VALID_BLOODTYPE_AMY, Name.MESSAGE_CONSTRAINTS); } diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index 6d8ddceaccc..1f2c8a5d47e 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -232,7 +232,8 @@ public void parseAllergies_null_throwsNullPointerException() { @Test public void parseAllergies_collectionWithInvalidAllergies_throwsParseException() { - assertThrows(ParseException.class, () -> ParserUtil.parseAllergies(Arrays.asList(VALID_ALLERGY_1, INVALID_ALLERGY))); + assertThrows(ParseException.class, () -> ParserUtil.parseAllergies(Arrays.asList(VALID_ALLERGY_1, + INVALID_ALLERGY))); } @Test @@ -243,7 +244,8 @@ public void parseAllergies_emptyCollection_returnsEmptySet() throws Exception { @Test public void parseAllergies_collectionWithValidAllergies_returnsAllergySet() throws Exception { Set actualAllergySet = ParserUtil.parseAllergies(Arrays.asList(VALID_ALLERGY_1, VALID_ALLERGY_2)); - Set expectedAllergySet = new HashSet(Arrays.asList(new Allergy(VALID_ALLERGY_1), new Allergy(VALID_ALLERGY_2))); + Set expectedAllergySet = new HashSet(Arrays.asList(new Allergy(VALID_ALLERGY_1), + new Allergy(VALID_ALLERGY_2))); assertEquals(expectedAllergySet, actualAllergySet); } diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index 11beaf255de..a83220d8ae8 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -3,8 +3,8 @@ 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.commands.CommandTestUtil.VALID_GENDER_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_ALLERGY_PEANUTS; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; diff --git a/src/test/java/seedu/address/model/person/PersonTest.java b/src/test/java/seedu/address/model/person/PersonTest.java index 5442ddb9e31..176a517b64d 100644 --- a/src/test/java/seedu/address/model/person/PersonTest.java +++ b/src/test/java/seedu/address/model/person/PersonTest.java @@ -3,7 +3,13 @@ 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.commands.CommandTestUtil.*; +import static seedu.address.logic.commands.CommandTestUtil.VALID_AGE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_ALLERGY_PEANUTS; +import static seedu.address.logic.commands.CommandTestUtil.VALID_BLOODTYPE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.BOB; diff --git a/src/test/java/seedu/address/model/person/UniquePersonListTest.java b/src/test/java/seedu/address/model/person/UniquePersonListTest.java index ce82e81c078..974cb2511dc 100644 --- a/src/test/java/seedu/address/model/person/UniquePersonListTest.java +++ b/src/test/java/seedu/address/model/person/UniquePersonListTest.java @@ -3,7 +3,8 @@ 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.commands.CommandTestUtil.*; +import static seedu.address.logic.commands.CommandTestUtil.VALID_ALLERGY_PEANUTS; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.BOB; diff --git a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java index e1ec925b433..e11b36cf49f 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java @@ -62,7 +62,7 @@ public void toModelType_nullName_throwsIllegalValueException() { @Test public void toModelType_invalidPhone_throwsIllegalValueException() { JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_EMAIL, INVALID_PHONE, + new JsonAdaptedPerson(VALID_NAME, VALID_EMAIL, INVALID_PHONE, VALID_GENDER, VALID_AGE, VALID_BLOODTYPE, VALID_ALLERGIES); String expectedMessage = Phone.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); diff --git a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java index 25ff4b60992..c8259e56b39 100644 --- a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java @@ -5,7 +5,14 @@ import java.util.stream.Stream; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; -import seedu.address.model.person.*; +import seedu.address.model.person.Age; +import seedu.address.model.person.Allergy; +import seedu.address.model.person.BloodType; +import seedu.address.model.person.Email; +import seedu.address.model.person.Gender; +import seedu.address.model.person.Name; +import seedu.address.model.person.Person; +import seedu.address.model.person.Phone; /** * A utility class to help with building EditPersonDescriptor objects. diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index 59dc339303b..b39fc62cb56 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -3,7 +3,14 @@ import java.util.HashSet; import java.util.Set; -import seedu.address.model.person.*; +import seedu.address.model.person.Age; +import seedu.address.model.person.Allergy; +import seedu.address.model.person.BloodType; +import seedu.address.model.person.Email; +import seedu.address.model.person.Gender; +import seedu.address.model.person.Name; +import seedu.address.model.person.Person; +import seedu.address.model.person.Phone; import seedu.address.model.util.SampleDataUtil; /** diff --git a/src/test/java/seedu/address/testutil/PersonUtil.java b/src/test/java/seedu/address/testutil/PersonUtil.java index aa71fad9bd2..791ff8e2c37 100644 --- a/src/test/java/seedu/address/testutil/PersonUtil.java +++ b/src/test/java/seedu/address/testutil/PersonUtil.java @@ -1,14 +1,19 @@ package seedu.address.testutil; +import static seedu.address.logic.parser.CliSyntax.PREFIX_AGE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ALLERGIES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_BLOODTYPE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; + import java.util.Set; import seedu.address.logic.commands.AddCommand; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; import seedu.address.model.person.Allergy; import seedu.address.model.person.Person; - -import static seedu.address.logic.parser.CliSyntax.*; - /** * A utility class for Person. */ @@ -48,7 +53,8 @@ public static String getEditPersonDescriptorDetails(EditPersonDescriptor descrip descriptor.getPhone().ifPresent(phone -> sb.append(PREFIX_PHONE).append(phone.value).append(" ")); descriptor.getGender().ifPresent(gender -> sb.append(PREFIX_GENDER).append(gender.gender).append(" ")); descriptor.getAge().ifPresent(age -> sb.append(PREFIX_AGE).append(age.age).append(" ")); - descriptor.getBloodType().ifPresent(bloodType -> sb.append(PREFIX_BLOODTYPE).append(bloodType.bloodType).append(" ")); + descriptor.getBloodType().ifPresent(bloodType -> sb.append(PREFIX_BLOODTYPE).append(bloodType.bloodType) + .append(" ")); if (descriptor.getAllergies().isPresent()) { Set allergies = descriptor.getAllergies().get(); if (allergies.isEmpty()) { diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java index 049d5b99dad..c4c6b6e7bb0 100644 --- a/src/test/java/seedu/address/testutil/TypicalPersons.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -1,14 +1,26 @@ package seedu.address.testutil; +import static seedu.address.logic.commands.CommandTestUtil.VALID_AGE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_AGE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_ALLERGY_DUST; +import static seedu.address.logic.commands.CommandTestUtil.VALID_ALLERGY_PEANUTS; +import static seedu.address.logic.commands.CommandTestUtil.VALID_BLOODTYPE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_BLOODTYPE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_GENDER_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; import seedu.address.model.AddressBook; import seedu.address.model.person.Person; - -import static seedu.address.logic.commands.CommandTestUtil.*; - /** * A utility class containing a list of {@code Person} objects to be used in tests. */