diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 7bf4cf91e7f..6d4eb530dd4 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -25,10 +25,13 @@ public class Messages { public static final String MESSAGE_TAG_NOT_FOUND_IN_CONTACT = "Some tags were not found in the person's tag list."; public static final String MESSAGE_ADD_TAG_SUCCESS = "Added tag(s) %1$s to %2$s."; public static final String MESSAGE_ADD_WEDDING_SUCCESS = "Added wedding(s) %1$s to %2$s."; + public static final String MESSAGE_REMOVE_WEDDING_SUCCESS = "Removed wedding(s) %1$s from %2$s."; public static final String MESSAGE_WEDDING_NOT_FOUND = "One or more specified weddings do not exist in " + "the Wedlinker."; public static final String MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT = "Some weddings were not found in " + "the person's wedding list."; + public static final String MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT = "Use f/ to force the assignment of wedding(s)." + + " This will create the required Wedding objects."; /** * Returns an error message indicating the duplicate prefixes. diff --git a/src/main/java/seedu/address/logic/commands/AssignWeddingCommand.java b/src/main/java/seedu/address/logic/commands/AssignWeddingCommand.java index 26b32c94393..365295183cf 100644 --- a/src/main/java/seedu/address/logic/commands/AssignWeddingCommand.java +++ b/src/main/java/seedu/address/logic/commands/AssignWeddingCommand.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static seedu.address.logic.Messages.MESSAGE_ADD_WEDDING_SUCCESS; +import static seedu.address.logic.Messages.MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT; import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; import static seedu.address.logic.Messages.MESSAGE_WEDDING_NOT_FOUND; @@ -33,6 +34,7 @@ public class AssignWeddingCommand extends Command { private final Index index; private final HashSet weddingsToAdd; + private boolean force = false; /** * Constructs a {@code AssignWedding} Command to add weddings to a person. @@ -44,6 +46,18 @@ public AssignWeddingCommand(Index index, HashSet weddingsToAdd) { this.weddingsToAdd = weddingsToAdd; } + /** + * Constructs a {@code AssignWedding} Command to add weddings to a person with the force flag. + * @param index The index of the person in the person list. + * @param weddingsToAdd The list of weddings to be added. + * @param force Whether the command should force the assignment by creating the Wedding object. + */ + public AssignWeddingCommand(Index index, HashSet weddingsToAdd, boolean force) { + this.index = index; + this.weddingsToAdd = weddingsToAdd; + this.force = force; + } + /** * Generates a command execution success message showing the added weddings and the person. * @@ -69,7 +83,13 @@ public CommandResult execute(Model model) throws CommandException { for (Wedding wedding : weddingsToAdd) { if (!model.hasWedding(wedding)) { - throw new CommandException(MESSAGE_WEDDING_NOT_FOUND); + if (this.force) { + CreateWeddingCommand newWeddingCommand = new CreateWeddingCommand(wedding); + newWeddingCommand.execute(model); + } else { + throw new CommandException( + MESSAGE_WEDDING_NOT_FOUND + "\n" + MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT); + } } } diff --git a/src/main/java/seedu/address/logic/commands/UnassignWeddingCommand.java b/src/main/java/seedu/address/logic/commands/UnassignWeddingCommand.java index bb810dcdaad..a8b3dbc4cb9 100644 --- a/src/main/java/seedu/address/logic/commands/UnassignWeddingCommand.java +++ b/src/main/java/seedu/address/logic/commands/UnassignWeddingCommand.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; +import static seedu.address.logic.Messages.MESSAGE_REMOVE_WEDDING_SUCCESS; import static seedu.address.logic.Messages.MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT; import java.util.HashSet; @@ -19,7 +20,6 @@ */ public class UnassignWeddingCommand extends Command { public static final String COMMAND_WORD = "unassign-wedding"; - public static final String MESSAGE_REMOVE_WEDDING_SUCCESS = "Removed wedding(s) %1$s from %2$s."; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Removes one or multiple weddings from the person identified " diff --git a/src/main/java/seedu/address/logic/parser/AssignWeddingCommandParser.java b/src/main/java/seedu/address/logic/parser/AssignWeddingCommandParser.java index d86c84f875b..06f3f555c89 100644 --- a/src/main/java/seedu/address/logic/parser/AssignWeddingCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AssignWeddingCommandParser.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_FORCE; import static seedu.address.logic.parser.CliSyntax.PREFIX_WEDDING; import java.util.HashSet; @@ -32,7 +33,7 @@ public class AssignWeddingCommandParser implements Parser public AssignWeddingCommand parse(String args) throws ParseException { requireNonNull(args); - ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_WEDDING); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_WEDDING, PREFIX_FORCE); Index index; if (!arePrefixesPresent(argMultimap, PREFIX_WEDDING)) { @@ -63,7 +64,12 @@ public AssignWeddingCommand parse(String args) throws ParseException { .map(Wedding::new) .collect(Collectors.toList())); - return new AssignWeddingCommand(index, weddings); + if (arePrefixesPresent(argMultimap, PREFIX_FORCE)) { + return new AssignWeddingCommand(index, weddings, true); + } else { + return new AssignWeddingCommand(index, weddings); + } + } /** diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 66d74a4997e..adc6af7988a 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -12,4 +12,5 @@ public class CliSyntax { public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); public static final Prefix PREFIX_WEDDING = new Prefix("w/"); + public static final Prefix PREFIX_FORCE = new Prefix("f/"); } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 91093d2b233..3b578fe67fe 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -61,6 +61,7 @@ public EditCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) { editPersonDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).orElse(""))); } + parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags); parseWeddingsForEdit(argMultimap.getAllValues(PREFIX_WEDDING)).ifPresent(editPersonDescriptor::setWeddings); diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 13eddcb079c..d7100716686 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -70,14 +70,6 @@ public void setPersons(List persons) { this.persons.setPersons(persons); } - /** - * Replaces the contents of the tag list with {@code tags}. - * {@code tags} must not contain duplicate tags. - */ - public void setTags(List tags) { - this.tags.setTags(tags); - } - /** * Replaces the contents of the wedding list with {@code weddings}. * {@code weddings} must not contain duplicate tags. @@ -189,6 +181,14 @@ public void setTag(Tag target, Tag editedTag) { tags.setTag(target, editedTag); } + /** + * Replaces the contents of the tag list with {@code tags}. + * {@code tags} must not contain duplicate tags. + */ + public void setTags(List tags) { + this.tags.setTags(tags); + } + /** * Removes {@code key} from this {@code AddressBook}. * {@code key} must exist in the address book. diff --git a/src/test/java/seedu/address/logic/commands/AssignWeddingCommandTest.java b/src/test/java/seedu/address/logic/commands/AssignWeddingCommandTest.java new file mode 100644 index 00000000000..80b93ccc7bc --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/AssignWeddingCommandTest.java @@ -0,0 +1,110 @@ +package seedu.address.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +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 static seedu.address.testutil.TypicalWeddings.AMY_WEDDING; +import static seedu.address.testutil.TypicalWeddings.BOB_WEDDING; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.Messages; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.Person; +import seedu.address.model.wedding.Wedding; +import seedu.address.model.wedding.WeddingName; + +public class AssignWeddingCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void assignWedding_success() { + Person personToEdit = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + HashSet weddingsToAdd = new HashSet<>(Arrays.asList(AMY_WEDDING)); + + AssignWeddingCommand assignWeddingCommand = new AssignWeddingCommand( + INDEX_FIRST_PERSON, weddingsToAdd); + + String expectedMessage = String.format(Messages.MESSAGE_ADD_WEDDING_SUCCESS, "Amy's Wedding", + personToEdit.getName().toString()); + + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + Set updatedWeddings = new HashSet<>(personToEdit.getWeddings()); + updatedWeddings.addAll(weddingsToAdd); + Person editedPerson = new Person( + personToEdit.getName(), + personToEdit.getPhone(), + personToEdit.getEmail(), + personToEdit.getAddress(), + personToEdit.getTags(), + updatedWeddings); + expectedModel.setPerson(personToEdit, editedPerson); + + CommandTestUtil.assertCommandSuccess(assignWeddingCommand, model, expectedMessage, expectedModel); + } + + @Test + public void assignWeddingZeroWeddings_fail() { + Wedding unseenWedding = new Wedding(new WeddingName("UNKNOWN WEDDING")); + HashSet weddingsToAdd = new HashSet<>(Arrays.asList(unseenWedding)); + AssignWeddingCommand assignWeddingCommand = new AssignWeddingCommand( + INDEX_FIRST_PERSON, weddingsToAdd); + String expectedMessage = Messages.MESSAGE_WEDDING_NOT_FOUND + "\n" + + Messages.MESSAGE_FORCE_ASSIGN_WEDDING_TO_CONTACT; + CommandTestUtil.assertCommandFailure(assignWeddingCommand, model, expectedMessage); + } + + @Test + public void sameCommandTest_success() { + HashSet weddingsToRemove = new HashSet<>(Arrays.asList(BOB_WEDDING)); + AssignWeddingCommand command1 = new AssignWeddingCommand(INDEX_FIRST_PERSON, weddingsToRemove); + assertTrue(command1.equals(command1)); + } + + @Test + public void differentCommandType_fail() { + HashSet weddingsToRemove = new HashSet<>(); + AssignWeddingCommand command1 = new AssignWeddingCommand(INDEX_FIRST_PERSON, weddingsToRemove); + assertFalse(command1.equals(null)); + } + + @Test + public void differentIndex_fail() { + HashSet weddingsToRemove = new HashSet<>(); + AssignWeddingCommand command1 = new AssignWeddingCommand(INDEX_FIRST_PERSON, weddingsToRemove); + AssignWeddingCommand command2 = new AssignWeddingCommand(INDEX_SECOND_PERSON, weddingsToRemove); + assertFalse(command1.equals(command2)); + } + + @Test + public void differentWeddings_fail() { + HashSet weddingsToRemove1 = new HashSet<>(); + HashSet weddingsToRemove2 = new HashSet<>(Arrays.asList(AMY_WEDDING)); + AssignWeddingCommand command1 = new AssignWeddingCommand(INDEX_FIRST_PERSON, weddingsToRemove1); + AssignWeddingCommand command2 = new AssignWeddingCommand(INDEX_SECOND_PERSON, weddingsToRemove2); + assertFalse(command1.equals(command2)); + } + + @Test + public void forceAssignWedding_success() { + Person personToEdit = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + Wedding unseenWedding = new Wedding(new WeddingName("UNKNOWN WEDDING")); + HashSet weddingsToAdd = new HashSet<>(Arrays.asList(unseenWedding)); + AssignWeddingCommand assignWeddingCommand = new AssignWeddingCommand( + INDEX_FIRST_PERSON, weddingsToAdd, true); + String expectedMessage = String.format( + Messages.MESSAGE_ADD_WEDDING_SUCCESS, + unseenWedding.getWeddingName().toString(), + personToEdit.getName().toString()); + CommandTestUtil.assertCommandSuccess(assignWeddingCommand, model, expectedMessage, model); + + } +} diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 7490c036343..6bc88aa5f06 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -20,8 +20,6 @@ import seedu.address.model.Model; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; -import seedu.address.model.tag.Tag; -import seedu.address.model.tag.TagName; import seedu.address.testutil.EditPersonDescriptorBuilder; /** @@ -96,8 +94,6 @@ public class CommandTestUtil { public static final EditCommand.EditPersonDescriptor DESC_AMY; public static final EditCommand.EditPersonDescriptor DESC_BOB; - public static final Tag TEST_TAG_FLORIST = new Tag(new TagName(VALID_TAG_FLORIST)); - static { DESC_AMY = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY) .withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY) diff --git a/src/test/java/seedu/address/logic/commands/CreateWeddingCommandTest.java b/src/test/java/seedu/address/logic/commands/CreateWeddingCommandTest.java new file mode 100644 index 00000000000..1a013326843 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/CreateWeddingCommandTest.java @@ -0,0 +1,262 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalWeddings.VALID_WEDDING_NAME_AMY_WEDDING; +import static seedu.address.testutil.TypicalWeddings.VALID_WEDDING_NAME_BOB_WEDDING; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.function.Predicate; + +import org.junit.jupiter.api.Test; + +import javafx.collections.ObservableList; +import seedu.address.commons.core.GuiSettings; +import seedu.address.logic.Messages; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.AddressBook; +import seedu.address.model.Model; +import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyUserPrefs; +import seedu.address.model.person.Person; +import seedu.address.model.tag.Tag; +import seedu.address.model.wedding.Wedding; + +public class CreateWeddingCommandTest { + + @Test + public void constructor_nullWedding_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new CreateWeddingCommand(null)); + } + + @Test + public void execute_weddingAcceptedByModel_addSuccessful() throws Exception { + ModelStubAcceptingWeddingAdded modelStub = new ModelStubAcceptingWeddingAdded(); + Wedding validWedding = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + + CommandResult commandResult = new CreateWeddingCommand(validWedding).execute(modelStub); + assertEquals(String.format(CreateWeddingCommand.MESSAGE_SUCCESS, Messages.format(validWedding)), + commandResult.getFeedbackToUser()); + assertEquals(Arrays.asList(validWedding), modelStub.weddingsAdded); + } + + @Test + public void execute_duplicateWedding_throwsCommandException() { + Wedding validWedding = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + CreateWeddingCommand createWeddingCommand = new CreateWeddingCommand(validWedding); + ModelStub modelStub = new ModelStubWithWedding(validWedding); + + assertThrows(CommandException.class, + CreateWeddingCommand.MESSAGE_DUPLICATE_WEDDING, () -> createWeddingCommand.execute(modelStub)); + } + + @Test + public void equals() { + Wedding amyWedding = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + Wedding bobWedding = new Wedding(VALID_WEDDING_NAME_BOB_WEDDING); + CreateWeddingCommand createAmyWeddingCommand = new CreateWeddingCommand(amyWedding); + CreateWeddingCommand createBobWeddingCommand = new CreateWeddingCommand(bobWedding); + + // same object -> returns ture + assertEquals(createAmyWeddingCommand, createAmyWeddingCommand); + + // same values -> returns false + CreateWeddingCommand createFloristCommandCopy = new CreateWeddingCommand(amyWedding); + assertEquals(createAmyWeddingCommand, createFloristCommandCopy); + + // different types -> returns false + assertFalse(createAmyWeddingCommand.equals(1)); + + // null -> return false + assertFalse(createAmyWeddingCommand.equals(null)); + + // different Wedding -> return false + assertFalse(createAmyWeddingCommand.equals(createBobWeddingCommand)); + } + + /** + * A default model stub that have all methods failing. + */ + private class ModelStub implements Model { + @Override + public void setUserPrefs(ReadOnlyUserPrefs userPrefs) { + throw new AssertionError("This method should not be called."); + } + + @Override + public ReadOnlyUserPrefs getUserPrefs() { + throw new AssertionError("This method should not be called."); + } + + @Override + public GuiSettings getGuiSettings() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setGuiSettings(GuiSettings guiSettings) { + throw new AssertionError("This method should not be called."); + } + + @Override + public Path getAddressBookFilePath() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setAddressBookFilePath(Path addressBookFilePath) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void addPerson(Person person) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setAddressBook(ReadOnlyAddressBook newData) { + throw new AssertionError("This method should not be called."); + } + + @Override + public ReadOnlyAddressBook getAddressBook() { + throw new AssertionError("This method should not be called."); + } + + @Override + public boolean hasPerson(Person person) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void deletePerson(Person target) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setPerson(Person target, Person editedPerson) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setTag(Tag target, Tag editedWedding) { + throw new AssertionError("This method should not be called."); + } + + @Override + public ObservableList getFilteredPersonList() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void updateFilteredPersonList(Predicate predicate) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void updateFilteredPersonListByTag(Predicate tagPredicate) { + throw new AssertionError("This method should not be called."); + } + + @Override + public boolean hasTag(Tag toAdd) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void addTag(Tag toAdd) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void updateFilteredTagList(Predicate predicate) { + throw new AssertionError("This method should not be called."); + } + + @Override + public boolean hasWedding(Wedding toAdd) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void addWedding(Wedding toAdd) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setWedding(Wedding target, Wedding editedWedding) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void deleteTag(Tag tag) { + throw new AssertionError("This method should not be called."); + } + + + @Override + public ObservableList getFilteredTagList() { + throw new AssertionError("This method should not be called."); + } + @Override + public void updateFilteredWeddingList(Predicate predicate) { + throw new AssertionError("This method should not be called."); + } + + @Override + public ObservableList getFilteredWeddingList() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void deleteWedding(Wedding wedding) { + throw new AssertionError("This method should not be called."); + } + } + + /** + * A Model stub that contains a single Wedding. + */ + private class ModelStubWithWedding extends CreateWeddingCommandTest.ModelStub { + private final Wedding wedding; + + ModelStubWithWedding(Wedding wedding) { + requireNonNull(wedding); + this.wedding = wedding; + } + + @Override + public boolean hasWedding(Wedding wedding) { + requireNonNull(wedding); + return this.wedding.isSameWedding(wedding); + } + } + + /** + * A Model stub that always accept the Wedding being added. + */ + private class ModelStubAcceptingWeddingAdded extends CreateWeddingCommandTest.ModelStub { + final ArrayList weddingsAdded = new ArrayList<>(); + + @Override + public boolean hasWedding(Wedding wedding) { + requireNonNull(wedding); + return weddingsAdded.stream().anyMatch(wedding::isSameWedding); + } + + @Override + public void addWedding(Wedding wedding) { + requireNonNull(wedding); + weddingsAdded.add(wedding); + } + + @Override + public ReadOnlyAddressBook getAddressBook() { + return new AddressBook(); + } + } +} diff --git a/src/test/java/seedu/address/logic/commands/DeleteTagCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteTagCommandTest.java index 29ccad16588..b614ada6ec4 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteTagCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteTagCommandTest.java @@ -4,9 +4,9 @@ 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.TypicalPersons.FLORIST; -import static seedu.address.testutil.TypicalPersons.PHOTOGRAPHER; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; +import static seedu.address.testutil.TypicalTags.FLORIST; +import static seedu.address.testutil.TypicalTags.PHOTOGRAPHER; import org.junit.jupiter.api.Test; diff --git a/src/test/java/seedu/address/logic/commands/DeleteWeddingCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteWeddingCommandTest.java new file mode 100644 index 00000000000..7be526db9c3 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/DeleteWeddingCommandTest.java @@ -0,0 +1,72 @@ +package seedu.address.logic.commands; + +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.TypicalPersons.getTypicalAddressBook; +import static seedu.address.testutil.TypicalWeddings.AMY_WEDDING; +import static seedu.address.testutil.TypicalWeddings.BOB_WEDDING; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.Messages; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.wedding.Wedding; + +public class DeleteWeddingCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void execute_validDeleteWeddingCommand_success() { + Wedding weddingToDelete = model.getFilteredWeddingList().get(0); + DeleteWeddingCommand deleteWeddingCommand = new DeleteWeddingCommand(weddingToDelete); + + String expectedMessage = String.format(DeleteWeddingCommand.MESSAGE_DELETE_WEDDING_SUCCESS, + Messages.format(weddingToDelete)); + + ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + expectedModel.deleteWedding(weddingToDelete); + + assertCommandSuccess(deleteWeddingCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_invalidNotFoundDeleteWeddingCommand() { + Wedding weddingToDelete = model.getFilteredWeddingList().get(0); + + String expectedMessage = String.format(DeleteWeddingCommand.MESSAGE_DELETE_WEDDING_FAILURE_NOT_FOUND, + Messages.format(weddingToDelete)); + + ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + expectedModel.deleteWedding(weddingToDelete); + + DeleteWeddingCommand expectedDeleteWeddingCommand = new DeleteWeddingCommand(weddingToDelete); + + assertCommandFailure(expectedDeleteWeddingCommand, expectedModel, expectedMessage); + } + + @Test + public void equals() { + DeleteWeddingCommand deleteFloristWeddingCommand = new DeleteWeddingCommand(AMY_WEDDING); + DeleteWeddingCommand deletePhotographerWeddingCommandCopy = new DeleteWeddingCommand(BOB_WEDDING); + + // same object -> returns true + assertTrue(deleteFloristWeddingCommand.equals(deleteFloristWeddingCommand)); + + // same values -> returns true + DeleteWeddingCommand deleteFloristWeddingCommandCopy = new DeleteWeddingCommand(AMY_WEDDING); + assertTrue(deleteFloristWeddingCommand.equals(deleteFloristWeddingCommandCopy)); + + // different types -> return false + assertFalse(deleteFloristWeddingCommand.equals(1)); + + // null -> returns false + assertFalse(deleteFloristWeddingCommand.equals(null)); + + // different Wedding -> returns false + assertFalse(deleteFloristWeddingCommand.equals(deletePhotographerWeddingCommandCopy)); + } +} diff --git a/src/test/java/seedu/address/logic/commands/UnassignWeddingCommandTest.java b/src/test/java/seedu/address/logic/commands/UnassignWeddingCommandTest.java new file mode 100644 index 00000000000..df0793a5819 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/UnassignWeddingCommandTest.java @@ -0,0 +1,102 @@ +package seedu.address.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +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 static seedu.address.testutil.TypicalWeddings.AMY_WEDDING; +import static seedu.address.testutil.TypicalWeddings.BOB_WEDDING; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.Messages; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.Person; +import seedu.address.model.wedding.Wedding; +import seedu.address.model.wedding.WeddingName; + +public class UnassignWeddingCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void unassignWedding_success() { + Person personToEdit = model.getFilteredPersonList().get(INDEX_SECOND_PERSON.getZeroBased()); + HashSet weddingsToRemove = new HashSet<>(Arrays.asList(new Wedding(new WeddingName("Wedding 2")))); + + UnassignWeddingCommand unassignWeddingCommand = new UnassignWeddingCommand( + INDEX_SECOND_PERSON, weddingsToRemove); + + String expectedMessage = String.format(Messages.MESSAGE_REMOVE_WEDDING_SUCCESS, "Wedding 2", + personToEdit.getName().toString()); + + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + Set updatedWeddings = new HashSet<>(personToEdit.getWeddings()); + updatedWeddings.removeAll(weddingsToRemove); + Person editedPerson = new Person( + personToEdit.getName(), + personToEdit.getPhone(), + personToEdit.getEmail(), + personToEdit.getAddress(), + personToEdit.getTags(), + updatedWeddings); + expectedModel.setPerson(personToEdit, editedPerson); + + CommandTestUtil.assertCommandSuccess(unassignWeddingCommand, model, expectedMessage, expectedModel); + } + + @Test + public void unassignWeddingZeroWeddings_fail() { + HashSet weddingsToRemove = new HashSet<>(Arrays.asList(AMY_WEDDING)); + UnassignWeddingCommand unassignWeddingCommand = new UnassignWeddingCommand( + INDEX_SECOND_PERSON, weddingsToRemove); + String expectedMessage = Messages.MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT; + CommandTestUtil.assertCommandFailure(unassignWeddingCommand, model, expectedMessage); + } + + @Test + public void unassignWeddingNoMatchingWedding_fail() { + HashSet weddingsToRemove = new HashSet<>(Arrays.asList(BOB_WEDDING)); + UnassignWeddingCommand unassignWeddingCommand = new UnassignWeddingCommand( + INDEX_FIRST_PERSON, weddingsToRemove); + String expectedMessage = Messages.MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT; + CommandTestUtil.assertCommandFailure(unassignWeddingCommand, model, expectedMessage); + } + + @Test + public void sameCommandTest_success() { + HashSet weddingsToRemove = new HashSet<>(Arrays.asList(BOB_WEDDING)); + UnassignWeddingCommand command1 = new UnassignWeddingCommand(INDEX_FIRST_PERSON, weddingsToRemove); + assertTrue(command1.equals(command1)); + } + + @Test + public void differentCommandType_fail() { + HashSet weddingsToRemove = new HashSet<>(); + UnassignWeddingCommand command1 = new UnassignWeddingCommand(INDEX_FIRST_PERSON, weddingsToRemove); + assertFalse(command1.equals(null)); + } + + @Test + public void differentIndex_fail() { + HashSet weddingsToRemove = new HashSet<>(); + UnassignWeddingCommand command1 = new UnassignWeddingCommand(INDEX_FIRST_PERSON, weddingsToRemove); + UnassignWeddingCommand command2 = new UnassignWeddingCommand(INDEX_SECOND_PERSON, weddingsToRemove); + assertFalse(command1.equals(command2)); + } + + @Test + public void differentWeddings_fail() { + HashSet weddingsToRemove1 = new HashSet<>(); + HashSet weddingsToRemove2 = new HashSet<>(Arrays.asList(AMY_WEDDING)); + UnassignWeddingCommand command1 = new UnassignWeddingCommand(INDEX_FIRST_PERSON, weddingsToRemove1); + UnassignWeddingCommand command2 = new UnassignWeddingCommand(INDEX_SECOND_PERSON, weddingsToRemove2); + assertFalse(command1.equals(command2)); + } +} diff --git a/src/test/java/seedu/address/logic/parser/AssignWeddingCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AssignWeddingCommandParserTest.java index b73f119281a..8296b7c85dc 100644 --- a/src/test/java/seedu/address/logic/parser/AssignWeddingCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AssignWeddingCommandParserTest.java @@ -56,4 +56,20 @@ public void parse_invalidArgs_throwsParseException() { assertParseFailure(parser, "1 w/ w/Jeslyn's_Wedding", WeddingName.MESSAGE_CONSTRAINTS); } + + @Test + public void parse_validArgsWithForce_returnsAssignWeddingCommand() { + Index targetIndex = Index.fromOneBased(1); + + // Expected weddings + Wedding wedding1 = new Wedding(new WeddingName("Jeslyn's Wedding")); + Wedding wedding2 = new Wedding(new WeddingName("Wedding April 17th 2025")); + + AssignWeddingCommand expectedCommand = new AssignWeddingCommand(targetIndex, + new HashSet<>(Arrays.asList(wedding1, wedding2)), true); + + String userInput = "1 w/Jeslyn's Wedding w/Wedding April 17th 2025 f/"; + + assertParseSuccess(parser, userInput, expectedCommand); + } } diff --git a/src/test/java/seedu/address/logic/parser/CreateWeddingCommandParserTest.java b/src/test/java/seedu/address/logic/parser/CreateWeddingCommandParserTest.java index 4421671808b..e5bfc2c7aac 100644 --- a/src/test/java/seedu/address/logic/parser/CreateWeddingCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/CreateWeddingCommandParserTest.java @@ -7,13 +7,12 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_WEDDING; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; -import static seedu.address.testutil.TestWeddings.VALID_WEDDING; +import static seedu.address.testutil.TypicalWeddings.AMY_WEDDING; import org.junit.jupiter.api.Test; import seedu.address.logic.Messages; import seedu.address.logic.commands.CreateWeddingCommand; -import seedu.address.model.wedding.Wedding; import seedu.address.model.wedding.WeddingName; public class CreateWeddingCommandParserTest { @@ -21,9 +20,8 @@ public class CreateWeddingCommandParserTest { @Test public void parse_validWedding_success() { - Wedding expectedWedding = VALID_WEDDING; assertParseSuccess(parser, PREAMBLE_WHITESPACE + WEDDING_DESC_AMY, - new CreateWeddingCommand(expectedWedding)); + new CreateWeddingCommand(AMY_WEDDING)); } @Test diff --git a/src/test/java/seedu/address/logic/parser/DeleteTagCommandParserTest.java b/src/test/java/seedu/address/logic/parser/DeleteTagCommandParserTest.java index 855010ec946..0307bb64028 100644 --- a/src/test/java/seedu/address/logic/parser/DeleteTagCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/DeleteTagCommandParserTest.java @@ -1,9 +1,9 @@ package seedu.address.logic.parser; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.commands.CommandTestUtil.TEST_TAG_FLORIST; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; +import static seedu.address.testutil.TypicalTags.FLORIST; import org.junit.jupiter.api.Test; @@ -15,7 +15,7 @@ public class DeleteTagCommandParserTest { @Test public void parse_validArgs_returnsDeleteTagCommand() { - assertParseSuccess(parser, " t/florist", new DeleteTagCommand(TEST_TAG_FLORIST)); + assertParseSuccess(parser, " t/florist", new DeleteTagCommand(FLORIST)); } @Test diff --git a/src/test/java/seedu/address/logic/parser/DeleteWeddingCommandParserTest.java b/src/test/java/seedu/address/logic/parser/DeleteWeddingCommandParserTest.java index 702a34a5c41..f7d1ee91f19 100644 --- a/src/test/java/seedu/address/logic/parser/DeleteWeddingCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/DeleteWeddingCommandParserTest.java @@ -7,13 +7,12 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_WEDDING; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; -import static seedu.address.testutil.TestWeddings.VALID_WEDDING; +import static seedu.address.testutil.TypicalWeddings.AMY_WEDDING; import org.junit.jupiter.api.Test; import seedu.address.logic.Messages; import seedu.address.logic.commands.DeleteWeddingCommand; -import seedu.address.model.wedding.Wedding; import seedu.address.model.wedding.WeddingName; public class DeleteWeddingCommandParserTest { @@ -21,9 +20,8 @@ public class DeleteWeddingCommandParserTest { @Test public void parse_validWedding_success() { - Wedding expectedWedding = VALID_WEDDING; assertParseSuccess(parser, PREAMBLE_WHITESPACE + WEDDING_DESC_AMY, - new DeleteWeddingCommand(expectedWedding)); + new DeleteWeddingCommand(AMY_WEDDING)); } @Test diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index f5c657cfe26..ac39fe90f7d 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -7,9 +7,9 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalPersons.ALICE; -import static seedu.address.testutil.TypicalPersons.FLORIST; -import static seedu.address.testutil.TypicalPersons.WEDDING_ONE; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; +import static seedu.address.testutil.TypicalTags.FLORIST; +import static seedu.address.testutil.TypicalWeddings.AMY_WEDDING; import java.util.Arrays; import java.util.Collection; @@ -54,7 +54,7 @@ public void resetData_withDuplicatePersons_throwsDuplicatePersonException() { .build(); List newPersons = Arrays.asList(ALICE, editedAlice); List tags = Arrays.asList(FLORIST); - List weddings = Arrays.asList(WEDDING_ONE); + List weddings = Arrays.asList(AMY_WEDDING); AddressBookStub newData = new AddressBookStub(newPersons, tags, weddings); assertThrows(DuplicatePersonException.class, () -> addressBook.resetData(newData)); diff --git a/src/test/java/seedu/address/model/ModelManagerTest.java b/src/test/java/seedu/address/model/ModelManagerTest.java index 5939636affc..3f20d13e609 100644 --- a/src/test/java/seedu/address/model/ModelManagerTest.java +++ b/src/test/java/seedu/address/model/ModelManagerTest.java @@ -7,7 +7,7 @@ import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.BENSON; -import static seedu.address.testutil.TypicalPersons.FLORIST; +import static seedu.address.testutil.TypicalTags.FLORIST; import java.nio.file.Path; import java.nio.file.Paths; diff --git a/src/test/java/seedu/address/model/tag/UniqueTagListTest.java b/src/test/java/seedu/address/model/tag/UniqueTagListTest.java index 062f784f835..cdc247b1502 100644 --- a/src/test/java/seedu/address/model/tag/UniqueTagListTest.java +++ b/src/test/java/seedu/address/model/tag/UniqueTagListTest.java @@ -4,8 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalPersons.FLORIST; -import static seedu.address.testutil.TypicalPersons.PHOTOGRAPHER; +import static seedu.address.testutil.TypicalTags.FLORIST; +import static seedu.address.testutil.TypicalTags.PHOTOGRAPHER; import java.util.Arrays; import java.util.Collections; diff --git a/src/test/java/seedu/address/model/wedding/UniqueWeddingListTest.java b/src/test/java/seedu/address/model/wedding/UniqueWeddingListTest.java new file mode 100644 index 00000000000..5e58ec8e4e8 --- /dev/null +++ b/src/test/java/seedu/address/model/wedding/UniqueWeddingListTest.java @@ -0,0 +1,192 @@ +package seedu.address.model.wedding; + +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.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalWeddings.AMY_WEDDING; +import static seedu.address.testutil.TypicalWeddings.BOB_WEDDING; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.wedding.exceptions.DuplicateWeddingException; +import seedu.address.model.wedding.exceptions.WeddingNotFoundException; + +public class UniqueWeddingListTest { + private final UniqueWeddingList uniqueWeddingList = new UniqueWeddingList(); + + @Test + public void contains_nullWedding_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueWeddingList.contains(null)); + } + + @Test + public void contains_weddingNotInList_returnsFalse() { + assertFalse(uniqueWeddingList.contains(AMY_WEDDING)); + } + + @Test + public void contains_weddingInList_returnsTrue() { + uniqueWeddingList.add(AMY_WEDDING); + assertTrue(uniqueWeddingList.contains(AMY_WEDDING)); + } + + @Test + public void contains_weddingWithSameIdentityFieldsInList_returnsTrue() { + uniqueWeddingList.add(AMY_WEDDING); + Wedding sameWedding = new Wedding(new WeddingName("Amy's Wedding")); + assertTrue(uniqueWeddingList.contains(sameWedding)); + } + + @Test + public void add_nullWedding_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueWeddingList.add(null)); + } + + @Test + public void add_duplicateWedding_throwsDuplicateWeddingException() { + uniqueWeddingList.add(AMY_WEDDING); + assertThrows(DuplicateWeddingException.class, () -> uniqueWeddingList.add(AMY_WEDDING)); + } + + @Test + public void setWedding_nullTargetWedding_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueWeddingList.setWedding(null, AMY_WEDDING)); + } + + @Test + public void setWedding_nullEditedWedding_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueWeddingList.setWedding(AMY_WEDDING, null)); + } + + @Test + public void setWedding_targetWeddingNotInList_throwsWeddingNotFoundException() { + assertThrows(WeddingNotFoundException.class, () -> uniqueWeddingList.setWedding(AMY_WEDDING, BOB_WEDDING)); + } + + @Test + public void setWedding_editedWeddingIsSameWedding_success() { + uniqueWeddingList.add(AMY_WEDDING); + uniqueWeddingList.setWedding(AMY_WEDDING, AMY_WEDDING); + UniqueWeddingList expectedUniqueWeddingList = new UniqueWeddingList(); + expectedUniqueWeddingList.add(AMY_WEDDING); + assertEquals(expectedUniqueWeddingList, uniqueWeddingList); + } + + @Test + public void setWedding_editedWeddingHasDifferentIdentity_success() { + uniqueWeddingList.add(AMY_WEDDING); + uniqueWeddingList.setWedding(AMY_WEDDING, BOB_WEDDING); + UniqueWeddingList expectedUniqueWeddingList = new UniqueWeddingList(); + expectedUniqueWeddingList.add(BOB_WEDDING); + assertEquals(expectedUniqueWeddingList, uniqueWeddingList); + } + + @Test + public void setWedding_editedWeddingHasNonUniqueIdentity_throwsDuplicateWeddingException() { + uniqueWeddingList.add(AMY_WEDDING); + uniqueWeddingList.add(BOB_WEDDING); + assertThrows(DuplicateWeddingException.class, () -> uniqueWeddingList.setWedding(AMY_WEDDING, BOB_WEDDING)); + } + + @Test + public void remove_nullWedding_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueWeddingList.remove(null)); + } + + @Test + public void remove_weddingDoesNotExist_throwsWeddingNotFoundException() { + assertThrows(WeddingNotFoundException.class, () -> uniqueWeddingList.remove(AMY_WEDDING)); + } + + @Test + public void remove_existingWedding_removesWedding() { + uniqueWeddingList.add(AMY_WEDDING); + uniqueWeddingList.remove(AMY_WEDDING); + UniqueWeddingList expectedUniqueWeddingList = new UniqueWeddingList(); + assertEquals(expectedUniqueWeddingList, uniqueWeddingList); + } + + @Test + public void setWeddings_nullUniqueWeddingList_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueWeddingList.setWeddings((List) null)); + } + + @Test + public void setWeddings_uniqueWeddingList_replacesOwnListWithProvidedUniqueWeddingList() { + uniqueWeddingList.add(AMY_WEDDING); + List weddingList = Collections.singletonList(BOB_WEDDING); + uniqueWeddingList.setWeddings(weddingList); + UniqueWeddingList expectedUniqueWeddingList = new UniqueWeddingList(); + expectedUniqueWeddingList.add(BOB_WEDDING); + assertEquals(expectedUniqueWeddingList, uniqueWeddingList); + } + + @Test + public void setWeddings_listWithDuplicateWeddings_throwsDuplicateWeddingException() { + List listWithDuplicateWeddings = Arrays.asList(AMY_WEDDING, AMY_WEDDING); + assertThrows(DuplicateWeddingException.class, () -> uniqueWeddingList.setWeddings(listWithDuplicateWeddings)); + } + + @Test + public void asUnmodifiableObservableList_modifyList_throwsUnsupportedOperationException() { + assertThrows(UnsupportedOperationException.class, () -> + uniqueWeddingList.asUnmodifiableObservableList().remove(0)); + } + + @Test + public void equals_sameValues_returnsTrue() { + UniqueWeddingList anotherList = new UniqueWeddingList(); + anotherList.add(AMY_WEDDING); + uniqueWeddingList.add(AMY_WEDDING); + assertTrue(uniqueWeddingList.equals(anotherList)); + } + + @Test + public void equals_differentValues_returnsFalse() { + UniqueWeddingList anotherList = new UniqueWeddingList(); + anotherList.add(BOB_WEDDING); + uniqueWeddingList.add(AMY_WEDDING); + assertFalse(uniqueWeddingList.equals(anotherList)); + } + + @Test + public void equals_sameObject_returnsTrue() { + assertTrue(uniqueWeddingList.equals(uniqueWeddingList)); + } + + @Test + public void equals_null_returnsFalse() { + assertFalse(uniqueWeddingList.equals(null)); + } + + @Test + public void equals_differentType_returnsFalse() { + assertFalse(uniqueWeddingList.equals(5)); + } + + @Test + public void hashCode_sameValues_returnsSameHashCode() { + UniqueWeddingList anotherList = new UniqueWeddingList(); + anotherList.add(AMY_WEDDING); + uniqueWeddingList.add(AMY_WEDDING); + assertEquals(uniqueWeddingList.hashCode(), anotherList.hashCode()); + } + + @Test + public void hashCode_differentValues_returnsDifferentHashCode() { + UniqueWeddingList anotherList = new UniqueWeddingList(); + anotherList.add(BOB_WEDDING); + uniqueWeddingList.add(AMY_WEDDING); + assertFalse(uniqueWeddingList.hashCode() == anotherList.hashCode()); + } + + @Test + public void toStringTest() { + assertEquals(uniqueWeddingList.asUnmodifiableObservableList().toString(), uniqueWeddingList.toString()); + } +} diff --git a/src/test/java/seedu/address/model/wedding/WeddingNameTest.java b/src/test/java/seedu/address/model/wedding/WeddingNameTest.java new file mode 100644 index 00000000000..f6995f021d0 --- /dev/null +++ b/src/test/java/seedu/address/model/wedding/WeddingNameTest.java @@ -0,0 +1,92 @@ +package seedu.address.model.wedding; + +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.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalWeddings.VALID_WEDDING_STRING_AMY_WEDDING; +import static seedu.address.testutil.TypicalWeddings.VALID_WEDDING_STRING_BOB_WEDDING; + +import org.junit.jupiter.api.Test; + +public class WeddingNameTest { + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new WeddingName(null)); + } + + @Test + public void constructor_invalidWeddingName_throwsIllegalArgumentException() { + String invalidWeddingName = ""; + assertThrows(IllegalArgumentException.class, () -> new WeddingName(invalidWeddingName)); + } + + @Test + public void isValidName_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> WeddingName.isValidName(null)); + } + + @Test + public void isValidName_validName_returnsTrue() { + // Valid Wedding names + assertTrue(WeddingName.isValidName("friend")); + assertTrue(WeddingName.isValidName("Work")); + assertTrue(WeddingName.isValidName("123")); + assertTrue(WeddingName.isValidName("friend 123")); + assertTrue(WeddingName.isValidName("Family Time")); // Spaces and alphabets + } + + @Test + public void isValidName_invalidName_returnsFalse() { + // Invalid Wedding names + assertFalse(WeddingName.isValidName("")); // Empty string + assertFalse(WeddingName.isValidName(" ")); // Spaces only + assertFalse(WeddingName.isValidName("@home")); // Special character '@' + assertFalse(WeddingName.isValidName("home!")); // Special character '!' + assertFalse(WeddingName.isValidName(" friend")); // Leading space + } + + @Test + public void equals() { + WeddingName weddingName = new WeddingName(VALID_WEDDING_STRING_AMY_WEDDING); + + assertTrue(weddingName.equals(weddingName)); + + WeddingName weddingNameCopy = new WeddingName(VALID_WEDDING_STRING_AMY_WEDDING); + assertTrue(weddingName.equals(weddingNameCopy)); + + assertFalse(weddingName.equals(5)); + + assertFalse(weddingName.equals(null)); + + WeddingName differentWeddingName = new WeddingName(VALID_WEDDING_STRING_BOB_WEDDING); + assertFalse(weddingName.equals(differentWeddingName)); + } + + @Test + public void hashCode_sameWeddingName_returnsSameHashCode() { + WeddingName weddingName = new WeddingName(VALID_WEDDING_STRING_AMY_WEDDING); + WeddingName weddingNameCopy = new WeddingName(VALID_WEDDING_STRING_AMY_WEDDING); + assertEquals(weddingName.hashCode(), weddingNameCopy.hashCode()); + } + + @Test + public void hashCode_differentWeddingName_returnsDifferentHashCode() { + WeddingName weddingName = new WeddingName(VALID_WEDDING_STRING_AMY_WEDDING); + WeddingName differentWeddingName = new WeddingName(VALID_WEDDING_STRING_BOB_WEDDING); + assertFalse(weddingName.hashCode() == differentWeddingName.hashCode()); + } + + @Test + public void toString_validWeddingName_returnsStringRepresentation() { + WeddingName amyWeddingName = new WeddingName(VALID_WEDDING_STRING_AMY_WEDDING); + assertEquals("Amy's Wedding", amyWeddingName.toString()); + } + + @Test + public void matches_validRegex_returnsTrue() { + WeddingName amyWeddingName = new WeddingName(VALID_WEDDING_STRING_AMY_WEDDING); + assertTrue(amyWeddingName.matches("[\\p{Alnum}'][\\p{Alnum} ']*")); + } +} diff --git a/src/test/java/seedu/address/model/wedding/WeddingTest.java b/src/test/java/seedu/address/model/wedding/WeddingTest.java new file mode 100644 index 00000000000..aba2c20399e --- /dev/null +++ b/src/test/java/seedu/address/model/wedding/WeddingTest.java @@ -0,0 +1,117 @@ +package seedu.address.model.wedding; + +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.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalWeddings.AMY_WEDDING; +import static seedu.address.testutil.TypicalWeddings.BOB_WEDDING; +import static seedu.address.testutil.TypicalWeddings.VALID_WEDDING_NAME_AMY_WEDDING; +import static seedu.address.testutil.TypicalWeddings.VALID_WEDDING_NAME_BOB_WEDDING; + +import org.junit.jupiter.api.Test; + +public class WeddingTest { + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Wedding(null)); + } + + @Test + public void constructor_invalidWeddingName_throwsIllegalArgumentException() { + String invalidWeddingName = ""; + assertThrows(IllegalArgumentException.class, () -> new Wedding(new WeddingName(invalidWeddingName))); + } + + @Test + public void isValidWeddingName() { + // null Wedding name + assertThrows(NullPointerException.class, () -> Wedding.isValidWeddingName(null)); + } + + @Test + public void isValidWeddingName_validWeddingName_returnsTrue() { + // Valid Wedding names + assertTrue(Wedding.isValidWeddingName("friend")); + assertTrue(Wedding.isValidWeddingName("work")); + assertTrue(Wedding.isValidWeddingName("123")); + assertTrue(Wedding.isValidWeddingName("friend 123")); // Alphanumeric with spaces + } + + @Test + public void isValidWeddingName_invalidWeddingName_returnsFalse() { + // Invalid Wedding names + assertFalse(Wedding.isValidWeddingName("")); // Empty string + assertFalse(Wedding.isValidWeddingName(" ")); // Spaces only + assertFalse(Wedding.isValidWeddingName("@home")); // Special character not allowed + assertFalse(Wedding.isValidWeddingName("friend!")); // Special character not allowed + } + + @Test + public void isSameWedding_sameWedding_returnsTrue() { + Wedding amyWedding = AMY_WEDDING; + assertTrue(amyWedding.isSameWedding(amyWedding)); + } + + @Test + public void isSameWedding_identicalWeddingName_returnsTrue() { + Wedding amyWedding1 = AMY_WEDDING; + Wedding amyWedding2 = AMY_WEDDING; + assertTrue(amyWedding1.isSameWedding(amyWedding2)); + } + + @Test + public void isSameWedding_differentWeddingName_returnsFalse() { + Wedding amyWedding = AMY_WEDDING; + Wedding bobWeding = BOB_WEDDING; + assertFalse(amyWedding.isSameWedding(bobWeding)); + } + + @Test + public void equals_identicalWeddingName_returnsTrue() { + Wedding wedding1 = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + Wedding wedding2 = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + assertTrue(wedding1.equals(wedding2)); + } + + @Test + public void equals_differentWeddingName_returnsFalse() { + Wedding wedding1 = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + Wedding wedding2 = new Wedding(VALID_WEDDING_NAME_BOB_WEDDING); + assertFalse(wedding1.equals(wedding2)); + } + + @Test + public void toString_validWedding_returnsExpectedFormat() { + Wedding amyWedding = AMY_WEDDING; + assertTrue(amyWedding.toString().equals("[Amy's Wedding]")); + } + + @Test + public void noPersonsWeddinggedCheck() { + Wedding amyWedding = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + assertEquals(0, amyWedding.getNumPersonsForWedding()); + } + + @Test + public void increasePeopleCount() { + Wedding amyWedding = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + amyWedding.increasePeopleCount(); + assertEquals(1, amyWedding.getNumPersonsForWedding()); + } + + @Test + public void decrementPeopleCount() { + Wedding amyWedding = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + amyWedding.increasePeopleCount(); + amyWedding.decreasePeopleCount(); + assertEquals(0, amyWedding.getNumPersonsForWedding()); + } + + @Test + public void canBeDeleted() { + Wedding amyWedding = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + assertTrue(amyWedding.canBeDeleted()); + } +} diff --git a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java index 5e5a196a8ea..56e8970dc00 100644 --- a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java @@ -12,6 +12,8 @@ import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; import seedu.address.model.tag.TagName; +import seedu.address.model.wedding.Wedding; +import seedu.address.model.wedding.WeddingName; /** * A utility class to help with building EditPersonDescriptor objects. @@ -38,6 +40,8 @@ public EditPersonDescriptorBuilder(Person person) { descriptor.setEmail(person.getEmail()); descriptor.setAddress(person.getAddress()); descriptor.setTags(person.getTags()); + // Figure out why this is not possible + //descriptor.setWeddings(person.getWeddings()); } /** @@ -82,6 +86,18 @@ public EditPersonDescriptorBuilder withTags(String... tags) { return this; } + /** + * Parses the {@code weddings} into a {@code Set} and set it to the {@code EditPersonDescriptor} + * that we are building. + */ + + public EditPersonDescriptorBuilder withWeddings(String... weddings) { + Set weddingSet = Stream.of(weddings).map(WeddingName::new).map(Wedding::new) + .collect(Collectors.toSet()); + descriptor.setWeddings(weddingSet); + return this; + } + public EditPersonDescriptor build() { return descriptor; } diff --git a/src/test/java/seedu/address/testutil/PersonUtil.java b/src/test/java/seedu/address/testutil/PersonUtil.java index ee92d61b655..8628a0f31c9 100644 --- a/src/test/java/seedu/address/testutil/PersonUtil.java +++ b/src/test/java/seedu/address/testutil/PersonUtil.java @@ -5,6 +5,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_WEDDING; import java.util.Set; @@ -12,6 +13,7 @@ import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; import seedu.address.model.person.Person; import seedu.address.model.tag.Tag; +import seedu.address.model.wedding.Wedding; /** * A utility class for Person. @@ -35,7 +37,10 @@ public static String getPersonDetails(Person person) { sb.append(PREFIX_EMAIL + person.getEmail().value + " "); sb.append(PREFIX_ADDRESS + person.getAddress().value + " "); person.getTags().stream().forEach( - s -> sb.append(PREFIX_TAG + s.getTagName().toString() + " ") + s -> sb.append(PREFIX_TAG + s.getTagName().toString() + " ") + ); + person.getWeddings().stream().forEach( + s -> sb.append(PREFIX_WEDDING + s.getWeddingName().toString() + " ") ); return sb.toString(); } @@ -57,6 +62,14 @@ public static String getEditPersonDescriptorDetails(EditPersonDescriptor descrip tags.forEach(s -> sb.append(PREFIX_TAG).append(s.getTagName()).append(" ")); } } + if (descriptor.getWeddings().isPresent()) { + Set weddings = descriptor.getWeddings().get(); + if (weddings.isEmpty()) { + sb.append(PREFIX_WEDDING); + } else { + weddings.forEach(s -> sb.append(PREFIX_WEDDING).append(s.getWeddingName()).append(" ")); + } + } return sb.toString(); } } diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java index 46539fc87d8..712f733df21 100644 --- a/src/test/java/seedu/address/testutil/TypicalPersons.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -20,12 +20,13 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_CLIVE; import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_DOMINIC; import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_ERIC; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FLORIST; import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_NEIGHBOR; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_PHOTOGRAPHER; -import static seedu.address.logic.commands.CommandTestUtil.VALID_WEDDING_AMY; +import static seedu.address.testutil.TypicalTags.FLORIST; +import static seedu.address.testutil.TypicalTags.PHOTOGRAPHER; +import static seedu.address.testutil.TypicalWeddings.AMY_WEDDING; +import static seedu.address.testutil.TypicalWeddings.BOB_WEDDING; import java.util.ArrayList; import java.util.Arrays; @@ -33,10 +34,6 @@ import seedu.address.model.AddressBook; import seedu.address.model.person.Person; -import seedu.address.model.tag.Tag; -import seedu.address.model.tag.TagName; -import seedu.address.model.wedding.Wedding; -import seedu.address.model.wedding.WeddingName; /** * A utility class containing a list of {@code Person} objects to be used in tests. @@ -83,13 +80,6 @@ public class TypicalPersons { .withEmail(VALID_EMAIL_ERIC).withAddress(VALID_ADDRESS_ERIC).withTags(VALID_TAG_NEIGHBOR) .build(); - // Manually added Tags - public static final Tag FLORIST = new Tag(new TagName(VALID_TAG_FLORIST)); - public static final Tag PHOTOGRAPHER = new Tag(new TagName(VALID_TAG_PHOTOGRAPHER)); - public static final Wedding WEDDING_ONE = new Wedding(new WeddingName(VALID_WEDDING_AMY)); - - public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER - private TypicalPersons() {} // prevents instantiation /** @@ -97,11 +87,14 @@ private TypicalPersons() {} // prevents instantiation */ public static AddressBook getTypicalAddressBook() { AddressBook ab = new AddressBook(); + ab.addTag(FLORIST); + ab.addTag(PHOTOGRAPHER); + ab.addWedding(AMY_WEDDING); + ab.addWedding(BOB_WEDDING); + for (Person person : getTypicalPersons()) { ab.addPerson(person); } - ab.addTag(FLORIST); - ab.addTag(PHOTOGRAPHER); return ab; } diff --git a/src/test/java/seedu/address/testutil/TypicalTags.java b/src/test/java/seedu/address/testutil/TypicalTags.java new file mode 100644 index 00000000000..633d2f354fa --- /dev/null +++ b/src/test/java/seedu/address/testutil/TypicalTags.java @@ -0,0 +1,17 @@ +package seedu.address.testutil; + +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FLORIST; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_PHOTOGRAPHER; + +import seedu.address.model.tag.Tag; +import seedu.address.model.tag.TagName; + +/** + * A utility class containing a list of {@code Wedding} objects to be used in tests. + */ +public class TypicalTags { + public static final TagName VALID_TAG_NAME_FLORIST = new TagName(VALID_TAG_FLORIST); + public static final TagName VALID_TAG_NAME_PHOTOGRAPHER = new TagName(VALID_TAG_PHOTOGRAPHER); + public static final Tag FLORIST = new Tag(VALID_TAG_NAME_FLORIST); + public static final Tag PHOTOGRAPHER = new Tag(VALID_TAG_NAME_PHOTOGRAPHER); +} diff --git a/src/test/java/seedu/address/testutil/TypicalWeddings.java b/src/test/java/seedu/address/testutil/TypicalWeddings.java new file mode 100644 index 00000000000..31b0c71b95b --- /dev/null +++ b/src/test/java/seedu/address/testutil/TypicalWeddings.java @@ -0,0 +1,16 @@ +package seedu.address.testutil; + +import seedu.address.model.wedding.Wedding; +import seedu.address.model.wedding.WeddingName; + +/** + * A utility class containing a list of {@code Wedding} objects to be used in tests. + */ +public class TypicalWeddings { + public static final String VALID_WEDDING_STRING_AMY_WEDDING = "Amy's Wedding"; + public static final String VALID_WEDDING_STRING_BOB_WEDDING = "Bob's Wedding"; + public static final WeddingName VALID_WEDDING_NAME_AMY_WEDDING = new WeddingName(VALID_WEDDING_STRING_AMY_WEDDING); + public static final WeddingName VALID_WEDDING_NAME_BOB_WEDDING = new WeddingName(VALID_WEDDING_STRING_BOB_WEDDING); + public static final Wedding AMY_WEDDING = new Wedding(VALID_WEDDING_NAME_AMY_WEDDING); + public static final Wedding BOB_WEDDING = new Wedding(VALID_WEDDING_NAME_BOB_WEDDING); +}