forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for FindByEmailCommand
- Loading branch information
Showing
4 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/java/seedu/address/logic/commands/FindByEmailCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
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.getTypicalAddressBook; | ||
|
||
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(getTypicalAddressBook(), new UserPrefs()); | ||
private final Model model = new ModelManager(getTypicalAddressBook(), 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 = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); | ||
EmailContainsKeywordsPredicate predicate = preparePredicate(" "); | ||
FindByEmailCommand command = new FindByEmailCommand(predicate); | ||
expectedModel.updateFilteredPersonList(predicate); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
assertEquals(Collections.emptyList(), 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+"))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,10 @@ | |
|
||
import seedu.address.logic.commands.AbstractFindCommand; | ||
import seedu.address.logic.commands.FindByContactCommand; | ||
import seedu.address.logic.commands.FindByEmailCommand; | ||
import seedu.address.logic.commands.FindByNameCommand; | ||
import seedu.address.model.person.ContactContainsKeywordsPredicate; | ||
import seedu.address.model.person.EmailContainsKeywordsPredicate; | ||
import seedu.address.model.person.NameContainsKeywordsPredicate; | ||
|
||
public class FindCommandParserTest { | ||
|
@@ -49,4 +51,17 @@ public void parse_validArgs_returnsFindByContactCommand() { | |
assertParseSuccess(parser, "/c \n 91234567 \n \t 995 \t", expectedFindCommand); | ||
} | ||
|
||
@Test | ||
public void parse_validArgs_returnsFindByEmailCommand() { | ||
FindByEmailCommand expectedFindCommand = | ||
new FindByEmailCommand(new EmailContainsKeywordsPredicate( | ||
Arrays.asList("[email protected]", "[email protected]"))); | ||
|
||
// no leading and trailing whitespaces | ||
assertParseSuccess(parser, "/e [email protected] [email protected]", expectedFindCommand); | ||
|
||
// multiple whitespaces between keywords | ||
assertParseSuccess(parser, "/e \n [email protected] \n \t [email protected] \t", expectedFindCommand); | ||
} | ||
|
||
} |