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.
Let's * modify the regex to account for whitespace characters * implement unit tests for AddressBookParser and FindByNameCommand * modify unit test for FindCommandParserTest * implement equals method (overwriting) for FindByNameCommand
- Loading branch information
Showing
6 changed files
with
135 additions
and
27 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
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
91 changes: 91 additions & 0 deletions
91
src/test/java/seedu/address/logic/commands/FindByNameCommandTest.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,91 @@ | ||
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.CARL; | ||
import static seedu.address.testutil.TypicalPersons.ELLE; | ||
import static seedu.address.testutil.TypicalPersons.FIONA; | ||
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.NameContainsKeywordsPredicate; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) for {@code FindCommand}. | ||
*/ | ||
public class FindByNameCommandTest { | ||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private Model expectedModel = new ModelManager(getTypicalAddressBook(), 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 = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); | ||
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 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+"))); | ||
} | ||
} |
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