From cd4fbe069b041333ca70402a1b7cab166c9eee0e Mon Sep 17 00:00:00 2001 From: KrashKart Date: Sat, 2 Nov 2024 17:35:02 +0800 Subject: [PATCH 1/3] Tidy MESSAGE_USAGEs --- .../address/logic/commands/AddTagCommand.java | 9 +++++---- .../logic/commands/DeleteTagCommand.java | 4 ++-- .../logic/commands/SuperFindCommand.java | 20 +++++++++---------- .../logic/parser/AddTagCommandParser.java | 3 +-- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddTagCommand.java b/src/main/java/seedu/address/logic/commands/AddTagCommand.java index 83ae0fe4c70..9edd501644a 100644 --- a/src/main/java/seedu/address/logic/commands/AddTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddTagCommand.java @@ -20,10 +20,11 @@ public class AddTagCommand extends Command { public static final String COMMAND_WORD = "addtag"; - public static final String MESSAGE_USAGE = COMMAND_WORD + "Add tag(s) for the person identified " - + "by the index number used in the displayed person list " - + "Parameters: INDEX (must be a positive interger) " - + "[" + PREFIX_TAG + "TAG]...\n"; + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Add tag(s) for the person identified " + + "by the index number used in the displayed person list\n" + + "Parameters: INDEX (must be a positive integer) " + + PREFIX_TAG + "TAG [" + PREFIX_TAG + "MORE_TAGS]...\n" + + "Example: " + COMMAND_WORD + " 1 " + PREFIX_TAG + "friend " + PREFIX_TAG + "owesMoney"; public static final String MESSAGE_ADD_TAG_SUCCESS = "Tag added: %1$s"; public static final String MESSAGE_NOT_ADD = "At least one tag to be provided."; diff --git a/src/main/java/seedu/address/logic/commands/DeleteTagCommand.java b/src/main/java/seedu/address/logic/commands/DeleteTagCommand.java index d8989368dc3..50231c00699 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteTagCommand.java @@ -20,8 +20,8 @@ public class DeleteTagCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes tag from the person identified by the index number used in the displayed person list.\n" - + "Parameters: INDEX (must be a positive integer) [TAG NAME]\n" - + "Example: " + COMMAND_WORD + " 1 " + " hello_world"; + + "Parameters: INDEX (must be a positive integer) t/TAG\n" + + "Example: " + COMMAND_WORD + " 1 " + "t/hello_world"; private final Index targetIndex; private final Tag targetTag; diff --git a/src/main/java/seedu/address/logic/commands/SuperFindCommand.java b/src/main/java/seedu/address/logic/commands/SuperFindCommand.java index 8850d43ef3c..aabf9a51ed3 100644 --- a/src/main/java/seedu/address/logic/commands/SuperFindCommand.java +++ b/src/main/java/seedu/address/logic/commands/SuperFindCommand.java @@ -1,6 +1,10 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +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 seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.Messages; @@ -13,20 +17,14 @@ public class SuperFindCommand extends Command { public static final String COMMAND_WORD = "find"; - public static final String NAME_COMMAND_WORD = " n/"; - public static final String EMAIL_COMMAND_WORD = " e/"; - public static final String PHONE_COMMAND_WORD = " p/"; - public static final String TAG_COMMAND_WORD = " t/"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names, phone numbers, emails " - + "or tags contain any of the specified keywords (case-insensitive) and displays" + + "or tags contain any of the specified keywords (case-insensitive) and displays " + "them as a list with indices.\n" - + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" - + "Example:\n" - + COMMAND_WORD + NAME_COMMAND_WORD + "alice bob charlie\n" - + COMMAND_WORD + EMAIL_COMMAND_WORD + "bob@gmail.com\n" - + COMMAND_WORD + PHONE_COMMAND_WORD + "12345678\n" - + COMMAND_WORD + TAG_COMMAND_WORD + "CS2100_classmate\n"; + + "Parameters: PREFIX/KEYWORD [PREFIX/MORE_KEYWORDS]...\n" + + "Examples:\n" + + COMMAND_WORD + " " + PREFIX_NAME + "alice " + PREFIX_PHONE + "80021234 " + PREFIX_TAG + "CS1101S\n" + + COMMAND_WORD + " " + PREFIX_EMAIL + "bob@gmail.com " + PREFIX_EMAIL + "charlotte@yahoo.com"; public static final String MESSAGE_NO_PERSONS_FOUND = "No persons found!"; diff --git a/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java b/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java index a35b7259759..71077a4f33f 100644 --- a/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java @@ -27,8 +27,7 @@ public class AddTagCommandParser implements Parser { */ public AddTagCommand parse(String args) throws ParseException { requireNonNull(args); - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_TAG); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_TAG); Index index; From 68d3e14b920633e6c54decefa0ae6e3d0800b4fc Mon Sep 17 00:00:00 2001 From: KrashKart Date: Sat, 2 Nov 2024 18:32:28 +0800 Subject: [PATCH 2/3] Delete Find subclasses --- .../logic/commands/FindByEmailCommand.java | 36 ------------------- .../logic/commands/FindByNameCommand.java | 35 ------------------ .../logic/commands/FindByPhoneCommand.java | 34 ------------------ .../logic/commands/FindByTagCommand.java | 35 ------------------ 4 files changed, 140 deletions(-) delete mode 100644 src/main/java/seedu/address/logic/commands/FindByEmailCommand.java delete mode 100644 src/main/java/seedu/address/logic/commands/FindByNameCommand.java delete mode 100644 src/main/java/seedu/address/logic/commands/FindByPhoneCommand.java delete mode 100644 src/main/java/seedu/address/logic/commands/FindByTagCommand.java diff --git a/src/main/java/seedu/address/logic/commands/FindByEmailCommand.java b/src/main/java/seedu/address/logic/commands/FindByEmailCommand.java deleted file mode 100644 index 092dba7174e..00000000000 --- a/src/main/java/seedu/address/logic/commands/FindByEmailCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package seedu.address.logic.commands; - -import seedu.address.model.person.EmailContainsKeywordsPredicate; - -/** - * Finds and lists all persons in address book whose email is equivalent to the specified keyword. - * Keyword matching is case-insensitive. - */ -public class FindByEmailCommand extends SuperFindCommand { - - public static final String COMMAND_WORD = "find e/"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose email " - + "is the same as the specified keywords (case-insensitive) and displays them as a list with indices.\n" - + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" - + "Example: " + COMMAND_WORD + " alexyeoh@gmail.com"; - - public FindByEmailCommand(EmailContainsKeywordsPredicate predicate) { - super(predicate); - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - // instanceof handles nulls - if (!(other instanceof FindByEmailCommand)) { - return false; - } - - FindByEmailCommand otherFindCommand = (FindByEmailCommand) other; - return this.getPredicate().equals(otherFindCommand.getPredicate()); - } -} diff --git a/src/main/java/seedu/address/logic/commands/FindByNameCommand.java b/src/main/java/seedu/address/logic/commands/FindByNameCommand.java deleted file mode 100644 index 602a693b614..00000000000 --- a/src/main/java/seedu/address/logic/commands/FindByNameCommand.java +++ /dev/null @@ -1,35 +0,0 @@ -package seedu.address.logic.commands; - -import seedu.address.model.person.NameContainsKeywordsPredicate; - -/** - * Finds and lists all persons in address book whose name contains any of the argument keywords. - * Keyword matching is case-insensitive. - */ -public class FindByNameCommand extends SuperFindCommand { - public static final String COMMAND_WORD = "find n/"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names " - + "contain any of the specified keywords (case-insensitive) and displays them as a list with indices.\n" - + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" - + "Example: " + COMMAND_WORD + " alice bob charlie"; - - public FindByNameCommand(NameContainsKeywordsPredicate predicate) { - super(predicate); - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - // instanceof handles nulls - if (!(other instanceof FindByNameCommand)) { - return false; - } - - FindByNameCommand otherFindCommand = (FindByNameCommand) other; - return this.getPredicate().equals(otherFindCommand.getPredicate()); - } -} diff --git a/src/main/java/seedu/address/logic/commands/FindByPhoneCommand.java b/src/main/java/seedu/address/logic/commands/FindByPhoneCommand.java deleted file mode 100644 index 5e2ffcb432d..00000000000 --- a/src/main/java/seedu/address/logic/commands/FindByPhoneCommand.java +++ /dev/null @@ -1,34 +0,0 @@ -package seedu.address.logic.commands; - -import seedu.address.model.person.PhoneContainsKeywordsPredicate; - -/** - * Finds and lists all persons in address book whose phone number - * contains any of the argument keywords. - */ -public class FindByPhoneCommand extends SuperFindCommand { - public static final String COMMAND_WORD = "find p/"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose phone numbers " - + "contain any of the specified keywords (case-insensitive) and displays them as a list with indices.\n" - + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" - + "Example: " + COMMAND_WORD + " 91112345 999 995"; - public FindByPhoneCommand(PhoneContainsKeywordsPredicate predicate) { - super(predicate); - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - // instanceof handles nulls - if (!(other instanceof FindByPhoneCommand)) { - return false; - } - - FindByPhoneCommand otherFindCommand = (FindByPhoneCommand) other; - return this.getPredicate().equals(otherFindCommand.getPredicate()); - } -} diff --git a/src/main/java/seedu/address/logic/commands/FindByTagCommand.java b/src/main/java/seedu/address/logic/commands/FindByTagCommand.java deleted file mode 100644 index 813e85b39f7..00000000000 --- a/src/main/java/seedu/address/logic/commands/FindByTagCommand.java +++ /dev/null @@ -1,35 +0,0 @@ -package seedu.address.logic.commands; - -import seedu.address.model.person.TagContainsKeywordsPredicate; - -/** - * Finds and lists all persons in address book whose name contains any of the argument keywords. - * Keyword matching is case-insensitive. - */ -public class FindByTagCommand extends SuperFindCommand { - public static final String COMMAND_WORD = "find t/"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose tags " - + "contain any of the specified keywords (case-insensitive) and displays them as a list with indices.\n" - + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" - + "Example: " + COMMAND_WORD + " CS2100_classmate"; - - public FindByTagCommand(TagContainsKeywordsPredicate predicate) { - super(predicate); - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - // instanceof handles nulls - if (!(other instanceof FindByTagCommand)) { - return false; - } - - FindByTagCommand otherFindCommand = (FindByTagCommand) other; - return this.getPredicate().equals(otherFindCommand.getPredicate()); - } -} From 64342dad0421389a99c26c2138dbb325b5b70aee Mon Sep 17 00:00:00 2001 From: KrashKart Date: Sat, 2 Nov 2024 18:34:22 +0800 Subject: [PATCH 3/3] Remove unit tests for find subclasses --- .../commands/FindByEmailCommandTest.java | 88 --------------- .../logic/commands/FindByNameCommandTest.java | 104 ------------------ .../commands/FindByPhoneCommandTest.java | 102 ----------------- .../logic/commands/FindByTagCommandTest.java | 91 --------------- .../logic/parser/CampusConnectParserTest.java | 6 +- 5 files changed, 4 insertions(+), 387 deletions(-) delete mode 100644 src/test/java/seedu/address/logic/commands/FindByEmailCommandTest.java delete mode 100644 src/test/java/seedu/address/logic/commands/FindByNameCommandTest.java delete mode 100644 src/test/java/seedu/address/logic/commands/FindByPhoneCommandTest.java delete mode 100644 src/test/java/seedu/address/logic/commands/FindByTagCommandTest.java diff --git a/src/test/java/seedu/address/logic/commands/FindByEmailCommandTest.java b/src/test/java/seedu/address/logic/commands/FindByEmailCommandTest.java deleted file mode 100644 index 269c2384bff..00000000000 --- a/src/test/java/seedu/address/logic/commands/FindByEmailCommandTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package seedu.address.logic.commands; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static seedu.address.logic.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; -import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.testutil.TypicalPersons.DANIEL; -import static seedu.address.testutil.TypicalPersons.ELLE; -import static seedu.address.testutil.TypicalPersons.getTypicalCampusConnect; - -import java.util.Arrays; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - -import seedu.address.model.Model; -import seedu.address.model.ModelManager; -import seedu.address.model.UserPrefs; -import seedu.address.model.person.EmailContainsKeywordsPredicate; - -public class FindByEmailCommandTest { - - private final Model expectedModel = new ModelManager(getTypicalCampusConnect(), new UserPrefs()); - private final Model model = new ModelManager(getTypicalCampusConnect(), new UserPrefs()); - - @Test - public void equals() { - EmailContainsKeywordsPredicate firstPredicate = - new EmailContainsKeywordsPredicate(Collections.singletonList("first")); - EmailContainsKeywordsPredicate secondPredicate = - new EmailContainsKeywordsPredicate(Collections.singletonList("second")); - - FindByEmailCommand findFirstCommand = new FindByEmailCommand(firstPredicate); - FindByEmailCommand findSecondCommand = new FindByEmailCommand(secondPredicate); - - // same object -> returns true - assertEquals(findFirstCommand, findFirstCommand); - - // same values -> returns true - FindByEmailCommand findFirstCommandCopy = new FindByEmailCommand(firstPredicate); - assertEquals(findFirstCommand, findFirstCommandCopy); - - // different types -> returns false - assertNotEquals(1, findFirstCommand); - - // null -> returns false - assertNotEquals(null, findFirstCommand); - - // different person -> returns false - assertNotEquals(findFirstCommand, findSecondCommand); - } - - @Test - public void execute_zeroKeywords_noPersonFound() { - String expectedMessage = SuperFindCommand.MESSAGE_NO_PERSONS_FOUND; - EmailContainsKeywordsPredicate predicate = preparePredicate(" "); - FindByEmailCommand command = new FindByEmailCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Collections.emptyList(), model.getFilteredPersonList()); - } - - @Test - public void execute_resultsWithPartialMatch_multiplePersonsFound() { - String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 2); - EmailContainsKeywordsPredicate predicate = preparePredicate("ne"); - FindByEmailCommand command = new FindByEmailCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Arrays.asList(DANIEL, ELLE), model.getFilteredPersonList()); - } - - @Test - public void toStringMethod() { - EmailContainsKeywordsPredicate predicate = new EmailContainsKeywordsPredicate(Arrays.asList("keyword")); - FindByEmailCommand findCommand = new FindByEmailCommand(predicate); - String expected = FindByEmailCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; - assertEquals(expected, findCommand.toString()); - } - - /** - * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. - */ - private EmailContainsKeywordsPredicate preparePredicate(String userInput) { - return new EmailContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); - } - -} diff --git a/src/test/java/seedu/address/logic/commands/FindByNameCommandTest.java b/src/test/java/seedu/address/logic/commands/FindByNameCommandTest.java deleted file mode 100644 index 6809f29c5f0..00000000000 --- a/src/test/java/seedu/address/logic/commands/FindByNameCommandTest.java +++ /dev/null @@ -1,104 +0,0 @@ -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.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; -import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.testutil.TypicalPersons.ALICE; -import static seedu.address.testutil.TypicalPersons.BENSON; -import static seedu.address.testutil.TypicalPersons.CARL; -import static seedu.address.testutil.TypicalPersons.DANIEL; -import static seedu.address.testutil.TypicalPersons.ELLE; -import static seedu.address.testutil.TypicalPersons.FIONA; -import static seedu.address.testutil.TypicalPersons.getTypicalCampusConnect; - -import java.util.Arrays; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - -import seedu.address.model.Model; -import seedu.address.model.ModelManager; -import seedu.address.model.UserPrefs; -import seedu.address.model.person.NameContainsKeywordsPredicate; - -/** - * Contains integration tests (interaction with the Model) for {@code FindByNameCommand}. - */ -public class FindByNameCommandTest { - private final Model model = new ModelManager(getTypicalCampusConnect(), new UserPrefs()); - private final Model expectedModel = new ModelManager(getTypicalCampusConnect(), new UserPrefs()); - - @Test - public void equals() { - NameContainsKeywordsPredicate firstPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("first")); - NameContainsKeywordsPredicate secondPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("second")); - - FindByNameCommand findFirstCommand = new FindByNameCommand(firstPredicate); - FindByNameCommand findSecondCommand = new FindByNameCommand(secondPredicate); - - // same object -> returns true - assertTrue(findFirstCommand.equals(findFirstCommand)); - - // same values -> returns true - FindByNameCommand findFirstCommandCopy = new FindByNameCommand(firstPredicate); - assertTrue(findFirstCommand.equals(findFirstCommandCopy)); - - // different types -> returns false - assertFalse(findFirstCommand.equals(1)); - - // null -> returns false - assertFalse(findFirstCommand.equals(null)); - - // different person -> returns false - assertFalse(findFirstCommand.equals(findSecondCommand)); - } - - @Test - public void execute_zeroKeywords_noPersonFound() { - String expectedMessage = SuperFindCommand.MESSAGE_NO_PERSONS_FOUND; - NameContainsKeywordsPredicate predicate = preparePredicate(" "); - FindByNameCommand command = new FindByNameCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Collections.emptyList(), model.getFilteredPersonList()); - } - - @Test - public void execute_multipleKeywords_multiplePersonsFound() { - String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); - NameContainsKeywordsPredicate predicate = preparePredicate("Kurz Elle Kunz"); - FindByNameCommand command = new FindByNameCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredPersonList()); - } - - @Test - public void execute_resultsWithPartialMatch_multiplePersonsFound() { - String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 4); - NameContainsKeywordsPredicate predicate = preparePredicate("n"); - FindByNameCommand command = new FindByNameCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Arrays.asList(ALICE, BENSON, DANIEL, FIONA), model.getFilteredPersonList()); - } - - @Test - public void toStringMethod() { - NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(Arrays.asList("keyword")); - FindByNameCommand findCommand = new FindByNameCommand(predicate); - String expected = FindByNameCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; - assertEquals(expected, findCommand.toString()); - } - - /** - * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. - */ - private NameContainsKeywordsPredicate preparePredicate(String userInput) { - return new NameContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); - } -} diff --git a/src/test/java/seedu/address/logic/commands/FindByPhoneCommandTest.java b/src/test/java/seedu/address/logic/commands/FindByPhoneCommandTest.java deleted file mode 100644 index ac05483b04a..00000000000 --- a/src/test/java/seedu/address/logic/commands/FindByPhoneCommandTest.java +++ /dev/null @@ -1,102 +0,0 @@ -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.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; -import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.testutil.TypicalPersons.ELLE; -import static seedu.address.testutil.TypicalPersons.FIONA; -import static seedu.address.testutil.TypicalPersons.GEORGE; -import static seedu.address.testutil.TypicalPersons.getTypicalCampusConnect; - -import java.util.Arrays; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - -import seedu.address.model.Model; -import seedu.address.model.ModelManager; -import seedu.address.model.UserPrefs; -import seedu.address.model.person.NameContainsKeywordsPredicate; -import seedu.address.model.person.PhoneContainsKeywordsPredicate; - -/** - * Contains integration tests (interaction with the Model) for {@code FindByPhoneCommand}. - */ -public class FindByPhoneCommandTest { - private final Model expectedModel = new ModelManager(getTypicalCampusConnect(), new UserPrefs()); - private final Model model = new ModelManager(getTypicalCampusConnect(), new UserPrefs()); - - @Test - public void equals() { - PhoneContainsKeywordsPredicate firstPredicate = - new PhoneContainsKeywordsPredicate(Collections.singletonList("first")); - PhoneContainsKeywordsPredicate secondPredicate = - new PhoneContainsKeywordsPredicate(Collections.singletonList("second")); - - FindByPhoneCommand findFirstCommand = new FindByPhoneCommand(firstPredicate); - FindByPhoneCommand findSecondCommand = new FindByPhoneCommand(secondPredicate); - - // same object -> returns true - assertTrue(findFirstCommand.equals(findFirstCommand)); - - // same values -> returns true - FindByPhoneCommand findFirstCommandCopy = new FindByPhoneCommand(firstPredicate); - assertTrue(findFirstCommand.equals(findFirstCommandCopy)); - - // different types -> returns false - assertFalse(findFirstCommand.equals(1)); - - // null -> returns false - assertFalse(findFirstCommand.equals(null)); - - // different person -> returns false - assertFalse(findFirstCommand.equals(findSecondCommand)); - } - - @Test - public void execute_zeroKeywords_noPersonFound() { - String expectedMessage = SuperFindCommand.MESSAGE_NO_PERSONS_FOUND; - PhoneContainsKeywordsPredicate predicate = preparePredicate(" "); - FindByPhoneCommand command = new FindByPhoneCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Collections.emptyList(), model.getFilteredPersonList()); - } - - @Test - public void execute_resultsWithPartialMatch_multiplePersonsFound() { - String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); - PhoneContainsKeywordsPredicate predicate = preparePredicate("82"); - FindByPhoneCommand command = new FindByPhoneCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Arrays.asList(ELLE, FIONA, GEORGE), model.getFilteredPersonList()); - } - - @Test - public void execute_multipleKeywords_multiplePersonsFound() { - String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); - PhoneContainsKeywordsPredicate predicate = preparePredicate("8482 6482"); - FindByPhoneCommand command = new FindByPhoneCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Arrays.asList(ELLE, FIONA, GEORGE), model.getFilteredPersonList()); - } - - @Test - public void toStringMethod() { - NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(Arrays.asList("keyword")); - FindByNameCommand findCommand = new FindByNameCommand(predicate); - String expected = FindByNameCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; - assertEquals(expected, findCommand.toString()); - } - - /** - * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. - */ - private PhoneContainsKeywordsPredicate preparePredicate(String userInput) { - return new PhoneContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); - } -} diff --git a/src/test/java/seedu/address/logic/commands/FindByTagCommandTest.java b/src/test/java/seedu/address/logic/commands/FindByTagCommandTest.java deleted file mode 100644 index 1dae126b209..00000000000 --- a/src/test/java/seedu/address/logic/commands/FindByTagCommandTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package seedu.address.logic.commands; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static seedu.address.logic.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; -import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.testutil.TypicalPersons.ALICE; -import static seedu.address.testutil.TypicalPersons.BENSON; -import static seedu.address.testutil.TypicalPersons.DANIEL; -import static seedu.address.testutil.TypicalPersons.getTypicalCampusConnect; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.junit.jupiter.api.Test; - -import seedu.address.model.Model; -import seedu.address.model.ModelManager; -import seedu.address.model.UserPrefs; -import seedu.address.model.person.TagContainsKeywordsPredicate; - -public class FindByTagCommandTest { - - private final Model expectedModel = new ModelManager(getTypicalCampusConnect(), new UserPrefs()); - private final Model model = new ModelManager(getTypicalCampusConnect(), new UserPrefs()); - - @Test - public void equals() { - TagContainsKeywordsPredicate firstPredicate = - new TagContainsKeywordsPredicate(Collections.singletonList("CS2100classmate")); - TagContainsKeywordsPredicate secondPredicate = - new TagContainsKeywordsPredicate(Collections.singletonList("CS1101STA")); - - FindByTagCommand findFirstCommand = new FindByTagCommand(firstPredicate); - FindByTagCommand findSecondCommand = new FindByTagCommand(secondPredicate); - - // same object -> returns true - assertEquals(findFirstCommand, findFirstCommand); - - // same values -> returns true - FindByTagCommand findFirstCommandCopy = new FindByTagCommand(firstPredicate); - assertEquals(findFirstCommand, findFirstCommandCopy); - - // different types -> returns false - assertNotEquals(1, findFirstCommand); - - // null -> returns false - assertNotEquals(null, findFirstCommand); - - // different person -> returns false - assertNotEquals(findFirstCommand, findSecondCommand); - } - - @Test - public void execute_zeroKeywords_noPersonFound() { - String expectedMessage = SuperFindCommand.MESSAGE_NO_PERSONS_FOUND; - TagContainsKeywordsPredicate predicate = preparePredicate(" "); - FindByTagCommand command = new FindByTagCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Collections.emptyList(), model.getFilteredPersonList()); - } - - @Test - public void execute_resultsWithPartialMatch_multiplePersonsFound() { - System.out.println(expectedModel.getCampusConnect().toString()); - String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); - TagContainsKeywordsPredicate predicate = preparePredicate("en"); - FindByTagCommand command = new FindByTagCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Arrays.asList(ALICE, BENSON, DANIEL), model.getFilteredPersonList()); - } - - @Test - public void toStringMethod() { - TagContainsKeywordsPredicate predicate = new TagContainsKeywordsPredicate(List.of("keyword")); - FindByTagCommand findCommand = new FindByTagCommand(predicate); - String expected = FindByTagCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; - assertEquals(expected, findCommand.toString()); - } - - /** - * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. - */ - private TagContainsKeywordsPredicate preparePredicate(String userInput) { - return new TagContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); - } - -} diff --git a/src/test/java/seedu/address/logic/parser/CampusConnectParserTest.java b/src/test/java/seedu/address/logic/parser/CampusConnectParserTest.java index cdcd2413cd6..0405a91cf6a 100644 --- a/src/test/java/seedu/address/logic/parser/CampusConnectParserTest.java +++ b/src/test/java/seedu/address/logic/parser/CampusConnectParserTest.java @@ -4,6 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; +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 static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; @@ -82,7 +84,7 @@ public void parseCommand_findByName() throws Exception { ); String input = SuperFindCommand.COMMAND_WORD + " " + keywords.stream() - .map(keyword -> SuperFindCommand.NAME_COMMAND_WORD + keyword) + .map(keyword -> PREFIX_NAME + keyword) .collect(Collectors.joining(" ")); Command command = parser.parseCommand(input); assertEquals(expectedCommand, command); @@ -99,7 +101,7 @@ public void parseCommand_findByPhone() throws Exception { ); String input = SuperFindCommand.COMMAND_WORD + " " + keywords.stream() - .map(keyword -> SuperFindCommand.PHONE_COMMAND_WORD + keyword) + .map(keyword -> PREFIX_PHONE + keyword) .collect(Collectors.joining(" ")); Command command = parser.parseCommand(input); assertEquals(expectedCommand, command);