|
| 1 | +package seedu.address.logic.commands; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 6 | +import static seedu.address.commons.core.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; |
| 7 | +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; |
| 8 | +import static seedu.address.testutil.TypicalPersons.ALICE; |
| 9 | +import static seedu.address.testutil.TypicalPersons.BENSON; |
| 10 | +import static seedu.address.testutil.TypicalPersons.DANIEL; |
| 11 | +import static seedu.address.testutil.TypicalPersons.JENNY; |
| 12 | +import static seedu.address.testutil.TypicalPersons.WENDY; |
| 13 | +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; |
| 14 | + |
| 15 | +import java.util.Arrays; |
| 16 | +import java.util.Collections; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | + |
| 20 | +import seedu.address.logic.commands.persons.FindGroupCommand; |
| 21 | +import seedu.address.model.Model; |
| 22 | +import seedu.address.model.ModelManager; |
| 23 | +import seedu.address.model.UserPrefs; |
| 24 | +import seedu.address.model.group.GroupContainsKeywordsPredicate; |
| 25 | + |
| 26 | +/** |
| 27 | + * Contains integration tests (interaction with the Model) for {@code FindGroupCommand}. |
| 28 | + */ |
| 29 | +public class FindGroupCommandTest { |
| 30 | + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); |
| 31 | + private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); |
| 32 | + |
| 33 | + @Test |
| 34 | + public void equals() { |
| 35 | + GroupContainsKeywordsPredicate firstPredicate = |
| 36 | + new GroupContainsKeywordsPredicate(Collections.singletonList("first")); |
| 37 | + GroupContainsKeywordsPredicate secondPredicate = |
| 38 | + new GroupContainsKeywordsPredicate(Collections.singletonList("second")); |
| 39 | + |
| 40 | + FindGroupCommand findFirstCommand = new FindGroupCommand(firstPredicate); |
| 41 | + FindGroupCommand findSecondCommand = new FindGroupCommand(secondPredicate); |
| 42 | + |
| 43 | + // same object -> returns true |
| 44 | + assertTrue(findFirstCommand.equals(findFirstCommand)); |
| 45 | + |
| 46 | + // same values -> returns true |
| 47 | + FindGroupCommand findFirstCommandCopy = new FindGroupCommand(firstPredicate); |
| 48 | + assertTrue(findFirstCommand.equals(findFirstCommandCopy)); |
| 49 | + |
| 50 | + // different types -> returns false |
| 51 | + assertFalse(findFirstCommand.equals(1)); |
| 52 | + |
| 53 | + // null -> returns false |
| 54 | + assertFalse(findFirstCommand.equals(null)); |
| 55 | + |
| 56 | + // different person -> returns false |
| 57 | + assertFalse(findFirstCommand.equals(findSecondCommand)); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void execute_zeroKeywords_noPersonFound() { |
| 62 | + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); |
| 63 | + GroupContainsKeywordsPredicate predicate = preparePredicate(" "); |
| 64 | + FindGroupCommand command = new FindGroupCommand(predicate); |
| 65 | + expectedModel.updateFilteredPersonList(predicate); |
| 66 | + assertCommandSuccess(command, model, expectedMessage, expectedModel); |
| 67 | + assertEquals(Collections.emptyList(), model.getFilteredPersonList()); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Correctly returns an empty collection when a non-existing group is inputted as keyword |
| 72 | + */ |
| 73 | + @Test |
| 74 | + public void execute_wrongKeywords_noPersonFound() { |
| 75 | + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); |
| 76 | + GroupContainsKeywordsPredicate predicate = preparePredicate("test"); |
| 77 | + FindGroupCommand command = new FindGroupCommand(predicate); |
| 78 | + expectedModel.updateFilteredPersonList(predicate); |
| 79 | + assertCommandSuccess(command, model, expectedMessage, expectedModel); |
| 80 | + assertEquals(Collections.emptyList(), model.getFilteredPersonList()); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Correctly returns all people in the specified group - first test |
| 85 | + */ |
| 86 | + @Test |
| 87 | + public void execute_multipleGroupsFoundFirst() { |
| 88 | + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); |
| 89 | + GroupContainsKeywordsPredicate predicate = preparePredicate("table tennis"); |
| 90 | + FindGroupCommand command = new FindGroupCommand(predicate); |
| 91 | + expectedModel.updateFilteredPersonList(predicate); |
| 92 | + assertCommandSuccess(command, model, expectedMessage, expectedModel); |
| 93 | + assertEquals(Arrays.asList(ALICE, BENSON, DANIEL), model.getFilteredPersonList()); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Correctly returns all people in the specified group - second test |
| 98 | + */ |
| 99 | + @Test |
| 100 | + public void execute_multipleGroupsFoundSecond() { |
| 101 | + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); |
| 102 | + GroupContainsKeywordsPredicate predicate = preparePredicate("CS2106"); |
| 103 | + FindGroupCommand command = new FindGroupCommand(predicate); |
| 104 | + expectedModel.updateFilteredPersonList(predicate); |
| 105 | + assertCommandSuccess(command, model, expectedMessage, expectedModel); |
| 106 | + assertEquals(Arrays.asList(BENSON, JENNY, WENDY), model.getFilteredPersonList()); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Correctly returns all people in groups with the partial keyword |
| 111 | + */ |
| 112 | + @Test |
| 113 | + public void execute_partialGroupKeyword_multipleGroupsFound() { |
| 114 | + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); |
| 115 | + GroupContainsKeywordsPredicate predicate = preparePredicate("table"); |
| 116 | + FindGroupCommand command = new FindGroupCommand(predicate); |
| 117 | + expectedModel.updateFilteredPersonList(predicate); |
| 118 | + assertCommandSuccess(command, model, expectedMessage, expectedModel); |
| 119 | + assertEquals(Arrays.asList(ALICE, BENSON, DANIEL), model.getFilteredPersonList()); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Parses {@code userInput} into a {@code GroupContainsKeywordsPredicate}. |
| 124 | + */ |
| 125 | + private GroupContainsKeywordsPredicate preparePredicate(String userInput) { |
| 126 | + return new GroupContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); |
| 127 | + } |
| 128 | +} |
| 129 | + |
0 commit comments