forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f63a4d
commit ff95db4
Showing
6 changed files
with
198 additions
and
1 deletion.
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
77 changes: 77 additions & 0 deletions
77
src/test/java/seedu/address/logic/commands/DetailsCommandTest.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,77 @@ | ||
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.commons.core.Messages.MESSAGE_PERSON_DETAILS_FOUND; | ||
import static seedu.address.commons.core.Messages.MESSAGE_PERSON_DETAILS_NOT_FOUND; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.testutil.TypicalPersons.CARL; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
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.Name; | ||
import seedu.address.model.person.NameEqualKeywordPredicate; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) for {@code DetailsCommand}. | ||
*/ | ||
class DetailsCommandTest { | ||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void equals() { | ||
NameEqualKeywordPredicate firstPredicate = | ||
new NameEqualKeywordPredicate(new Name("first")); | ||
NameEqualKeywordPredicate secondPredicate = | ||
new NameEqualKeywordPredicate(new Name("second")); | ||
|
||
DetailsCommand findFirstCommand = new DetailsCommand(firstPredicate); | ||
DetailsCommand findSecondCommand = new DetailsCommand(secondPredicate); | ||
|
||
// same object -> returns true | ||
assertTrue(findFirstCommand.equals(findFirstCommand)); | ||
|
||
// same values -> returns true | ||
DetailsCommand findFirstCommandCopy = new DetailsCommand(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 name = "cool name"; | ||
String expectedMessage = String.format(MESSAGE_PERSON_DETAILS_NOT_FOUND, name); | ||
NameEqualKeywordPredicate predicate = new NameEqualKeywordPredicate(new Name(name)); | ||
DetailsCommand command = new DetailsCommand(predicate); | ||
expectedModel.updateFilteredPersonList(predicate); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
assertEquals(Collections.emptyList(), model.getFilteredPersonList()); | ||
} | ||
|
||
@Test | ||
public void execute_multipleKeywords_multiplePersonsFound() { | ||
Name name = CARL.getName(); | ||
String expectedMessage = String.format(MESSAGE_PERSON_DETAILS_FOUND, name); | ||
NameEqualKeywordPredicate predicate = new NameEqualKeywordPredicate(name); | ||
DetailsCommand command = new DetailsCommand(predicate); | ||
expectedModel.updateFilteredPersonList(predicate); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
assertEquals(Collections.singletonList(CARL), model.getFilteredPersonList()); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/test/java/seedu/address/logic/parser/DetailsCommandParserTest.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,40 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.DetailsCommand; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.NameEqualKeywordPredicate; | ||
|
||
class DetailsCommandParserTest { | ||
|
||
private DetailsCommandParser parser = new DetailsCommandParser(); | ||
|
||
@Test | ||
public void parse_emptyArg_throwsParseException() { | ||
assertParseFailure(parser, " ", | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DetailsCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
@Test | ||
public void parse_validArgs_returnsDetailsCommand() { | ||
DetailsCommand expectedFindCommand = | ||
new DetailsCommand(new NameEqualKeywordPredicate(new Name("Alice Bob"))); | ||
|
||
// No trailing and leading whitespace | ||
assertParseSuccess(parser, "Alice Bob", expectedFindCommand); | ||
|
||
// Leading whitespace | ||
assertParseSuccess(parser, " Alice Bob", expectedFindCommand); | ||
|
||
// Trailing whitespace | ||
assertParseSuccess(parser, "Alice Bob ", expectedFindCommand); | ||
|
||
// Leading and trailing whitespace | ||
assertParseSuccess(parser, " Alice Bob ", expectedFindCommand); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/test/java/seedu/address/model/person/NameEqualKeywordPredicateTest.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,70 @@ | ||
package seedu.address.model.person; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.testutil.PersonBuilder; | ||
|
||
class NameEqualKeywordPredicateTest { | ||
@Test | ||
public void equals() { | ||
String firstKeyword = "keyword"; | ||
String secondKeyword = "Keyword"; | ||
String thirdKeyword = "keyword "; | ||
|
||
NameEqualKeywordPredicate firstPredicate = new NameEqualKeywordPredicate(new Name(firstKeyword)); | ||
NameEqualKeywordPredicate secondPredicate = new NameEqualKeywordPredicate(new Name(secondKeyword)); | ||
NameEqualKeywordPredicate thirdPredicate = new NameEqualKeywordPredicate(new Name(thirdKeyword)); | ||
|
||
// same object -> returns true | ||
assertTrue(firstPredicate.equals(firstPredicate)); | ||
|
||
// same values -> returns true | ||
NameEqualKeywordPredicate firstPredicateCopy = new NameEqualKeywordPredicate(new Name(firstKeyword)); | ||
assertTrue(firstPredicate.equals(firstPredicateCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(firstPredicate.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(firstPredicate.equals(null)); | ||
|
||
// different person -> returns false | ||
assertFalse(firstPredicate.equals(secondPredicate)); | ||
|
||
// extra spacing -> returns false | ||
assertFalse(thirdPredicate.equals(firstPredicate)); | ||
} | ||
|
||
@Test | ||
public void test_nameMatchKeyword_returnsTrue() { | ||
// Exact 1 word match | ||
NameEqualKeywordPredicate predicate = new NameEqualKeywordPredicate(new Name("Alice")); | ||
assertTrue(predicate.test(new PersonBuilder().withName("Alice").build())); | ||
|
||
// Exact 2 word match | ||
predicate = new NameEqualKeywordPredicate(new Name("Alice Bob")); | ||
assertTrue(predicate.test(new PersonBuilder().withName("Alice Bob").build())); | ||
} | ||
|
||
@Test | ||
public void test_nameDoesNotMatchKeyword_returnsFalse() { | ||
// Non-matching keyword | ||
NameEqualKeywordPredicate predicate = new NameEqualKeywordPredicate(new Name("Carol")); | ||
assertFalse(predicate.test(new PersonBuilder().withName("Alice").build())); | ||
|
||
// Partial match | ||
predicate = new NameEqualKeywordPredicate(new Name("Carol")); | ||
assertFalse(predicate.test(new PersonBuilder().withName("Caroline").build())); | ||
|
||
// Partial match 2 words | ||
predicate = new NameEqualKeywordPredicate(new Name("Bob")); | ||
assertFalse(predicate.test(new PersonBuilder().withName("Bob boy").build())); | ||
|
||
// Predicate with more words than person | ||
predicate = new NameEqualKeywordPredicate(new Name("Bob the builder")); | ||
assertFalse(predicate.test(new PersonBuilder().withName("Bob").build())); | ||
} | ||
} |