forked from AY2425S1-CS2103T-F11-2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
3 changed files
with
92 additions
and
3 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
85 changes: 85 additions & 0 deletions
85
src/test/java/seedu/address/model/person/TelegramContainsKeywordsPredicateTest.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,85 @@ | ||
package seedu.address.model.person; | ||
|
||
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 java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.testutil.PersonBuilder; | ||
|
||
public class TelegramContainsKeywordsPredicateTest { | ||
|
||
@Test | ||
public void equals() { | ||
List<String> firstPredicateKeywordList = Collections.singletonList("first"); | ||
List<String> secondPredicateKeywordList = Arrays.asList("first", "second"); | ||
|
||
TelegramContainsKeywordsPredicate firstPredicate = new TelegramContainsKeywordsPredicate( | ||
firstPredicateKeywordList); | ||
TelegramContainsKeywordsPredicate secondPredicate = new TelegramContainsKeywordsPredicate( | ||
secondPredicateKeywordList); | ||
|
||
// same object -> returns true | ||
assertTrue(firstPredicate.equals(firstPredicate)); | ||
|
||
// same values -> returns true | ||
TelegramContainsKeywordsPredicate firstPredicateCopy = new TelegramContainsKeywordsPredicate( | ||
firstPredicateKeywordList); | ||
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)); | ||
} | ||
|
||
@Test | ||
public void test_telegramContainsKeywords_returnsTrue() { | ||
// One keyword | ||
TelegramContainsKeywordsPredicate predicate = new TelegramContainsKeywordsPredicate(Collections | ||
.singletonList("javierTan")); | ||
assertTrue(predicate.test(new PersonBuilder().withTelegram("javierTan").build())); | ||
|
||
// Multiple keywords | ||
predicate = new TelegramContainsKeywordsPredicate(Arrays.asList("javiertan", "melinda")); | ||
assertTrue(predicate.test(new PersonBuilder().withTelegram("melinda").build())); | ||
|
||
// Mixed-case keywords | ||
predicate = new TelegramContainsKeywordsPredicate(Arrays.asList("AbCd", "QqQQ")); | ||
assertTrue(predicate.test(new PersonBuilder().withTelegram("abcd").build())); | ||
} | ||
|
||
@Test | ||
public void test_nameDoesNotContainKeywords_returnsFalse() { | ||
// Zero keywords | ||
TelegramContainsKeywordsPredicate predicate = new TelegramContainsKeywordsPredicate(Collections.emptyList()); | ||
assertFalse(predicate.test(new PersonBuilder().withTelegram("alisa").build())); | ||
|
||
// Non-matching keyword | ||
predicate = new TelegramContainsKeywordsPredicate(Arrays.asList("ben")); | ||
assertFalse(predicate.test(new PersonBuilder().withTelegram("boy").build())); | ||
|
||
// Keywords match name, phone and role, but does not match telegram | ||
predicate = new TelegramContainsKeywordsPredicate(Arrays.asList("Alice", "12345678", "alice", "member")); | ||
assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("12345678") | ||
.withTelegram("alicePauline").withRoles("member").build())); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
List<String> keywords = List.of("keyword1", "keyword2"); | ||
TelegramContainsKeywordsPredicate predicate = new TelegramContainsKeywordsPredicate(keywords); | ||
|
||
String expected = TelegramContainsKeywordsPredicate.class.getCanonicalName() + "{keywords=" + keywords + "}"; | ||
assertEquals(expected, predicate.toString()); | ||
} | ||
} |