diff --git a/src/main/java/seedu/foodrem/model/item/NameContainsKeywordsPredicate.java b/src/main/java/seedu/foodrem/model/item/NameContainsKeywordsPredicate.java index 17ed4e083e6..39a67309abc 100644 --- a/src/main/java/seedu/foodrem/model/item/NameContainsKeywordsPredicate.java +++ b/src/main/java/seedu/foodrem/model/item/NameContainsKeywordsPredicate.java @@ -18,7 +18,7 @@ public NameContainsKeywordsPredicate(List keywords) { @Override public boolean test(Item item) { return keywords.stream() - .anyMatch(keyword -> StringUtil.containsSubstringIgnoreCase(item.getName().toString(), keyword)); + .allMatch(keyword -> StringUtil.containsSubstringIgnoreCase(item.getName().toString(), keyword)); } @Override diff --git a/src/test/java/seedu/foodrem/logic/commands/itemcommands/FindCommandTest.java b/src/test/java/seedu/foodrem/logic/commands/itemcommands/FindCommandTest.java index 0a866065d7c..ab833f84abd 100644 --- a/src/test/java/seedu/foodrem/logic/commands/itemcommands/FindCommandTest.java +++ b/src/test/java/seedu/foodrem/logic/commands/itemcommands/FindCommandTest.java @@ -54,22 +54,22 @@ public void equals() { @Test public void execute_zeroKeywords_noItemsFound() { - String expectedMessage = String.format(MESSAGE_ITEMS_LISTED_OVERVIEW, 0); + String expectedMessage = String.format(MESSAGE_ITEMS_LISTED_OVERVIEW, 2); NameContainsKeywordsPredicate predicate = preparePredicate(" "); FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredItemList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Collections.emptyList(), model.getCurrentList()); + assertEquals(Arrays.asList(POTATOES, CUCUMBERS), model.getCurrentList()); } @Test public void execute_multipleKeywords_multipleItemsFound() { - String expectedMessage = String.format(MESSAGE_ITEMS_LISTED_OVERVIEW, 2); + String expectedMessage = String.format(MESSAGE_ITEMS_LISTED_OVERVIEW, 0); NameContainsKeywordsPredicate predicate = preparePredicate("Potatoes Cucumbers Carrots"); FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredItemList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Arrays.asList(POTATOES, CUCUMBERS), model.getCurrentList()); + assertEquals(Collections.emptyList(), model.getCurrentList()); } /** diff --git a/src/test/java/seedu/foodrem/model/item/NameContainsKeywordsPredicateTest.java b/src/test/java/seedu/foodrem/model/item/NameContainsKeywordsPredicateTest.java index 5f11ddb756c..da023574923 100644 --- a/src/test/java/seedu/foodrem/model/item/NameContainsKeywordsPredicateTest.java +++ b/src/test/java/seedu/foodrem/model/item/NameContainsKeywordsPredicateTest.java @@ -13,6 +13,7 @@ import seedu.foodrem.testutil.ItemBuilder; +// TODO: Properly test this public class NameContainsKeywordsPredicateTest { @Test public void equals() { @@ -52,7 +53,7 @@ public void test_nameContainsKeywords_returnsTrue() { // Only one matching keyword predicate = new NameContainsKeywordsPredicate(Arrays.asList("Potato", "Cuc")); - assertTrue(predicate.test(new ItemBuilder().withItemName("Potato Carol").build())); + assertFalse(predicate.test(new ItemBuilder().withItemName("Potato Carol").build())); // Mixed-case keywords predicate = new NameContainsKeywordsPredicate(Arrays.asList("PoTAto", "CuCUmber")); @@ -63,7 +64,7 @@ public void test_nameContainsKeywords_returnsTrue() { public void test_nameDoesNotContainKeywords_returnsFalse() { // Zero keywords NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(Collections.emptyList()); - assertFalse(predicate.test(new ItemBuilder().withItemName("Potato").build())); + assertTrue(predicate.test(new ItemBuilder().withItemName("Potato").build())); // Non-matching keyword predicate = new NameContainsKeywordsPredicate(List.of("Carrots")); @@ -71,8 +72,7 @@ public void test_nameDoesNotContainKeywords_returnsFalse() { // Keywords match quantity, bought date and expiry date, and name as it is a substring predicate = new NameContainsKeywordsPredicate(Arrays.asList("Potato", "12345", "11-11-2022", "12-12-2022")); - // TODO: Move this to the correct test method - assertTrue(predicate.test(new ItemBuilder() + assertFalse(predicate.test(new ItemBuilder() .withItemName("Potatoes") .withItemQuantity("12345") .withItemBoughtDate("11-11-2022")