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 finding contacts by email
- Loading branch information
Showing
2 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
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,95 @@ | ||
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 seedu.address.model.person.EmailContainsKeywordsPredicate; | ||
import static seedu.address.testutil.TypicalPersons.CARL; | ||
import static seedu.address.testutil.TypicalPersons.ELLE; | ||
import static seedu.address.testutil.TypicalPersons.FIONA; | ||
import static seedu.address.testutil.TypicalPersons.INA; | ||
import static seedu.address.testutil.TypicalPersons.REG; | ||
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.ContactContainsKeywordsPredicate; | ||
import seedu.address.model.person.NameContainsKeywordsPredicate; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) for {@code FindByContactCommand}. | ||
*/ | ||
public class FindByEmailCommandTest { | ||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private Model expectedModel = 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 | ||
assertTrue(findFirstCommand.equals(findFirstCommand)); | ||
|
||
// same values -> returns true | ||
FindByEmailCommand findFirstCommandCopy = new FindByEmailCommand(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 = 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 execute_multipleKeywords_multiplePersonsFound() { | ||
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 2); | ||
EmailContainsKeywordsPredicate predicate = preparePredicate("[email protected]"); | ||
FindByEmailCommand command = new FindByEmailCommand(predicate); | ||
expectedModel.updateFilteredPersonList(predicate); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
assertEquals(Arrays.asList(REG, INA), 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 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 |
---|---|---|
|
@@ -48,6 +48,12 @@ public class TypicalPersons { | |
public static final Person IDA = new PersonBuilder().withName("Ida Mueller").withPhone("8482131") | ||
.withEmail("[email protected]").withAddress("chicago ave").build(); | ||
|
||
// same emails for FindByEmailCommandTest | ||
public static final Person REG = new PersonBuilder().withName("Reg Loo").withPhone("8482424") | ||
.withEmail("[email protected]").withAddress("little india").build(); | ||
public static final Person INA = new PersonBuilder().withName("Ina Crust").withPhone("8482131") | ||
.withEmail("[email protected]").withAddress("chicago ave").build(); | ||
|
||
// Manually added - Person's details found in {@code CommandTestUtil} | ||
public static final Person AMY = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY) | ||
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY).withTags(VALID_TAG_FRIEND).build(); | ||
|
@@ -71,6 +77,6 @@ public static AddressBook getTypicalAddressBook() { | |
} | ||
|
||
public static List<Person> getTypicalPersons() { | ||
return new ArrayList<>(Arrays.asList(ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE)); | ||
return new ArrayList<>(Arrays.asList(ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE, REG, INA)); | ||
} | ||
} |