Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing for Weddings #98

Merged
merged 10 commits into from
Oct 17, 2024
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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 "
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ public void setPersons(List<Person> 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<Tag> tags) {
this.tags.setTags(tags);
}

/**
* Replaces the contents of the wedding list with {@code weddings}.
* {@code weddings} must not contain duplicate tags.
Expand Down Expand Up @@ -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<Tag> tags) {
this.tags.setTags(tags);
}

/**
* Removes {@code key} from this {@code AddressBook}.
* {@code key} must exist in the address book.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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<Wedding> 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<Wedding> 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<Wedding> weddingsToAdd = new HashSet<>(Arrays.asList(unseenWedding));
AssignWeddingCommand assignWeddingCommand = new AssignWeddingCommand(
INDEX_FIRST_PERSON, weddingsToAdd);
String expectedMessage = Messages.MESSAGE_WEDDING_NOT_FOUND;
CommandTestUtil.assertCommandFailure(assignWeddingCommand, model, expectedMessage);
}

@Test
public void sameCommandTest_success() {
HashSet<Wedding> 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<Wedding> weddingsToRemove = new HashSet<>();
AssignWeddingCommand command1 = new AssignWeddingCommand(INDEX_FIRST_PERSON, weddingsToRemove);
assertFalse(command1.equals(null));
}

@Test
public void differentIndex_fail() {
HashSet<Wedding> 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<Wedding> weddingsToRemove1 = new HashSet<>();
HashSet<Wedding> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)
Expand Down
Loading