From 0283250d1dcfe66f28b608a56441af021e87cd8c Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Fri, 9 Oct 2020 17:01:28 +0800 Subject: [PATCH 01/14] Add functionality to find suppliers by products sold --- .../clinic/logic/commands/FindCommand.java | 14 +++---- .../logic/parser/FindCommandParser.java | 12 ++++-- .../NameContainsKeywordsPredicate.java | 31 -------------- .../ProductsContainKeywordsPredicate.java | 42 +++++++++++++++++++ 4 files changed, 58 insertions(+), 41 deletions(-) delete mode 100644 src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java create mode 100644 src/main/java/seedu/clinic/model/supplier/ProductsContainKeywordsPredicate.java diff --git a/src/main/java/seedu/clinic/logic/commands/FindCommand.java b/src/main/java/seedu/clinic/logic/commands/FindCommand.java index 664d32f8adb..e581e319f8e 100644 --- a/src/main/java/seedu/clinic/logic/commands/FindCommand.java +++ b/src/main/java/seedu/clinic/logic/commands/FindCommand.java @@ -4,24 +4,24 @@ import seedu.clinic.commons.core.Messages; import seedu.clinic.model.Model; -import seedu.clinic.model.supplier.NameContainsKeywordsPredicate; +import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; /** - * Finds and lists all suppliers in the CLI-nic app whose name contains any of the argument keywords. + * Finds and lists all suppliers in the CLI-nic app that sell products matching any of the argument keywords. * Keyword matching is case insensitive. */ public class FindCommand extends Command { public static final String COMMAND_WORD = "find"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all suppliers whose names contain any of " + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all suppliers that sell products matching " + "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" - + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" - + "Example: " + COMMAND_WORD + " alice bob charlie"; + + "Parameters: TYPE KEYWORD [MORE_KEYWORDS]...\n" + + "Example: " + COMMAND_WORD + " supplier panadol"; - private final NameContainsKeywordsPredicate predicate; + private final ProductsContainKeywordsPredicate predicate; - public FindCommand(NameContainsKeywordsPredicate predicate) { + public FindCommand(ProductsContainKeywordsPredicate predicate) { this.predicate = predicate; } diff --git a/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java b/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java index 48574d1793b..ff973eb2863 100644 --- a/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java @@ -6,7 +6,7 @@ import seedu.clinic.logic.commands.FindCommand; import seedu.clinic.logic.parser.exceptions.ParseException; -import seedu.clinic.model.supplier.NameContainsKeywordsPredicate; +import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; /** * Parses input arguments and creates a new FindCommand object @@ -25,9 +25,15 @@ public FindCommand parse(String args) throws ParseException { String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); } - String[] nameKeywords = trimmedArgs.split("\\s+"); + String[] productNameKeywords = trimmedArgs.split("\\s+"); - return new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); + // Ensures that the user enters the type and at least 1 keyword + if (!productNameKeywords[0].toLowerCase().equals("supplier") || productNameKeywords.length < 2) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + } + + return new FindCommand(new ProductsContainKeywordsPredicate(Arrays.asList(productNameKeywords))); } } diff --git a/src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java b/src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java deleted file mode 100644 index 253fd2696e3..00000000000 --- a/src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java +++ /dev/null @@ -1,31 +0,0 @@ -package seedu.clinic.model.supplier; - -import java.util.List; -import java.util.function.Predicate; - -import seedu.clinic.commons.util.StringUtil; - -/** - * Tests that a {@code Supplier}'s {@code Name} matches any of the keywords given. - */ -public class NameContainsKeywordsPredicate implements Predicate { - private final List keywords; - - public NameContainsKeywordsPredicate(List keywords) { - this.keywords = keywords; - } - - @Override - public boolean test(Supplier supplier) { - return keywords.stream() - .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(supplier.getName().fullName, keyword)); - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof NameContainsKeywordsPredicate // instanceof handles nulls - && keywords.equals(((NameContainsKeywordsPredicate) other).keywords)); // state check - } - -} diff --git a/src/main/java/seedu/clinic/model/supplier/ProductsContainKeywordsPredicate.java b/src/main/java/seedu/clinic/model/supplier/ProductsContainKeywordsPredicate.java new file mode 100644 index 00000000000..0d947c9cc31 --- /dev/null +++ b/src/main/java/seedu/clinic/model/supplier/ProductsContainKeywordsPredicate.java @@ -0,0 +1,42 @@ +package seedu.clinic.model.supplier; + +import java.util.List; +import java.util.function.Predicate; + +import seedu.clinic.commons.util.StringUtil; +import seedu.clinic.model.product.Product; + +/** + * Tests that any of the {@code Product} sold by {@code Supplier} matches any of the keywords given. + */ +public class ProductsContainKeywordsPredicate implements Predicate { + private final List keywords; + + public ProductsContainKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Supplier supplier) { + Product[] products = supplier.getProducts().toArray(Product[]::new); + for (int i = 0; i < products.length; i++) { + String productName = products[i].getProductName().fullName; + boolean match = keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(productName, keyword)); + + if (match) { + return true; + } + } + + return false; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof ProductsContainKeywordsPredicate // instanceof handles nulls + && keywords.equals(((ProductsContainKeywordsPredicate) other).keywords)); // state check + } + +} From d41ecd17175fda45250d0bd2ab7d438d6991c7ca Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Fri, 9 Oct 2020 21:28:10 +0800 Subject: [PATCH 02/14] Modify test cases for finding suppliers --- .../NameContainsKeywordsPredicate.java | 31 +++++++++++++++++++ .../typicalSuppliersClinic.json | 15 +++++++-- .../logic/commands/FindCommandTest.java | 20 ++++++------ .../clinic/logic/parser/ClinicParserTest.java | 6 ++-- .../logic/parser/FindCommandParserTest.java | 7 +++-- .../clinic/testutil/TypicalSupplier.java | 9 ++++-- 6 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java diff --git a/src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java b/src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java new file mode 100644 index 00000000000..57f8314826b --- /dev/null +++ b/src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java @@ -0,0 +1,31 @@ +package seedu.clinic.model.supplier; + +import java.util.List; +import java.util.function.Predicate; + +import seedu.clinic.commons.util.StringUtil; + +/** + * Tests that a {@code Supplier}'s {@code Name} matches any of the keywords given. + */ +public class NameContainsKeywordsPredicate implements Predicate { + private final List keywords; + + public NameContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Supplier supplier) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(supplier.getName().fullName, keyword)); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof NameContainsKeywordsPredicate // instanceof handles nulls + && keywords.equals(((NameContainsKeywordsPredicate) other).keywords)); // state check + } + +} \ No newline at end of file diff --git a/src/test/data/JsonSerializableClinicTest/typicalSuppliersClinic.json b/src/test/data/JsonSerializableClinicTest/typicalSuppliersClinic.json index d6dca6b32a5..46d1b4837f5 100644 --- a/src/test/data/JsonSerializableClinicTest/typicalSuppliersClinic.json +++ b/src/test/data/JsonSerializableClinicTest/typicalSuppliersClinic.json @@ -23,7 +23,10 @@ "phone" : "95352563", "email" : "heinz@example.com", "remark" : "nearby", - "products" : [ ] + "products" : [{ + "name": "Mask", + "tagged": ["black"] + }] }, { "name" : "Daniel Meier Ltd", "phone" : "87652533", @@ -38,13 +41,19 @@ "phone" : "9482224", "email" : "werner@example.com", "remark" : "industry leader", - "products" : [ ] + "products" : [{ + "name": "Mask", + "tagged": ["black"] + }] }, { "name" : "Fiona Kunz Ltd", "phone" : "9482427", "email" : "lydia@example.com", "remark" : "specialises in antibiotics", - "products" : [ ] + "products" : [{ + "name": "Mask", + "tagged": ["black"] + }] }, { "name" : "George Best Ltd", "phone" : "9482442", diff --git a/src/test/java/seedu/clinic/logic/commands/FindCommandTest.java b/src/test/java/seedu/clinic/logic/commands/FindCommandTest.java index b240f7066d3..cfb12ee3fa0 100644 --- a/src/test/java/seedu/clinic/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/clinic/logic/commands/FindCommandTest.java @@ -18,7 +18,7 @@ import seedu.clinic.model.Model; import seedu.clinic.model.ModelManager; import seedu.clinic.model.UserPrefs; -import seedu.clinic.model.supplier.NameContainsKeywordsPredicate; +import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; /** * Contains integration tests (interaction with the Model) for {@code FindCommand}. @@ -29,10 +29,10 @@ public class FindCommandTest { @Test public void equals() { - NameContainsKeywordsPredicate firstPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("first")); - NameContainsKeywordsPredicate secondPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("second")); + ProductsContainKeywordsPredicate firstPredicate = + new ProductsContainKeywordsPredicate(Collections.singletonList("first")); + ProductsContainKeywordsPredicate secondPredicate = + new ProductsContainKeywordsPredicate(Collections.singletonList("second")); FindCommand findFirstCommand = new FindCommand(firstPredicate); FindCommand findSecondCommand = new FindCommand(secondPredicate); @@ -57,7 +57,7 @@ public void equals() { @Test public void execute_zeroKeywords_noSupplierFound() { String expectedMessage = String.format(MESSAGE_SUPPLIERS_LISTED_OVERVIEW, 0); - NameContainsKeywordsPredicate predicate = preparePredicate(" "); + ProductsContainKeywordsPredicate predicate = preparePredicate(" "); FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredSupplierList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -67,7 +67,7 @@ public void execute_zeroKeywords_noSupplierFound() { @Test public void execute_multipleKeywords_multipleSuppliersFound() { String expectedMessage = String.format(MESSAGE_SUPPLIERS_LISTED_OVERVIEW, 3); - NameContainsKeywordsPredicate predicate = preparePredicate("Kurz Elle Kunz"); + ProductsContainKeywordsPredicate predicate = preparePredicate("supplier mask"); FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredSupplierList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -75,9 +75,9 @@ public void execute_multipleKeywords_multipleSuppliersFound() { } /** - * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. + * Parses {@code userInput} into a {@code ProductsContainKeywordsPredicate}. */ - private NameContainsKeywordsPredicate preparePredicate(String userInput) { - return new NameContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); + private ProductsContainKeywordsPredicate preparePredicate(String userInput) { + return new ProductsContainKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); } } diff --git a/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java b/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java index b9c68318195..b7d6d4050ac 100644 --- a/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java @@ -23,7 +23,7 @@ import seedu.clinic.logic.commands.HelpCommand; import seedu.clinic.logic.commands.ListCommand; import seedu.clinic.logic.parser.exceptions.ParseException; -import seedu.clinic.model.supplier.NameContainsKeywordsPredicate; +import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; // import seedu.clinic.model.supplier.Supplier; // import seedu.clinic.testutil.EditSupplierDescriptorBuilder; // import seedu.clinic.testutil.SupplierBuilder; @@ -74,10 +74,10 @@ public void parseCommand_exit() throws Exception { @Test public void parseCommand_find() throws Exception { - List keywords = Arrays.asList("foo", "bar", "baz"); + List keywords = Arrays.asList("supplier", "panadol"); FindCommand command = (FindCommand) parser.parseCommand( FindCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); - assertEquals(new FindCommand(new NameContainsKeywordsPredicate(keywords)), command); + assertEquals(new FindCommand(new ProductsContainKeywordsPredicate(keywords)), command); } @Test diff --git a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java index c87e7902e5c..a978de0ff6c 100644 --- a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java @@ -10,6 +10,7 @@ import seedu.clinic.logic.commands.FindCommand; import seedu.clinic.model.supplier.NameContainsKeywordsPredicate; +import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; public class FindCommandParserTest { @@ -24,11 +25,11 @@ public void parse_emptyArg_throwsParseException() { public void parse_validArgs_returnsFindCommand() { // no leading and trailing whitespaces FindCommand expectedFindCommand = - new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob"))); - assertParseSuccess(parser, "Alice Bob", expectedFindCommand); + new FindCommand(new ProductsContainKeywordsPredicate(Arrays.asList("supplier", "panadol"))); + assertParseSuccess(parser, "supplier panadol", expectedFindCommand); // multiple whitespaces between keywords - assertParseSuccess(parser, " \n Alice \n \t Bob \t", expectedFindCommand); + assertParseSuccess(parser, " \n supplier \n \t panadol \t", expectedFindCommand); } } diff --git a/src/test/java/seedu/clinic/testutil/TypicalSupplier.java b/src/test/java/seedu/clinic/testutil/TypicalSupplier.java index d519c09502e..773007661db 100644 --- a/src/test/java/seedu/clinic/testutil/TypicalSupplier.java +++ b/src/test/java/seedu/clinic/testutil/TypicalSupplier.java @@ -35,14 +35,17 @@ public class TypicalSupplier { .withEmail("johnd@example.com").withPhone("98765432") .withProducts(Map.of("Panadol", new String[]{"fever"})).build(); public static final Supplier CARL = new SupplierBuilder().withName("Carl Kurz Ltd").withPhone("95352563") - .withEmail("heinz@example.com").withRemark("nearby").build(); + .withEmail("heinz@example.com").withRemark("nearby") + .withProducts(Map.of("Mask", new String[]{"black"})).build(); public static final Supplier DANIEL = new SupplierBuilder().withName("Daniel Meier Ltd").withPhone("87652533") .withEmail("cornelia@example.com").withRemark("premium prices") .withProducts(Map.of("Panadol", new String[]{"fever"})).build(); public static final Supplier ELLE = new SupplierBuilder().withName("Elle Meyer Ltd").withPhone("9482224") - .withEmail("werner@example.com").withRemark("industry leader").build(); + .withEmail("werner@example.com").withRemark("industry leader") + .withProducts(Map.of("Mask", new String[]{"black"})).build(); public static final Supplier FIONA = new SupplierBuilder().withName("Fiona Kunz Ltd").withPhone("9482427") - .withEmail("lydia@example.com").withRemark("specialises in antibiotics").build(); + .withEmail("lydia@example.com").withRemark("specialises in antibiotics") + .withProducts(Map.of("Mask", new String[]{"black"})).build(); public static final Supplier GEORGE = new SupplierBuilder().withName("George Best Ltd").withPhone("9482442") .withEmail("anna@example.com").withRemark("frequent discount").build(); From 2cbeb56c3e690c0ff396240819ea6a5a664a5005 Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Fri, 9 Oct 2020 21:34:18 +0800 Subject: [PATCH 03/14] Fix code style issues --- src/main/java/seedu/clinic/MainApp.java | 8 ++++---- src/main/java/seedu/clinic/model/ModelManager.java | 6 +++--- .../model/supplier/NameContainsKeywordsPredicate.java | 2 +- .../seedu/clinic/logic/parser/FindCommandParserTest.java | 1 - 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/seedu/clinic/MainApp.java b/src/main/java/seedu/clinic/MainApp.java index 1eac4bfbb4e..7c88445cf98 100644 --- a/src/main/java/seedu/clinic/MainApp.java +++ b/src/main/java/seedu/clinic/MainApp.java @@ -74,14 +74,14 @@ public void init() throws Exception { * or an empty clinic will be used instead if errors occur when reading {@code storage}'s clinic. */ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { - Optional ClinicOptional; + Optional clinicOptional; ReadOnlyClinic initialData; try { - ClinicOptional = storage.readClinic(); - if (!ClinicOptional.isPresent()) { + clinicOptional = storage.readClinic(); + if (!clinicOptional.isPresent()) { logger.info("Data file not found. Will be starting with a sample Clinic"); } - initialData = ClinicOptional.orElseGet(SampleDataUtil::getSampleClinic); + initialData = clinicOptional.orElseGet(SampleDataUtil::getSampleClinic); } catch (DataConversionException e) { logger.warning("Data file not in the correct format. Will be starting with an empty Clinic"); initialData = new Clinic(); diff --git a/src/main/java/seedu/clinic/model/ModelManager.java b/src/main/java/seedu/clinic/model/ModelManager.java index 14c0cb4f286..abf6b1ffd30 100644 --- a/src/main/java/seedu/clinic/model/ModelManager.java +++ b/src/main/java/seedu/clinic/model/ModelManager.java @@ -71,9 +71,9 @@ public Path getClinicFilePath() { } @Override - public void setClinicFilePath(Path ClinicFilePath) { - requireNonNull(ClinicFilePath); - userPrefs.setClinicFilePath(ClinicFilePath); + public void setClinicFilePath(Path clinicFilePath) { + requireNonNull(clinicFilePath); + userPrefs.setClinicFilePath(clinicFilePath); } //=========== Clinic ================================================================================ diff --git a/src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java b/src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java index 57f8314826b..253fd2696e3 100644 --- a/src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java +++ b/src/main/java/seedu/clinic/model/supplier/NameContainsKeywordsPredicate.java @@ -28,4 +28,4 @@ public boolean equals(Object other) { && keywords.equals(((NameContainsKeywordsPredicate) other).keywords)); // state check } -} \ No newline at end of file +} diff --git a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java index a978de0ff6c..4fc53830d7d 100644 --- a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java @@ -9,7 +9,6 @@ import org.junit.jupiter.api.Test; import seedu.clinic.logic.commands.FindCommand; -import seedu.clinic.model.supplier.NameContainsKeywordsPredicate; import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; public class FindCommandParserTest { From cfefa6dfb9ef6dd288c65d3dbd56227ce6885e48 Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 15:56:38 +0800 Subject: [PATCH 04/14] Rename file --- .../clinic/logic/commands/FindCommand.java | 6 +++--- .../logic/parser/FindCommandParser.java | 4 ++-- ...lierProductsContainKeywordsPredicate.java} | 8 ++++---- .../logic/commands/FindCommandTest.java | 20 +++++++++---------- .../clinic/logic/parser/ClinicParserTest.java | 4 ++-- .../logic/parser/FindCommandParserTest.java | 4 ++-- 6 files changed, 23 insertions(+), 23 deletions(-) rename src/main/java/seedu/clinic/model/supplier/{ProductsContainKeywordsPredicate.java => SupplierProductsContainKeywordsPredicate.java} (72%) diff --git a/src/main/java/seedu/clinic/logic/commands/FindCommand.java b/src/main/java/seedu/clinic/logic/commands/FindCommand.java index e581e319f8e..91f68880564 100644 --- a/src/main/java/seedu/clinic/logic/commands/FindCommand.java +++ b/src/main/java/seedu/clinic/logic/commands/FindCommand.java @@ -4,7 +4,7 @@ import seedu.clinic.commons.core.Messages; import seedu.clinic.model.Model; -import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; +import seedu.clinic.model.supplier.SupplierProductsContainKeywordsPredicate; /** * Finds and lists all suppliers in the CLI-nic app that sell products matching any of the argument keywords. @@ -19,9 +19,9 @@ public class FindCommand extends Command { + "Parameters: TYPE KEYWORD [MORE_KEYWORDS]...\n" + "Example: " + COMMAND_WORD + " supplier panadol"; - private final ProductsContainKeywordsPredicate predicate; + private final SupplierProductsContainKeywordsPredicate predicate; - public FindCommand(ProductsContainKeywordsPredicate predicate) { + public FindCommand(SupplierProductsContainKeywordsPredicate predicate) { this.predicate = predicate; } diff --git a/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java b/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java index ff973eb2863..e2e683826f9 100644 --- a/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java @@ -6,7 +6,7 @@ import seedu.clinic.logic.commands.FindCommand; import seedu.clinic.logic.parser.exceptions.ParseException; -import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; +import seedu.clinic.model.supplier.SupplierProductsContainKeywordsPredicate; /** * Parses input arguments and creates a new FindCommand object @@ -33,7 +33,7 @@ public FindCommand parse(String args) throws ParseException { String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); } - return new FindCommand(new ProductsContainKeywordsPredicate(Arrays.asList(productNameKeywords))); + return new FindCommand(new SupplierProductsContainKeywordsPredicate(Arrays.asList(productNameKeywords))); } } diff --git a/src/main/java/seedu/clinic/model/supplier/ProductsContainKeywordsPredicate.java b/src/main/java/seedu/clinic/model/supplier/SupplierProductsContainKeywordsPredicate.java similarity index 72% rename from src/main/java/seedu/clinic/model/supplier/ProductsContainKeywordsPredicate.java rename to src/main/java/seedu/clinic/model/supplier/SupplierProductsContainKeywordsPredicate.java index 0d947c9cc31..7d2842b38c7 100644 --- a/src/main/java/seedu/clinic/model/supplier/ProductsContainKeywordsPredicate.java +++ b/src/main/java/seedu/clinic/model/supplier/SupplierProductsContainKeywordsPredicate.java @@ -9,10 +9,10 @@ /** * Tests that any of the {@code Product} sold by {@code Supplier} matches any of the keywords given. */ -public class ProductsContainKeywordsPredicate implements Predicate { +public class SupplierProductsContainKeywordsPredicate implements Predicate { private final List keywords; - public ProductsContainKeywordsPredicate(List keywords) { + public SupplierProductsContainKeywordsPredicate(List keywords) { this.keywords = keywords; } @@ -35,8 +35,8 @@ public boolean test(Supplier supplier) { @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof ProductsContainKeywordsPredicate // instanceof handles nulls - && keywords.equals(((ProductsContainKeywordsPredicate) other).keywords)); // state check + || (other instanceof SupplierProductsContainKeywordsPredicate // instanceof handles nulls + && keywords.equals(((SupplierProductsContainKeywordsPredicate) other).keywords)); // state check } } diff --git a/src/test/java/seedu/clinic/logic/commands/FindCommandTest.java b/src/test/java/seedu/clinic/logic/commands/FindCommandTest.java index cfb12ee3fa0..4d550afd95b 100644 --- a/src/test/java/seedu/clinic/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/clinic/logic/commands/FindCommandTest.java @@ -18,7 +18,7 @@ import seedu.clinic.model.Model; import seedu.clinic.model.ModelManager; import seedu.clinic.model.UserPrefs; -import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; +import seedu.clinic.model.supplier.SupplierProductsContainKeywordsPredicate; /** * Contains integration tests (interaction with the Model) for {@code FindCommand}. @@ -29,10 +29,10 @@ public class FindCommandTest { @Test public void equals() { - ProductsContainKeywordsPredicate firstPredicate = - new ProductsContainKeywordsPredicate(Collections.singletonList("first")); - ProductsContainKeywordsPredicate secondPredicate = - new ProductsContainKeywordsPredicate(Collections.singletonList("second")); + SupplierProductsContainKeywordsPredicate firstPredicate = + new SupplierProductsContainKeywordsPredicate(Collections.singletonList("first")); + SupplierProductsContainKeywordsPredicate secondPredicate = + new SupplierProductsContainKeywordsPredicate(Collections.singletonList("second")); FindCommand findFirstCommand = new FindCommand(firstPredicate); FindCommand findSecondCommand = new FindCommand(secondPredicate); @@ -57,7 +57,7 @@ public void equals() { @Test public void execute_zeroKeywords_noSupplierFound() { String expectedMessage = String.format(MESSAGE_SUPPLIERS_LISTED_OVERVIEW, 0); - ProductsContainKeywordsPredicate predicate = preparePredicate(" "); + SupplierProductsContainKeywordsPredicate predicate = preparePredicate(" "); FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredSupplierList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -67,7 +67,7 @@ public void execute_zeroKeywords_noSupplierFound() { @Test public void execute_multipleKeywords_multipleSuppliersFound() { String expectedMessage = String.format(MESSAGE_SUPPLIERS_LISTED_OVERVIEW, 3); - ProductsContainKeywordsPredicate predicate = preparePredicate("supplier mask"); + SupplierProductsContainKeywordsPredicate predicate = preparePredicate("supplier mask"); FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredSupplierList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -75,9 +75,9 @@ public void execute_multipleKeywords_multipleSuppliersFound() { } /** - * Parses {@code userInput} into a {@code ProductsContainKeywordsPredicate}. + * Parses {@code userInput} into a {@code SupplierProductsContainKeywordsPredicate}. */ - private ProductsContainKeywordsPredicate preparePredicate(String userInput) { - return new ProductsContainKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); + private SupplierProductsContainKeywordsPredicate preparePredicate(String userInput) { + return new SupplierProductsContainKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); } } diff --git a/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java b/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java index b7d6d4050ac..7852ef5aa56 100644 --- a/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java @@ -23,7 +23,7 @@ import seedu.clinic.logic.commands.HelpCommand; import seedu.clinic.logic.commands.ListCommand; import seedu.clinic.logic.parser.exceptions.ParseException; -import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; +import seedu.clinic.model.supplier.SupplierProductsContainKeywordsPredicate; // import seedu.clinic.model.supplier.Supplier; // import seedu.clinic.testutil.EditSupplierDescriptorBuilder; // import seedu.clinic.testutil.SupplierBuilder; @@ -77,7 +77,7 @@ public void parseCommand_find() throws Exception { List keywords = Arrays.asList("supplier", "panadol"); FindCommand command = (FindCommand) parser.parseCommand( FindCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); - assertEquals(new FindCommand(new ProductsContainKeywordsPredicate(keywords)), command); + assertEquals(new FindCommand(new SupplierProductsContainKeywordsPredicate(keywords)), command); } @Test diff --git a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java index 4fc53830d7d..f4455eb28c5 100644 --- a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test; import seedu.clinic.logic.commands.FindCommand; -import seedu.clinic.model.supplier.ProductsContainKeywordsPredicate; +import seedu.clinic.model.supplier.SupplierProductsContainKeywordsPredicate; public class FindCommandParserTest { @@ -24,7 +24,7 @@ public void parse_emptyArg_throwsParseException() { public void parse_validArgs_returnsFindCommand() { // no leading and trailing whitespaces FindCommand expectedFindCommand = - new FindCommand(new ProductsContainKeywordsPredicate(Arrays.asList("supplier", "panadol"))); + new FindCommand(new SupplierProductsContainKeywordsPredicate(Arrays.asList("supplier", "panadol"))); assertParseSuccess(parser, "supplier panadol", expectedFindCommand); // multiple whitespaces between keywords From bd9c0cea2da71dea7b167eff99fd0f31c6a9ba18 Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 16:53:10 +0800 Subject: [PATCH 05/14] Add functionality to find warehouses by products stored --- .../clinic/logic/commands/FindCommand.java | 45 ++++++++++++++----- .../logic/parser/FindCommandParser.java | 12 ++++- ...houseProductsContainKeywordsPredicate.java | 42 +++++++++++++++++ 3 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 src/main/java/seedu/clinic/model/warehouse/WarehouseProductsContainKeywordsPredicate.java diff --git a/src/main/java/seedu/clinic/logic/commands/FindCommand.java b/src/main/java/seedu/clinic/logic/commands/FindCommand.java index 91f68880564..5128e811d66 100644 --- a/src/main/java/seedu/clinic/logic/commands/FindCommand.java +++ b/src/main/java/seedu/clinic/logic/commands/FindCommand.java @@ -1,42 +1,65 @@ package seedu.clinic.logic.commands; +import static java.util.Objects.nonNull; import static java.util.Objects.requireNonNull; import seedu.clinic.commons.core.Messages; import seedu.clinic.model.Model; import seedu.clinic.model.supplier.SupplierProductsContainKeywordsPredicate; +import seedu.clinic.model.warehouse.WarehouseProductsContainKeywordsPredicate; /** - * Finds and lists all suppliers in the CLI-nic app that sell products matching any of the argument keywords. + * Finds and lists all suppliers/warehouses in the CLI-nic app that sell/hold products matching any of the argument + * keywords. * Keyword matching is case insensitive. + * Keyword only matches whole word e.g. band will match "band aid" but not "bandaid". */ public class FindCommand extends Command { public static final String COMMAND_WORD = "find"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all suppliers that sell products matching " - + "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all suppliers/warehouses that sell/hold products" + + "matching the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" + "Parameters: TYPE KEYWORD [MORE_KEYWORDS]...\n" - + "Example: " + COMMAND_WORD + " supplier panadol"; + + "Example: " + COMMAND_WORD + " supplier panadol" + + "Example: " + COMMAND_WORD + " warehouse face mask"; - private final SupplierProductsContainKeywordsPredicate predicate; + private final SupplierProductsContainKeywordsPredicate supplierPredicate; + private final WarehouseProductsContainKeywordsPredicate warehousePredicate; - public FindCommand(SupplierProductsContainKeywordsPredicate predicate) { - this.predicate = predicate; + /** + * Constructs a new FindCommand object. + * + * @param supplierPredicate takes in the predicate used to filter a supplier's products. + * @param warehousePredicate takes in the predicate used to filter a warehouse's products. + */ + public FindCommand(SupplierProductsContainKeywordsPredicate supplierPredicate, + WarehouseProductsContainKeywordsPredicate warehousePredicate) { + this.supplierPredicate = supplierPredicate; + this.warehousePredicate = warehousePredicate; } @Override public CommandResult execute(Model model) { requireNonNull(model); - model.updateFilteredSupplierList(predicate); - return new CommandResult( - String.format(Messages.MESSAGE_SUPPLIERS_LISTED_OVERVIEW, model.getFilteredSupplierList().size())); + + if (nonNull(supplierPredicate)) { + model.updateFilteredSupplierList(supplierPredicate); + return new CommandResult( + String.format(Messages.MESSAGE_SUPPLIERS_LISTED_OVERVIEW, model.getFilteredSupplierList().size())); + } else { + model.updateFilteredWarehouseList(warehousePredicate); + return new CommandResult( + String.format(Messages.MESSAGE_WAREHOUSE_LISTED_OVERVIEW, model.getFilteredWarehouseList().size())); + } } @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof FindCommand // instanceof handles nulls - && predicate.equals(((FindCommand) other).predicate)); // state check + && (nonNull(supplierPredicate) + ? supplierPredicate.equals(((FindCommand) other).supplierPredicate) + : warehousePredicate.equals(((FindCommand) other).warehousePredicate))); } } diff --git a/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java b/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java index e2e683826f9..78bde7e5a98 100644 --- a/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java @@ -3,10 +3,12 @@ import static seedu.clinic.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import java.util.Arrays; +import java.util.List; import seedu.clinic.logic.commands.FindCommand; import seedu.clinic.logic.parser.exceptions.ParseException; import seedu.clinic.model.supplier.SupplierProductsContainKeywordsPredicate; +import seedu.clinic.model.warehouse.WarehouseProductsContainKeywordsPredicate; /** * Parses input arguments and creates a new FindCommand object @@ -26,14 +28,20 @@ public FindCommand parse(String args) throws ParseException { } String[] productNameKeywords = trimmedArgs.split("\\s+"); + String type = productNameKeywords[0].toLowerCase(); // Ensures that the user enters the type and at least 1 keyword - if (!productNameKeywords[0].toLowerCase().equals("supplier") || productNameKeywords.length < 2) { + if (!(type.equals("supplier") || type.equals("warehouse")) || productNameKeywords.length < 2) { throw new ParseException( String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); } - return new FindCommand(new SupplierProductsContainKeywordsPredicate(Arrays.asList(productNameKeywords))); + List keywords = Arrays.asList(productNameKeywords); + if (type.equals("supplier")) { + return new FindCommand(new SupplierProductsContainKeywordsPredicate(keywords), null); + } else { + return new FindCommand(null, new WarehouseProductsContainKeywordsPredicate(keywords)); + } } } diff --git a/src/main/java/seedu/clinic/model/warehouse/WarehouseProductsContainKeywordsPredicate.java b/src/main/java/seedu/clinic/model/warehouse/WarehouseProductsContainKeywordsPredicate.java new file mode 100644 index 00000000000..ed69240b4a2 --- /dev/null +++ b/src/main/java/seedu/clinic/model/warehouse/WarehouseProductsContainKeywordsPredicate.java @@ -0,0 +1,42 @@ +package seedu.clinic.model.warehouse; + +import java.util.List; +import java.util.function.Predicate; + +import seedu.clinic.commons.util.StringUtil; +import seedu.clinic.model.product.Product; + +/** + * Tests that any of the {@code Product} stored in a {@code Warehouse} matches any of the keywords given. + */ +public class WarehouseProductsContainKeywordsPredicate implements Predicate { + private final List keywords; + + public WarehouseProductsContainKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Warehouse warehouse) { + Product[] products = warehouse.getProducts().toArray(Product[]::new); + for (int i = 0; i < products.length; i++) { + String productName = products[i].getProductName().fullName; + boolean match = keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(productName, keyword)); + + if (match) { + return true; + } + } + + return false; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof WarehouseProductsContainKeywordsPredicate // instanceof handles nulls + && keywords.equals(((WarehouseProductsContainKeywordsPredicate) other).keywords)); // state check + } + +} From 7ef5405e60ddf631decc5a9a2270cd1d6cb97a23 Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 17:08:31 +0800 Subject: [PATCH 06/14] Fix naming issues in find suppliers test cases --- ...ommandTest.java => FindSuppliersCommandTest.java} | 12 ++++++------ .../seedu/clinic/logic/parser/ClinicParserTest.java | 5 +++-- .../clinic/logic/parser/FindCommandParserTest.java | 11 ++++++----- 3 files changed, 15 insertions(+), 13 deletions(-) rename src/test/java/seedu/clinic/logic/commands/{FindCommandTest.java => FindSuppliersCommandTest.java} (94%) diff --git a/src/test/java/seedu/clinic/logic/commands/FindCommandTest.java b/src/test/java/seedu/clinic/logic/commands/FindSuppliersCommandTest.java similarity index 94% rename from src/test/java/seedu/clinic/logic/commands/FindCommandTest.java rename to src/test/java/seedu/clinic/logic/commands/FindSuppliersCommandTest.java index 4d550afd95b..0c5b7f2b627 100644 --- a/src/test/java/seedu/clinic/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/clinic/logic/commands/FindSuppliersCommandTest.java @@ -23,7 +23,7 @@ /** * Contains integration tests (interaction with the Model) for {@code FindCommand}. */ -public class FindCommandTest { +public class FindSuppliersCommandTest { private Model model = new ModelManager(getTypicalClinic(), new UserPrefs()); private Model expectedModel = new ModelManager(getTypicalClinic(), new UserPrefs()); @@ -34,14 +34,14 @@ public void equals() { SupplierProductsContainKeywordsPredicate secondPredicate = new SupplierProductsContainKeywordsPredicate(Collections.singletonList("second")); - FindCommand findFirstCommand = new FindCommand(firstPredicate); - FindCommand findSecondCommand = new FindCommand(secondPredicate); + FindCommand findFirstCommand = new FindCommand(firstPredicate, null); + FindCommand findSecondCommand = new FindCommand(secondPredicate, null); // same object -> returns true assertTrue(findFirstCommand.equals(findFirstCommand)); // same values -> returns true - FindCommand findFirstCommandCopy = new FindCommand(firstPredicate); + FindCommand findFirstCommandCopy = new FindCommand(firstPredicate, null); assertTrue(findFirstCommand.equals(findFirstCommandCopy)); // different types -> returns false @@ -58,7 +58,7 @@ public void equals() { public void execute_zeroKeywords_noSupplierFound() { String expectedMessage = String.format(MESSAGE_SUPPLIERS_LISTED_OVERVIEW, 0); SupplierProductsContainKeywordsPredicate predicate = preparePredicate(" "); - FindCommand command = new FindCommand(predicate); + FindCommand command = new FindCommand(predicate, null); expectedModel.updateFilteredSupplierList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); assertEquals(Collections.emptyList(), model.getFilteredSupplierList()); @@ -68,7 +68,7 @@ public void execute_zeroKeywords_noSupplierFound() { public void execute_multipleKeywords_multipleSuppliersFound() { String expectedMessage = String.format(MESSAGE_SUPPLIERS_LISTED_OVERVIEW, 3); SupplierProductsContainKeywordsPredicate predicate = preparePredicate("supplier mask"); - FindCommand command = new FindCommand(predicate); + FindCommand command = new FindCommand(predicate, null); expectedModel.updateFilteredSupplierList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredSupplierList()); diff --git a/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java b/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java index 7852ef5aa56..eb087857477 100644 --- a/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java @@ -73,11 +73,12 @@ public void parseCommand_exit() throws Exception { } @Test - public void parseCommand_find() throws Exception { + public void parseCommand_findSuppliers() throws Exception { List keywords = Arrays.asList("supplier", "panadol"); FindCommand command = (FindCommand) parser.parseCommand( FindCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); - assertEquals(new FindCommand(new SupplierProductsContainKeywordsPredicate(keywords)), command); + assertEquals(new FindCommand(new SupplierProductsContainKeywordsPredicate(keywords), null), + command); } @Test diff --git a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java index f4455eb28c5..87e31b7f1a3 100644 --- a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java @@ -21,14 +21,15 @@ public void parse_emptyArg_throwsParseException() { } @Test - public void parse_validArgs_returnsFindCommand() { + public void parse_validArgs_returnsFindSuppliersCommand() { // no leading and trailing whitespaces - FindCommand expectedFindCommand = - new FindCommand(new SupplierProductsContainKeywordsPredicate(Arrays.asList("supplier", "panadol"))); - assertParseSuccess(parser, "supplier panadol", expectedFindCommand); + FindCommand expectedFindSuppliersCommand = + new FindCommand(new SupplierProductsContainKeywordsPredicate(Arrays.asList("supplier", "panadol")), + null); + assertParseSuccess(parser, "supplier panadol", expectedFindSuppliersCommand); // multiple whitespaces between keywords - assertParseSuccess(parser, " \n supplier \n \t panadol \t", expectedFindCommand); + assertParseSuccess(parser, " \n supplier \n \t panadol \t", expectedFindSuppliersCommand); } } From fe3d2b0584c243135f86af3887ca4df797fafad5 Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 17:50:12 +0800 Subject: [PATCH 07/14] Add test cases for finding warehouses --- .../invalidSupplierClinic.json | 2 +- .../invalidWarehouseClinic.json | 2 +- .../duplicateWarehouseClinic.json | 2 +- .../typicalWarehousesClinic.json | 12 ++- .../commands/FindWarehousesCommandTest.java | 83 +++++++++++++++++++ .../logic/parser/FindCommandParserTest.java | 16 ++++ .../warehouse/UniqueWarehouseListTest.java | 10 +-- .../storage/JsonAdaptedWarehouseTest.java | 1 - .../clinic/testutil/TypicalWarehouse.java | 14 ++-- 9 files changed, 124 insertions(+), 18 deletions(-) create mode 100644 src/test/java/seedu/clinic/logic/commands/FindWarehousesCommandTest.java diff --git a/src/test/data/JsonClinicStorageTest/invalidSupplierClinic.json b/src/test/data/JsonClinicStorageTest/invalidSupplierClinic.json index b3c78fb20e5..ce289691eaa 100644 --- a/src/test/data/JsonClinicStorageTest/invalidSupplierClinic.json +++ b/src/test/data/JsonClinicStorageTest/invalidSupplierClinic.json @@ -3,7 +3,7 @@ "name": "Supplier with invalid name field: Ha!ns Mu@ster", "phone": "9482424", "email": "hans@example.com", - "remark": "Trusted company" + "remark": "Trusted seller" } ], "warehouse": [ ] } diff --git a/src/test/data/JsonClinicStorageTest/invalidWarehouseClinic.json b/src/test/data/JsonClinicStorageTest/invalidWarehouseClinic.json index 5cd10d8eb0a..74f3d4ee422 100644 --- a/src/test/data/JsonClinicStorageTest/invalidWarehouseClinic.json +++ b/src/test/data/JsonClinicStorageTest/invalidWarehouseClinic.json @@ -4,6 +4,6 @@ "name": "@ invalid name warehouse", "phone": "9482424", "address": "hans address", - "remark": "Trusted company" + "remark": "Biggest warehouse" } ] } diff --git a/src/test/data/JsonSerializableClinicTest/duplicateWarehouseClinic.json b/src/test/data/JsonSerializableClinicTest/duplicateWarehouseClinic.json index e0f02f86a2e..50a325eefc7 100644 --- a/src/test/data/JsonSerializableClinicTest/duplicateWarehouseClinic.json +++ b/src/test/data/JsonSerializableClinicTest/duplicateWarehouseClinic.json @@ -13,7 +13,7 @@ "name" : "Alice Pauline Ltd", "phone" : "98765432", "address" : "johnd address", - "remark" : "trusted warehouse", + "remark" : "biggest warehouse", "products": [ { "name": "Panadol", "quantity": 20 diff --git a/src/test/data/JsonSerializableClinicTest/typicalWarehousesClinic.json b/src/test/data/JsonSerializableClinicTest/typicalWarehousesClinic.json index a175d5445fe..9286c94595d 100644 --- a/src/test/data/JsonSerializableClinicTest/typicalWarehousesClinic.json +++ b/src/test/data/JsonSerializableClinicTest/typicalWarehousesClinic.json @@ -24,7 +24,10 @@ "phone" : "94361253", "address" : "carl address", "remark" : "Warehouse 3", - "products" : [ ] + "products" : [ { + "name": "Cough Syrup", + "quantity": 20 + } ] }, { "name" : "Warehouse Daniel", "phone" : "94351233", @@ -39,14 +42,17 @@ "phone" : "94651253", "address" : "elle address", "remark" : "Warehouse 5", - "products" : [ ] + "products" : [ { + "name": "Cough Syrup", + "quantity": 30 + } ] }, { "name" : "Warehouse Fiona", "phone" : "92351253", "address" : "fiona address", "remark" : "Warehouse 10", "products" : [ { - "name": "Panadol", + "name": "Flu Syrup", "quantity": 1000 } ] }, { diff --git a/src/test/java/seedu/clinic/logic/commands/FindWarehousesCommandTest.java b/src/test/java/seedu/clinic/logic/commands/FindWarehousesCommandTest.java new file mode 100644 index 00000000000..fa55edb7651 --- /dev/null +++ b/src/test/java/seedu/clinic/logic/commands/FindWarehousesCommandTest.java @@ -0,0 +1,83 @@ +package seedu.clinic.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.clinic.commons.core.Messages.MESSAGE_WAREHOUSE_LISTED_OVERVIEW; +import static seedu.clinic.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.clinic.testutil.TypicalWarehouse.CARL; +import static seedu.clinic.testutil.TypicalWarehouse.ELLE; +import static seedu.clinic.testutil.TypicalWarehouse.FIONA; +import static seedu.clinic.testutil.TypicalWarehouse.getTypicalWarehouseOnlyClinic; + +import java.util.Arrays; +import java.util.Collections; + +import org.junit.jupiter.api.Test; + +import seedu.clinic.model.Model; +import seedu.clinic.model.ModelManager; +import seedu.clinic.model.UserPrefs; +import seedu.clinic.model.warehouse.WarehouseProductsContainKeywordsPredicate; + +/** + * Contains integration tests (interaction with the Model) for {@code FindCommand}. + */ +public class FindWarehousesCommandTest { + private Model model = new ModelManager(getTypicalWarehouseOnlyClinic(), new UserPrefs()); + private Model expectedModel = new ModelManager(getTypicalWarehouseOnlyClinic(), new UserPrefs()); + + @Test + public void equals() { + WarehouseProductsContainKeywordsPredicate firstPredicate = + new WarehouseProductsContainKeywordsPredicate(Collections.singletonList("first")); + WarehouseProductsContainKeywordsPredicate secondPredicate = + new WarehouseProductsContainKeywordsPredicate(Collections.singletonList("second")); + + FindCommand findFirstCommand = new FindCommand(null, firstPredicate); + FindCommand findSecondCommand = new FindCommand(null, secondPredicate); + + // same object -> returns true + assertTrue(findFirstCommand.equals(findFirstCommand)); + + // same values -> returns true + FindCommand findFirstCommandCopy = new FindCommand(null, firstPredicate); + assertTrue(findFirstCommand.equals(findFirstCommandCopy)); + + // different types -> returns false + assertFalse(findFirstCommand.equals(1)); + + // null -> returns false + assertFalse(findFirstCommand.equals(null)); + + // different warehouse -> returns false + assertFalse(findFirstCommand.equals(findSecondCommand)); + } + + @Test + public void execute_zeroKeywords_noWarehouseFound() { + String expectedMessage = String.format(MESSAGE_WAREHOUSE_LISTED_OVERVIEW, 0); + WarehouseProductsContainKeywordsPredicate warehousePredicate = preparePredicate(" "); + FindCommand command = new FindCommand(null, warehousePredicate); + expectedModel.updateFilteredWarehouseList(warehousePredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Collections.emptyList(), model.getFilteredWarehouseList()); + } + + @Test + public void execute_multipleKeywords_multipleSuppliersFound() { + String expectedMessage = String.format(MESSAGE_WAREHOUSE_LISTED_OVERVIEW, 3); + WarehouseProductsContainKeywordsPredicate warehousePredicate = preparePredicate("warehouse syrup"); + FindCommand command = new FindCommand(null, warehousePredicate); + expectedModel.updateFilteredWarehouseList(warehousePredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredWarehouseList()); + } + + /** + * Parses {@code userInput} into a {@code WarehouseProductsContainKeywordsPredicate}. + */ + private WarehouseProductsContainKeywordsPredicate preparePredicate(String userInput) { + return new WarehouseProductsContainKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); + } +} diff --git a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java index 87e31b7f1a3..d621fc7e465 100644 --- a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java @@ -10,7 +10,11 @@ import seedu.clinic.logic.commands.FindCommand; import seedu.clinic.model.supplier.SupplierProductsContainKeywordsPredicate; +import seedu.clinic.model.warehouse.WarehouseProductsContainKeywordsPredicate; +/** + * Tests if {@code FindCommand} parses the arguments correctly for {@code Supplier} and {@code Warehouse}. + */ public class FindCommandParserTest { private FindCommandParser parser = new FindCommandParser(); @@ -32,4 +36,16 @@ public void parse_validArgs_returnsFindSuppliersCommand() { assertParseSuccess(parser, " \n supplier \n \t panadol \t", expectedFindSuppliersCommand); } + @Test + public void parse_validArgs_returnsFindWarehousesCommand() { + // no leading and trailing whitespaces + FindCommand expectedFindWarehousesCommand = + new FindCommand(null, + new WarehouseProductsContainKeywordsPredicate(Arrays.asList("warehouse", "panadol"))); + assertParseSuccess(parser, "warehouse panadol", expectedFindWarehousesCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n warehouse \n \t panadol \t", expectedFindWarehousesCommand); + } + } diff --git a/src/test/java/seedu/clinic/model/warehouse/UniqueWarehouseListTest.java b/src/test/java/seedu/clinic/model/warehouse/UniqueWarehouseListTest.java index 2ff9c17dad3..da28825fc1e 100644 --- a/src/test/java/seedu/clinic/model/warehouse/UniqueWarehouseListTest.java +++ b/src/test/java/seedu/clinic/model/warehouse/UniqueWarehouseListTest.java @@ -72,12 +72,12 @@ public void setWarehouse_nullEditedWarehouse_throwsNullPointerException() { } @Test - public void setWarehouse_targetSupplierNotInList_throwsWarehouseNotFoundException() { + public void setWarehouse_targetWarehouseNotInList_throwsWarehouseNotFoundException() { assertThrows(WarehouseNotFoundException.class, () -> uniqueWarehouseList.setWarehouse(A, A)); } @Test - public void setWarehouse_editedWarehouseIsSameSupplier_success() { + public void setWarehouse_editedWarehouseIsSameWarehouse_success() { uniqueWarehouseList.add(A); uniqueWarehouseList.setWarehouse(A, A); UniqueWarehouseList expectedUniqueWarehouseList = new UniqueWarehouseList(); @@ -98,7 +98,7 @@ public void setWarehouse_editedWarehouseHasSameIdentity_success() { } @Test - public void setSupplier_editedSupplierHasDifferentIdentity_success() { + public void setWarehouse_editedWarehouseHasDifferentIdentity_success() { uniqueWarehouseList.add(A); uniqueWarehouseList.setWarehouse(A, B); UniqueWarehouseList expectedUniqueWarehouseList = new UniqueWarehouseList(); @@ -124,7 +124,7 @@ public void remove_warehouseDoesNotExist_throwsWarehouseNotFoundException() { } @Test - public void remove_existingWarehouse_removesSupplier() { + public void remove_existingWarehouse_removesWarehouse() { uniqueWarehouseList.add(A); uniqueWarehouseList.remove(A); UniqueWarehouseList expectedUniqueWarehouseList = new UniqueWarehouseList(); @@ -151,7 +151,7 @@ public void setWarehouses_nullList_throwsNullPointerException() { } @Test - public void setSuppliers_list_replacesOwnListWithProvidedList() { + public void setWarehouses_list_replacesOwnListWithProvidedList() { uniqueWarehouseList.add(A); List supplierList = Collections.singletonList(B); uniqueWarehouseList.setWarehouses(supplierList); diff --git a/src/test/java/seedu/clinic/storage/JsonAdaptedWarehouseTest.java b/src/test/java/seedu/clinic/storage/JsonAdaptedWarehouseTest.java index 8cca5135806..7ec9bdabbd2 100644 --- a/src/test/java/seedu/clinic/storage/JsonAdaptedWarehouseTest.java +++ b/src/test/java/seedu/clinic/storage/JsonAdaptedWarehouseTest.java @@ -22,7 +22,6 @@ public class JsonAdaptedWarehouseTest { private static final String INVALID_PHONE = "+651234"; private static final String INVALID_REMARK = " "; private static final String INVALID_ADDRESS = " example.com"; - private static final String INVALID_TAG = "#friend"; private static final String VALID_NAME = BENSON.getName().toString(); private static final String VALID_PHONE = BENSON.getPhone().toString(); diff --git a/src/test/java/seedu/clinic/testutil/TypicalWarehouse.java b/src/test/java/seedu/clinic/testutil/TypicalWarehouse.java index 20ac3325410..3006532f408 100644 --- a/src/test/java/seedu/clinic/testutil/TypicalWarehouse.java +++ b/src/test/java/seedu/clinic/testutil/TypicalWarehouse.java @@ -22,7 +22,7 @@ import seedu.clinic.model.warehouse.Warehouse; /** - * A utility class containing a list of {@code Supplier} objects to be used in tests. + * A utility class containing a list of {@code Warehouse} objects to be used in tests. */ public class TypicalWarehouse { @@ -36,18 +36,20 @@ public class TypicalWarehouse { .withProducts(Map.of("Panadol", 200)).build(); public static final Warehouse CARL = new WarehouseBuilder().withName("Warehouse Carl") .withRemark("Warehouse 3").withAddress("carl address") - .withPhone("94361253").build(); + .withPhone("94361253") + .withProducts(Map.of("Cough Syrup", 20)).build(); public static final Warehouse DANIEL = new WarehouseBuilder().withName("Warehouse Daniel") .withRemark("Warehouse 4").withAddress("daniel address") .withPhone("94351233") .withProducts(Map.of("Panadol", 1)).build(); public static final Warehouse ELLE = new WarehouseBuilder().withName("Warehouse Elle") .withRemark("Warehouse 5").withAddress("elle address") - .withPhone("94651253").build(); + .withPhone("94651253") + .withProducts(Map.of("Cough Syrup", 30)).build(); public static final Warehouse FIONA = new WarehouseBuilder().withName("Warehouse Fiona") .withRemark("Warehouse 10").withAddress("fiona address") .withPhone("92351253") - .withProducts(Map.of("Panadol", 1000)).build(); + .withProducts(Map.of("Flu Syrup", 1000)).build(); public static final Warehouse GEORGE = new WarehouseBuilder().withName("Warehouse George") .withRemark("Warehouse to be removed").withAddress("george address") .withPhone("84351253") @@ -59,7 +61,7 @@ public class TypicalWarehouse { public static final Warehouse IRVIN = new WarehouseBuilder().withName("Irvin's Warehouse").withPhone("8482131") .withAddress("hans@35 prince george.").withRemark("big warehouse").build(); - // Manually added - Supplier's details found in {@code CommandTestUtil} + // Manually added - Warehouse's details found in {@code CommandTestUtil} public static final Warehouse A = new WarehouseBuilder().withName(VALID_WAREHOUSE_NAME_A) .withPhone(VALID_WAREHOUSE_PHONE_A) .withAddress(VALID_WAREHOUSE_ADDRESS_A) @@ -78,7 +80,7 @@ public class TypicalWarehouse { private TypicalWarehouse() {} // prevents instantiation /** - * Returns an {@code Clinic} with all the typical suppliers. + * Returns an {@code Clinic} with all the typical warehouses. */ public static Clinic getTypicalWarehouseOnlyClinic() { Clinic ab = new Clinic(); From 8137a066ad7aeae2e1f4ad4025380010feb81665 Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 20:19:15 +0800 Subject: [PATCH 08/14] Clean up code --- src/main/java/seedu/clinic/model/attribute/Name.java | 3 +-- .../clinic/logic/parser/AddCommandParserTest.java | 10 ---------- .../clinic/logic/parser/EditCommandParserTest.java | 12 ------------ .../clinic/storage/JsonSerializableClinicTest.java | 2 +- .../java/seedu/clinic/testutil/WarehouseBuilder.java | 2 -- 5 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/main/java/seedu/clinic/model/attribute/Name.java b/src/main/java/seedu/clinic/model/attribute/Name.java index 819a9c6ed3f..de61a949f04 100644 --- a/src/main/java/seedu/clinic/model/attribute/Name.java +++ b/src/main/java/seedu/clinic/model/attribute/Name.java @@ -12,9 +12,8 @@ public class Name { public static final String MESSAGE_CONSTRAINTS = "Names should only contain alphanumeric characters and spaces, and it should not be blank"; - /* + /** * The first character of the name must be alphanumeric. - * The . */ public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Print}]*"; diff --git a/src/test/java/seedu/clinic/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/clinic/logic/parser/AddCommandParserTest.java index b8328b723d7..24b484e12e8 100644 --- a/src/test/java/seedu/clinic/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/AddCommandParserTest.java @@ -28,15 +28,6 @@ import org.junit.jupiter.api.Test; -<<<<<<< HEAD:src/test/java/seedu/address/logic/parser/AddCommandParserTest.java -import seedu.address.logic.commands.AddCommand; -import seedu.address.model.attribute.Email; -import seedu.address.model.attribute.Name; -import seedu.address.model.attribute.Phone; -import seedu.address.model.attribute.Remark; -import seedu.address.model.supplier.Supplier; -import seedu.address.testutil.SupplierBuilder; -======= import seedu.clinic.logic.commands.AddCommand; import seedu.clinic.model.supplier.Email; import seedu.clinic.model.supplier.Name; @@ -44,7 +35,6 @@ import seedu.clinic.model.supplier.Remark; import seedu.clinic.model.supplier.Supplier; import seedu.clinic.testutil.SupplierBuilder; ->>>>>>> upstream/master:src/test/java/seedu/clinic/logic/parser/AddCommandParserTest.java */ public class AddCommandParserTest { /* diff --git a/src/test/java/seedu/clinic/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/clinic/logic/parser/EditCommandParserTest.java index d7296b495eb..bd9bd289903 100644 --- a/src/test/java/seedu/clinic/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/EditCommandParserTest.java @@ -33,17 +33,6 @@ import org.junit.jupiter.api.Test; -<<<<<<< HEAD:src/test/java/seedu/address/logic/parser/EditCommandParserTest.java -import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.EditCommand.EditSupplierDescriptor; -import seedu.address.model.attribute.Address; -import seedu.address.model.attribute.Email; -import seedu.address.model.attribute.Name; -import seedu.address.model.attribute.Phone; -import seedu.address.model.attribute.Tag; -import seedu.address.testutil.EditSupplierDescriptorBuilder; -======= import seedu.clinic.commons.core.index.Index; import seedu.clinic.logic.commands.EditCommand; import seedu.clinic.logic.commands.EditCommand.EditSupplierDescriptor; @@ -53,7 +42,6 @@ import seedu.clinic.model.supplier.Phone; import seedu.clinic.model.tag.Tag; import seedu.clinic.testutil.EditSupplierDescriptorBuilder; ->>>>>>> upstream/master:src/test/java/seedu/clinic/logic/parser/EditCommandParserTest.java */ public class EditCommandParserTest { /* diff --git a/src/test/java/seedu/clinic/storage/JsonSerializableClinicTest.java b/src/test/java/seedu/clinic/storage/JsonSerializableClinicTest.java index 9276c9378f6..e28834d7f25 100644 --- a/src/test/java/seedu/clinic/storage/JsonSerializableClinicTest.java +++ b/src/test/java/seedu/clinic/storage/JsonSerializableClinicTest.java @@ -65,7 +65,7 @@ public void toModelType_invalidWarehouseFile_throwsIllegalValueException() throw } @Test - public void toModelType_duplicateSWarehouses_throwsIllegalValueException() throws Exception { + public void toModelType_duplicateWarehouses_throwsIllegalValueException() throws Exception { JsonSerializableClinic dataFromFile = JsonUtil.readJsonFile(DUPLICATE_WAREHOUSE_FILE, JsonSerializableClinic.class).get(); assertThrows(IllegalValueException.class, JsonSerializableClinic.MESSAGE_DUPLICATE_WAREHOUSE, diff --git a/src/test/java/seedu/clinic/testutil/WarehouseBuilder.java b/src/test/java/seedu/clinic/testutil/WarehouseBuilder.java index b734c7c1928..4376da99159 100644 --- a/src/test/java/seedu/clinic/testutil/WarehouseBuilder.java +++ b/src/test/java/seedu/clinic/testutil/WarehouseBuilder.java @@ -12,8 +12,6 @@ import seedu.clinic.model.util.SampleDataUtil; import seedu.clinic.model.warehouse.Warehouse; -//INVALID_WAREHOUSE_ADDRESS_DESC - /** * A utility class to help with building Warehouse objects. */ From 053e5f16ed3d31aee0d30697fdf948a96e9345ee Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 20:21:14 +0800 Subject: [PATCH 09/14] Remove extra character from UG --- docs/UserGuide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 304a3739067..8a71fce2a38 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -13,7 +13,7 @@ and efficient Graphical User Interface interaction. -------------------------------------------------------------------------------------------------------------------- -## Quick startf +## Quick start 1. Ensure you have Java `11` or above installed in your Computer. From 6d5362078a768437b41de6a1eec3993945e4d76f Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 20:55:35 +0800 Subject: [PATCH 10/14] Remove ability to pass in null as param --- .../clinic/logic/commands/FindCommand.java | 33 ++++++++++++------- .../logic/parser/FindCommandParser.java | 4 +-- .../commands/FindSuppliersCommandTest.java | 10 +++--- .../commands/FindWarehousesCommandTest.java | 10 +++--- .../clinic/logic/parser/ClinicParserTest.java | 3 +- .../logic/parser/FindCommandParserTest.java | 6 ++-- 6 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/main/java/seedu/clinic/logic/commands/FindCommand.java b/src/main/java/seedu/clinic/logic/commands/FindCommand.java index 5128e811d66..b3a51fc57ef 100644 --- a/src/main/java/seedu/clinic/logic/commands/FindCommand.java +++ b/src/main/java/seedu/clinic/logic/commands/FindCommand.java @@ -1,8 +1,9 @@ package seedu.clinic.logic.commands; -import static java.util.Objects.nonNull; import static java.util.Objects.requireNonNull; +import java.util.Optional; + import seedu.clinic.commons.core.Messages; import seedu.clinic.model.Model; import seedu.clinic.model.supplier.SupplierProductsContainKeywordsPredicate; @@ -20,35 +21,43 @@ public class FindCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all suppliers/warehouses that sell/hold products" + "matching the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" - + "Parameters: TYPE KEYWORD [MORE_KEYWORDS]...\n" + + "Parameters: TYPE KEYWORD [MORE_KEYWORDS...]\n" + "Example: " + COMMAND_WORD + " supplier panadol" + "Example: " + COMMAND_WORD + " warehouse face mask"; - private final SupplierProductsContainKeywordsPredicate supplierPredicate; - private final WarehouseProductsContainKeywordsPredicate warehousePredicate; + private final Optional supplierPredicate; + private final Optional warehousePredicate; /** * Constructs a new FindCommand object. * * @param supplierPredicate takes in the predicate used to filter a supplier's products. + */ + public FindCommand(SupplierProductsContainKeywordsPredicate supplierPredicate) { + this.supplierPredicate = Optional.of(supplierPredicate); + this.warehousePredicate = Optional.empty(); + } + + /** + * Constructs a new FindCommand object. + * * @param warehousePredicate takes in the predicate used to filter a warehouse's products. */ - public FindCommand(SupplierProductsContainKeywordsPredicate supplierPredicate, - WarehouseProductsContainKeywordsPredicate warehousePredicate) { - this.supplierPredicate = supplierPredicate; - this.warehousePredicate = warehousePredicate; + public FindCommand(WarehouseProductsContainKeywordsPredicate warehousePredicate) { + this.warehousePredicate = Optional.of(warehousePredicate); + this.supplierPredicate = Optional.empty(); } @Override public CommandResult execute(Model model) { requireNonNull(model); - if (nonNull(supplierPredicate)) { - model.updateFilteredSupplierList(supplierPredicate); + if (supplierPredicate.isPresent()) { + model.updateFilteredSupplierList(supplierPredicate.get()); return new CommandResult( String.format(Messages.MESSAGE_SUPPLIERS_LISTED_OVERVIEW, model.getFilteredSupplierList().size())); } else { - model.updateFilteredWarehouseList(warehousePredicate); + model.updateFilteredWarehouseList(warehousePredicate.get()); return new CommandResult( String.format(Messages.MESSAGE_WAREHOUSE_LISTED_OVERVIEW, model.getFilteredWarehouseList().size())); } @@ -58,7 +67,7 @@ public CommandResult execute(Model model) { public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof FindCommand // instanceof handles nulls - && (nonNull(supplierPredicate) + && (supplierPredicate.isPresent() ? supplierPredicate.equals(((FindCommand) other).supplierPredicate) : warehousePredicate.equals(((FindCommand) other).warehousePredicate))); } diff --git a/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java b/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java index 78bde7e5a98..413e5ea35ae 100644 --- a/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/clinic/logic/parser/FindCommandParser.java @@ -38,9 +38,9 @@ public FindCommand parse(String args) throws ParseException { List keywords = Arrays.asList(productNameKeywords); if (type.equals("supplier")) { - return new FindCommand(new SupplierProductsContainKeywordsPredicate(keywords), null); + return new FindCommand(new SupplierProductsContainKeywordsPredicate(keywords)); } else { - return new FindCommand(null, new WarehouseProductsContainKeywordsPredicate(keywords)); + return new FindCommand(new WarehouseProductsContainKeywordsPredicate(keywords)); } } diff --git a/src/test/java/seedu/clinic/logic/commands/FindSuppliersCommandTest.java b/src/test/java/seedu/clinic/logic/commands/FindSuppliersCommandTest.java index 0c5b7f2b627..4d97b1861d8 100644 --- a/src/test/java/seedu/clinic/logic/commands/FindSuppliersCommandTest.java +++ b/src/test/java/seedu/clinic/logic/commands/FindSuppliersCommandTest.java @@ -34,14 +34,14 @@ public void equals() { SupplierProductsContainKeywordsPredicate secondPredicate = new SupplierProductsContainKeywordsPredicate(Collections.singletonList("second")); - FindCommand findFirstCommand = new FindCommand(firstPredicate, null); - FindCommand findSecondCommand = new FindCommand(secondPredicate, null); + FindCommand findFirstCommand = new FindCommand(firstPredicate); + FindCommand findSecondCommand = new FindCommand(secondPredicate); // same object -> returns true assertTrue(findFirstCommand.equals(findFirstCommand)); // same values -> returns true - FindCommand findFirstCommandCopy = new FindCommand(firstPredicate, null); + FindCommand findFirstCommandCopy = new FindCommand(firstPredicate); assertTrue(findFirstCommand.equals(findFirstCommandCopy)); // different types -> returns false @@ -58,7 +58,7 @@ public void equals() { public void execute_zeroKeywords_noSupplierFound() { String expectedMessage = String.format(MESSAGE_SUPPLIERS_LISTED_OVERVIEW, 0); SupplierProductsContainKeywordsPredicate predicate = preparePredicate(" "); - FindCommand command = new FindCommand(predicate, null); + FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredSupplierList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); assertEquals(Collections.emptyList(), model.getFilteredSupplierList()); @@ -68,7 +68,7 @@ public void execute_zeroKeywords_noSupplierFound() { public void execute_multipleKeywords_multipleSuppliersFound() { String expectedMessage = String.format(MESSAGE_SUPPLIERS_LISTED_OVERVIEW, 3); SupplierProductsContainKeywordsPredicate predicate = preparePredicate("supplier mask"); - FindCommand command = new FindCommand(predicate, null); + FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredSupplierList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredSupplierList()); diff --git a/src/test/java/seedu/clinic/logic/commands/FindWarehousesCommandTest.java b/src/test/java/seedu/clinic/logic/commands/FindWarehousesCommandTest.java index fa55edb7651..43cc30f3c64 100644 --- a/src/test/java/seedu/clinic/logic/commands/FindWarehousesCommandTest.java +++ b/src/test/java/seedu/clinic/logic/commands/FindWarehousesCommandTest.java @@ -34,14 +34,14 @@ public void equals() { WarehouseProductsContainKeywordsPredicate secondPredicate = new WarehouseProductsContainKeywordsPredicate(Collections.singletonList("second")); - FindCommand findFirstCommand = new FindCommand(null, firstPredicate); - FindCommand findSecondCommand = new FindCommand(null, secondPredicate); + FindCommand findFirstCommand = new FindCommand(firstPredicate); + FindCommand findSecondCommand = new FindCommand(secondPredicate); // same object -> returns true assertTrue(findFirstCommand.equals(findFirstCommand)); // same values -> returns true - FindCommand findFirstCommandCopy = new FindCommand(null, firstPredicate); + FindCommand findFirstCommandCopy = new FindCommand(firstPredicate); assertTrue(findFirstCommand.equals(findFirstCommandCopy)); // different types -> returns false @@ -58,7 +58,7 @@ public void equals() { public void execute_zeroKeywords_noWarehouseFound() { String expectedMessage = String.format(MESSAGE_WAREHOUSE_LISTED_OVERVIEW, 0); WarehouseProductsContainKeywordsPredicate warehousePredicate = preparePredicate(" "); - FindCommand command = new FindCommand(null, warehousePredicate); + FindCommand command = new FindCommand(warehousePredicate); expectedModel.updateFilteredWarehouseList(warehousePredicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); assertEquals(Collections.emptyList(), model.getFilteredWarehouseList()); @@ -68,7 +68,7 @@ public void execute_zeroKeywords_noWarehouseFound() { public void execute_multipleKeywords_multipleSuppliersFound() { String expectedMessage = String.format(MESSAGE_WAREHOUSE_LISTED_OVERVIEW, 3); WarehouseProductsContainKeywordsPredicate warehousePredicate = preparePredicate("warehouse syrup"); - FindCommand command = new FindCommand(null, warehousePredicate); + FindCommand command = new FindCommand(warehousePredicate); expectedModel.updateFilteredWarehouseList(warehousePredicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredWarehouseList()); diff --git a/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java b/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java index eb087857477..13a80794b18 100644 --- a/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/ClinicParserTest.java @@ -77,8 +77,7 @@ public void parseCommand_findSuppliers() throws Exception { List keywords = Arrays.asList("supplier", "panadol"); FindCommand command = (FindCommand) parser.parseCommand( FindCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); - assertEquals(new FindCommand(new SupplierProductsContainKeywordsPredicate(keywords), null), - command); + assertEquals(new FindCommand(new SupplierProductsContainKeywordsPredicate(keywords)), command); } @Test diff --git a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java index d621fc7e465..86fc7817c12 100644 --- a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java @@ -28,8 +28,7 @@ public void parse_emptyArg_throwsParseException() { public void parse_validArgs_returnsFindSuppliersCommand() { // no leading and trailing whitespaces FindCommand expectedFindSuppliersCommand = - new FindCommand(new SupplierProductsContainKeywordsPredicate(Arrays.asList("supplier", "panadol")), - null); + new FindCommand(new SupplierProductsContainKeywordsPredicate(Arrays.asList("supplier", "panadol"))); assertParseSuccess(parser, "supplier panadol", expectedFindSuppliersCommand); // multiple whitespaces between keywords @@ -40,8 +39,7 @@ public void parse_validArgs_returnsFindSuppliersCommand() { public void parse_validArgs_returnsFindWarehousesCommand() { // no leading and trailing whitespaces FindCommand expectedFindWarehousesCommand = - new FindCommand(null, - new WarehouseProductsContainKeywordsPredicate(Arrays.asList("warehouse", "panadol"))); + new FindCommand(new WarehouseProductsContainKeywordsPredicate(Arrays.asList("warehouse", "panadol"))); assertParseSuccess(parser, "warehouse panadol", expectedFindWarehousesCommand); // multiple whitespaces between keywords From df93fee2324920fdb52f3c5291ee166e7705ed6c Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 21:47:18 +0800 Subject: [PATCH 11/14] Update logic to add more products to test-supplier --- .../seedu/clinic/model/util/SampleDataUtil.java | 15 +++++++-------- .../typicalSuppliersClinic.json | 12 ++++++++++++ .../seedu/clinic/testutil/SupplierBuilder.java | 2 +- .../seedu/clinic/testutil/TypicalSupplier.java | 10 +++++++--- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/seedu/clinic/model/util/SampleDataUtil.java b/src/main/java/seedu/clinic/model/util/SampleDataUtil.java index 6fdd5842b42..57abf4064c3 100644 --- a/src/main/java/seedu/clinic/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/clinic/model/util/SampleDataUtil.java @@ -26,22 +26,22 @@ public static Supplier[] getSampleSuppliers() { return new Supplier[] { new Supplier(new Name("Alex Yeoh Ltd"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Remark("long term partner"), - getProductSet(Map.of("Panadol", new String[]{"fever"}))), + getProductSet(new HashSet(), Map.of("Panadol", new String[]{"fever"}))), new Supplier(new Name("Bernice Yu Pte Ltd"), new Phone("99272758"), new Email("berniceyu@example.com"), new Remark("long term partner"), - getProductSet(Map.of("Panadol", new String[]{"fever"}))), + getProductSet(new HashSet(), Map.of("Panadol", new String[]{"fever"}))), new Supplier(new Name("Charlotte Oliveiro Ltd"), new Phone("93210283"), new Email("charlotte@example.com"), new Remark("long term partner"), - getProductSet(Map.of("Panadol", new String[]{"fever"}))), + getProductSet(new HashSet(), Map.of("Panadol", new String[]{"fever"}))), new Supplier(new Name("David Li Pte Ltd"), new Phone("91031282"), new Email("lidavid@example.com"), new Remark("long term partner"), - getProductSet(Map.of("Panadol", new String[]{"fever"}))), + getProductSet(new HashSet(), Map.of("Panadol", new String[]{"fever"}))), new Supplier(new Name("Irfan Ibrahim Pte Ltd"), new Phone("92492021"), new Email("irfan@example.com"), new Remark("long term partner"), - getProductSet(Map.of("Panadol", new String[]{"fever"}))), + getProductSet(new HashSet(), Map.of("Panadol", new String[]{"fever"}))), new Supplier(new Name("Roy Balakrishnan Pte Ltd"), new Phone("92624417"), new Email("royb@example.com"), new Remark("long term partner"), - getProductSet(Map.of("Panadol", new String[]{"fever"}))), + getProductSet(new HashSet(), Map.of("Panadol", new String[]{"fever"}))), }; } @@ -93,8 +93,7 @@ public static Set getTagSet(String... strings) { /** * Returns a product set containing the hashmap of strings given. */ - public static Set getProductSet(Map productMap) { - Set productSet = new HashSet<>(); + public static Set getProductSet(Set productSet, Map productMap) { for (String productName:productMap.keySet()) { Set productTags = getTagSet(productMap.get(productName)); Product product = new Product(new Name(productName), productTags); diff --git a/src/test/data/JsonSerializableClinicTest/typicalSuppliersClinic.json b/src/test/data/JsonSerializableClinicTest/typicalSuppliersClinic.json index 21198fc0a50..5435d56cc43 100644 --- a/src/test/data/JsonSerializableClinicTest/typicalSuppliersClinic.json +++ b/src/test/data/JsonSerializableClinicTest/typicalSuppliersClinic.json @@ -26,6 +26,9 @@ "products" : [{ "name": "Mask", "tagged": ["black"] + }, { + "name": "Thermometer", + "tagged": ["digital"] }] }, { "name" : "Daniel Meier Ltd", @@ -44,6 +47,9 @@ "products" : [{ "name": "Mask", "tagged": ["black"] + }, { + "name": "Medical Glove", + "tagged": ["rubber"] }] }, { "name" : "Fiona Kunz Ltd", @@ -53,6 +59,12 @@ "products" : [{ "name": "Mask", "tagged": ["black"] + }, { + "name": "Needle", + "tagged": ["1mm"] + }, { + "name": "Cough Syrup", + "tagged": ["cough"] }] }, { "name" : "George Best Ltd", diff --git a/src/test/java/seedu/clinic/testutil/SupplierBuilder.java b/src/test/java/seedu/clinic/testutil/SupplierBuilder.java index 53e801a8b2c..d470e4950b1 100644 --- a/src/test/java/seedu/clinic/testutil/SupplierBuilder.java +++ b/src/test/java/seedu/clinic/testutil/SupplierBuilder.java @@ -63,7 +63,7 @@ public SupplierBuilder withName(String name) { * building. */ public SupplierBuilder withProducts(Map productMap) { - this.products = SampleDataUtil.getProductSet(productMap); + this.products = SampleDataUtil.getProductSet(products, productMap); return this; } diff --git a/src/test/java/seedu/clinic/testutil/TypicalSupplier.java b/src/test/java/seedu/clinic/testutil/TypicalSupplier.java index 760866500a2..30493c63163 100644 --- a/src/test/java/seedu/clinic/testutil/TypicalSupplier.java +++ b/src/test/java/seedu/clinic/testutil/TypicalSupplier.java @@ -36,16 +36,20 @@ public class TypicalSupplier { .withProducts(Map.of("Panadol", new String[]{"fever"})).build(); public static final Supplier CARL = new SupplierBuilder().withName("Carl Kurz Ltd").withPhone("95352563") .withEmail("heinz@example.com").withRemark("nearby") - .withProducts(Map.of("Mask", new String[]{"black"})).build(); + .withProducts(Map.of("Mask", new String[]{"black"})) + .withProducts(Map.of("Thermometer", new String[]{"digital"})).build(); public static final Supplier DANIEL = new SupplierBuilder().withName("Daniel Meier Ltd").withPhone("87652533") .withEmail("cornelia@example.com").withRemark("premium prices") .withProducts(Map.of("Panadol", new String[]{"fever"})).build(); public static final Supplier ELLE = new SupplierBuilder().withName("Elle Meyer Ltd").withPhone("9482224") .withEmail("werner@example.com").withRemark("industry leader") - .withProducts(Map.of("Mask", new String[]{"black"})).build(); + .withProducts(Map.of("Mask", new String[]{"black"})) + .withProducts(Map.of("Medical Glove", new String[]{"rubber"})).build(); public static final Supplier FIONA = new SupplierBuilder().withName("Fiona Kunz Ltd").withPhone("9482427") .withEmail("lydia@example.com").withRemark("specialises in antibiotics") - .withProducts(Map.of("Mask", new String[]{"black"})).build(); + .withProducts(Map.of("Mask", new String[]{"black"})) + .withProducts(Map.of("Needle", new String[]{"1mm"})) + .withProducts(Map.of("Cough Syrup", new String[]{"cough"})).build(); public static final Supplier GEORGE = new SupplierBuilder().withName("George Best Ltd").withPhone("9482442") .withEmail("anna@example.com").withRemark("frequent discount").build(); From ea2182ab1936c8e20f639e1f8b8db0738f303f8f Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 21:55:45 +0800 Subject: [PATCH 12/14] Update logic to add more products to test-warehouse data --- .../seedu/clinic/model/util/SampleDataUtil.java | 15 +++++++-------- .../typicalWarehousesClinic.json | 9 +++++++++ .../seedu/clinic/testutil/TypicalWarehouse.java | 7 +++++-- .../seedu/clinic/testutil/WarehouseBuilder.java | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/seedu/clinic/model/util/SampleDataUtil.java b/src/main/java/seedu/clinic/model/util/SampleDataUtil.java index 57abf4064c3..1b0df02142a 100644 --- a/src/main/java/seedu/clinic/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/clinic/model/util/SampleDataUtil.java @@ -49,22 +49,22 @@ public static Warehouse[] getSampleWarehouses() { return new Warehouse[] { new Warehouse(new Name("Alex Yeoh warehouse"), new Phone("87438807"), new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), - getProductSetForWarehouse(Map.of("Panadol", 10))), + getProductSetForWarehouse(new HashSet(), Map.of("Panadol", 10))), new Warehouse(new Name("Bernice Yu warehouse"), new Phone("99272758"), new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), - getProductSetForWarehouse(Map.of("Panadol", 20))), + getProductSetForWarehouse(new HashSet(), Map.of("Panadol", 20))), new Warehouse(new Name("Charlotte Oliveiro warehouse"), new Phone("93210283"), new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), - getProductSetForWarehouse(Map.of("Panadol", 30))), + getProductSetForWarehouse(new HashSet(), Map.of("Panadol", 30))), new Warehouse(new Name("David Li warehouse"), new Phone("91031282"), new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), - getProductSetForWarehouse(Map.of("Panadol", 100))), + getProductSetForWarehouse(new HashSet(), Map.of("Panadol", 100))), new Warehouse(new Name("Irfan Ibrahim warehouse"), new Phone("92492021"), new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), - getProductSetForWarehouse(Map.of("Panadol", 50))), + getProductSetForWarehouse(new HashSet(), Map.of("Panadol", 50))), new Warehouse(new Name("Roy Balakrishnan warehouse"), new Phone("92624417"), new Address("21 Lower Kent Ridge Rd, Singapore 119077"), new Remark("long term partner"), - getProductSetForWarehouse(Map.of("Panadol", 70))), + getProductSetForWarehouse(new HashSet(), Map.of("Panadol", 70))), }; } @@ -105,8 +105,7 @@ public static Set getProductSet(Set productSet, Map getProductSetForWarehouse(Map productMap) { - Set productSet = new HashSet<>(); + public static Set getProductSetForWarehouse(Set productSet, Map productMap) { for (String productName:productMap.keySet()) { Product product = new Product(new Name(productName), productMap.get(productName)); productSet.add(product); diff --git a/src/test/data/JsonSerializableClinicTest/typicalWarehousesClinic.json b/src/test/data/JsonSerializableClinicTest/typicalWarehousesClinic.json index 9286c94595d..55d5fa58810 100644 --- a/src/test/data/JsonSerializableClinicTest/typicalWarehousesClinic.json +++ b/src/test/data/JsonSerializableClinicTest/typicalWarehousesClinic.json @@ -45,6 +45,9 @@ "products" : [ { "name": "Cough Syrup", "quantity": 30 + }, { + "name": "Medical Glove", + "quantity": 50 } ] }, { "name" : "Warehouse Fiona", @@ -54,6 +57,12 @@ "products" : [ { "name": "Flu Syrup", "quantity": 1000 + }, { + "name": "Medical Glove", + "quantity": 50 + }, { + "name": "Syringe", + "quantity": 500 } ] }, { "name" : "Warehouse George", diff --git a/src/test/java/seedu/clinic/testutil/TypicalWarehouse.java b/src/test/java/seedu/clinic/testutil/TypicalWarehouse.java index 3006532f408..5f2cc563cfb 100644 --- a/src/test/java/seedu/clinic/testutil/TypicalWarehouse.java +++ b/src/test/java/seedu/clinic/testutil/TypicalWarehouse.java @@ -45,11 +45,14 @@ public class TypicalWarehouse { public static final Warehouse ELLE = new WarehouseBuilder().withName("Warehouse Elle") .withRemark("Warehouse 5").withAddress("elle address") .withPhone("94651253") - .withProducts(Map.of("Cough Syrup", 30)).build(); + .withProducts(Map.of("Cough Syrup", 30)) + .withProducts(Map.of("Medical Glove", 50)).build(); public static final Warehouse FIONA = new WarehouseBuilder().withName("Warehouse Fiona") .withRemark("Warehouse 10").withAddress("fiona address") .withPhone("92351253") - .withProducts(Map.of("Flu Syrup", 1000)).build(); + .withProducts(Map.of("Flu Syrup", 1000)) + .withProducts(Map.of("Medical Glove", 50)) + .withProducts(Map.of("Syringe", 500)).build(); public static final Warehouse GEORGE = new WarehouseBuilder().withName("Warehouse George") .withRemark("Warehouse to be removed").withAddress("george address") .withPhone("84351253") diff --git a/src/test/java/seedu/clinic/testutil/WarehouseBuilder.java b/src/test/java/seedu/clinic/testutil/WarehouseBuilder.java index 4376da99159..57bf56d5ece 100644 --- a/src/test/java/seedu/clinic/testutil/WarehouseBuilder.java +++ b/src/test/java/seedu/clinic/testutil/WarehouseBuilder.java @@ -61,7 +61,7 @@ public WarehouseBuilder withName(String name) { * Parses the {@code products} into a {@code Set} and set it to the {@code Warehouse} that we are building. */ public WarehouseBuilder withProducts(Map productMap) { - this.products = SampleDataUtil.getProductSetForWarehouse(productMap); + this.products = SampleDataUtil.getProductSetForWarehouse(products, productMap); return this; } From 34e17a40e3094e0f62738573179cc88bb00ff39d Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 22:03:04 +0800 Subject: [PATCH 13/14] Add more tests for FindCommandParser --- .../logic/parser/FindCommandParserTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java index 86fc7817c12..360b828ddcc 100644 --- a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java @@ -24,6 +24,22 @@ public void parse_emptyArg_throwsParseException() { assertParseFailure(parser, " ", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); } + @Test + public void parse_invalidType_throwsParseException() { + assertParseFailure(parser, "s", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "w", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "suppliers", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "warehouses", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "suppliersqwerty panadol", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "warehouses panadol", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + } + + @Test + public void parse_missingKeyword_throwsParseException() { + assertParseFailure(parser, "supplier", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "warehouse", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + } + @Test public void parse_validArgs_returnsFindSuppliersCommand() { // no leading and trailing whitespaces From 3c33317c91dfd62ec1b67cf3ee788b8bd1a79efb Mon Sep 17 00:00:00 2001 From: Zheng Wei Date: Sat, 10 Oct 2020 22:05:12 +0800 Subject: [PATCH 14/14] Fix code style errors --- .../logic/parser/FindCommandParserTest.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java index 360b828ddcc..6657fea392a 100644 --- a/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/clinic/logic/parser/FindCommandParserTest.java @@ -21,23 +21,32 @@ public class FindCommandParserTest { @Test public void parse_emptyArg_throwsParseException() { - assertParseFailure(parser, " ", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, " ", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FindCommand.MESSAGE_USAGE)); } @Test public void parse_invalidType_throwsParseException() { - assertParseFailure(parser, "s", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); - assertParseFailure(parser, "w", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); - assertParseFailure(parser, "suppliers", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); - assertParseFailure(parser, "warehouses", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); - assertParseFailure(parser, "suppliersqwerty panadol", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); - assertParseFailure(parser, "warehouses panadol", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "s", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "w", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "suppliers", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "warehouses", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "suppliersqwerty panadol", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "warehouses panadol", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FindCommand.MESSAGE_USAGE)); } @Test public void parse_missingKeyword_throwsParseException() { - assertParseFailure(parser, "supplier", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); - assertParseFailure(parser, "warehouse", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "supplier", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FindCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "warehouse", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FindCommand.MESSAGE_USAGE)); } @Test