diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000000..519da2bbecf --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,4 @@ +# Changes + +# Related Issues/ PRs +- Fixes # (issue) diff --git a/src/main/java/seedu/ibook/logic/parser/AddCommandParser.java b/src/main/java/seedu/ibook/logic/parser/AddCommandParser.java index 65d48a913e2..c7be2574401 100644 --- a/src/main/java/seedu/ibook/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/ibook/logic/parser/AddCommandParser.java @@ -34,13 +34,14 @@ public AddCommand parse(String args) throws ParseException { ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_CATEGORY, PREFIX_EXPIRY_DATE, PREFIX_DESCRIPTION, PREFIX_PRICE); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_CATEGORY, PREFIX_EXPIRY_DATE, PREFIX_DESCRIPTION, + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_EXPIRY_DATE, PREFIX_DESCRIPTION, PREFIX_PRICE) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); - Category category = ParserUtil.parseCategory(argMultimap.getValue(PREFIX_CATEGORY).get()); + Category category = + ParserUtil.parseCategory(argMultimap.getValue(PREFIX_CATEGORY).orElse(Category.DEFAULT_CATEGORY)); ExpiryDate expiryDate = ParserUtil.parseExpiryDate(argMultimap.getValue(PREFIX_EXPIRY_DATE).get()); Description description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get()); Price price = ParserUtil.parsePrice(argMultimap.getValue(PREFIX_PRICE).get()); diff --git a/src/main/java/seedu/ibook/logic/parser/FindCommandParser.java b/src/main/java/seedu/ibook/logic/parser/FindCommandParser.java index 8db7682deff..a2af1baa914 100644 --- a/src/main/java/seedu/ibook/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/ibook/logic/parser/FindCommandParser.java @@ -42,35 +42,35 @@ public FindCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_NAME).isPresent()) { name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); } else { - name = Name.WILDNAME; + name = Name.WILD_NAME; wildCard--; } if (argMultimap.getValue(PREFIX_CATEGORY).isPresent()) { category = ParserUtil.parseCategory(argMultimap.getValue(PREFIX_CATEGORY).get()); } else { - category = Category.WILDCATEGORY; + category = Category.WILD_CATEGORY; wildCard--; } if (argMultimap.getValue(PREFIX_EXPIRY_DATE).isPresent()) { expiryDate = ParserUtil.parseExpiryDate(argMultimap.getValue(PREFIX_EXPIRY_DATE).get()); } else { - expiryDate = ExpiryDate.WILDEXPIRYDATE; + expiryDate = ExpiryDate.WILD_EXPIRY_DATE; wildCard--; } if (argMultimap.getValue(PREFIX_DESCRIPTION).isPresent()) { description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get()); } else { - description = Description.WILDDESCRIPTION; + description = Description.WILD_DESCRIPTION; wildCard--; } if (argMultimap.getValue(PREFIX_PRICE).isPresent()) { price = ParserUtil.parsePrice(argMultimap.getValue(PREFIX_PRICE).get()); } else { - price = Price.WILDPRICE; + price = Price.WILD_PRICE; wildCard--; } diff --git a/src/main/java/seedu/ibook/model/product/Category.java b/src/main/java/seedu/ibook/model/product/Category.java index af0c4d90843..d620d45770d 100644 --- a/src/main/java/seedu/ibook/model/product/Category.java +++ b/src/main/java/seedu/ibook/model/product/Category.java @@ -9,19 +9,14 @@ */ public class Category { - private static class WildCategory extends Category { - private WildCategory() {}; - + public static final Category WILD_CATEGORY = new Category() { @Override public boolean equals(Object other) { - if (other instanceof Category) { - return true; - } else { - return false; - } + return other instanceof Category; } - } - public static final WildCategory WILDCATEGORY = new WildCategory(); + }; + + public static final String DEFAULT_CATEGORY = "Miscellaneous"; public static final String MESSAGE_CONSTRAINTS = "Categories (if given) should only contain alphanumeric characters and spaces"; @@ -38,7 +33,7 @@ public boolean equals(Object other) { * Constructs a {@code Category} representing no categorization. */ private Category() { - fullCategoryName = ""; + fullCategoryName = DEFAULT_CATEGORY; } /** @@ -53,7 +48,10 @@ public Category(String categoryName) { } /** - * Returns true if a given string is a valid category name. + * Checks if the string is valid as per {@code VALIDATION_REGEX}. + * + * @param test String to test. + * @return Result of test. */ public static boolean isValidCategoryName(String test) { return test.matches(VALIDATION_REGEX); diff --git a/src/main/java/seedu/ibook/model/product/Description.java b/src/main/java/seedu/ibook/model/product/Description.java index 64504904fd7..0ffca99de07 100644 --- a/src/main/java/seedu/ibook/model/product/Description.java +++ b/src/main/java/seedu/ibook/model/product/Description.java @@ -9,19 +9,13 @@ */ public class Description { - private static class WildDescription extends Description { - private WildDescription() {}; - + public static final Description WILD_DESCRIPTION = new Description() { @Override public boolean equals(Object other) { - if (other instanceof Description) { - return true; - } else { - return false; - } + return other instanceof Description; } - } - public static final WildDescription WILDDESCRIPTION = new WildDescription(); + }; + public static final String MESSAGE_CONSTRAINTS = "Descriptions should only contain alphanumeric characters and spaces"; @@ -35,7 +29,7 @@ public boolean equals(Object other) { private Description() { fullDescription = "???"; - }; + } /** * Constructs a {@code Description}. @@ -49,7 +43,10 @@ public Description(String description) { } /** - * Returns true if a given string is a valid description. + * Checks if the string is valid as per {@code VALIDATION_REGEX}. + * + * @param test String to test. + * @return Result of test. */ public static boolean isValidDescription(String test) { return test.matches(VALIDATION_REGEX); diff --git a/src/main/java/seedu/ibook/model/product/ExpiryDate.java b/src/main/java/seedu/ibook/model/product/ExpiryDate.java index 39b63dd9053..1e1e9041a47 100644 --- a/src/main/java/seedu/ibook/model/product/ExpiryDate.java +++ b/src/main/java/seedu/ibook/model/product/ExpiryDate.java @@ -14,20 +14,12 @@ */ public class ExpiryDate { - private static class WildExpiryDate extends ExpiryDate { - private WildExpiryDate() {}; - + public static final ExpiryDate WILD_EXPIRY_DATE = new ExpiryDate() { @Override public boolean equals(Object other) { - if (other instanceof ExpiryDate) { - return true; - } else { - return false; - } + return other instanceof ExpiryDate; } - } - - public static final WildExpiryDate WILDEXPIRYDATE = new WildExpiryDate(); + }; public static final String MESSAGE_CONSTRAINTS = "Expiry dates should have format such as 03 May 2022, 3 May 2022 or 2022-05-03"; @@ -62,7 +54,10 @@ public ExpiryDate(String date) { } /** - * Returns true if a given {@code LocalDate} is a valid expiry date. + * Checks if a given {@code LocalDate} is valid as per {@code VALIDATION_REGEX}. + * + * @param expiryDate Date to test. + * @return Result of test. */ public static boolean isValidExpiryDate(String expiryDate) { return Arrays.stream(ACCEPTED_FORMATS) diff --git a/src/main/java/seedu/ibook/model/product/Name.java b/src/main/java/seedu/ibook/model/product/Name.java index 1977050a921..4ec3f50388b 100644 --- a/src/main/java/seedu/ibook/model/product/Name.java +++ b/src/main/java/seedu/ibook/model/product/Name.java @@ -9,21 +9,12 @@ */ public class Name { - private static class WildName extends Name { - private WildName() {}; - + public static final Name WILD_NAME = new Name() { @Override public boolean equals(Object other) { - if (other instanceof Name) { - return true; - } else { - return false; - } + return other instanceof Name; } - - } - - public static final WildName WILDNAME = new WildName(); + }; public static final String MESSAGE_CONSTRAINTS = "Names should only contain alphanumeric characters and spaces, and it should not be blank"; @@ -36,8 +27,6 @@ public boolean equals(Object other) { public final String fullName; - - private Name() { fullName = "???"; } @@ -54,7 +43,10 @@ public Name(String name) { } /** - * Returns true if a given string is a valid name. + * Checks if the string is valid as per {@code VALIDATION_REGEX}. + * + * @param test String to test. + * @return Result of test. */ public static boolean isValidName(String test) { return test.matches(VALIDATION_REGEX); diff --git a/src/main/java/seedu/ibook/model/product/Price.java b/src/main/java/seedu/ibook/model/product/Price.java index b15d0b999ec..a297e65b216 100644 --- a/src/main/java/seedu/ibook/model/product/Price.java +++ b/src/main/java/seedu/ibook/model/product/Price.java @@ -9,21 +9,13 @@ */ public class Price { - private static class WildPrice extends Price { - private WildPrice() {}; - + public static final Price WILD_PRICE = new Price() { @Override public boolean equals(Object other) { - if (other instanceof Price) { - return true; - } else { - return false; - } + return other instanceof Price; } + }; - } - - public static final WildPrice WILDPRICE = new WildPrice(); public static final String MESSAGE_CONSTRAINTS = "Prices should only be of type double, and should not be negative"; @@ -31,7 +23,7 @@ public boolean equals(Object other) { * The first character of the name must not be a whitespace, * otherwise " " (a blank string) becomes a valid input. */ - public static final String VALIDATION_REGEX = "\\d+(?:.\\d{1,2})?"; + public static final String VALIDATION_REGEX = "\\$?(\\d+(?:.\\d{1,2})?)"; public final Double price; @@ -47,16 +39,34 @@ private Price() { public Price(String price) { requireNonNull(price); checkArgument(isValidPrice(price), MESSAGE_CONSTRAINTS); + + price = removeDollarSign(price); this.price = Double.parseDouble(price); } /** - * Returns true if a given string is a valid price. + * Checks if the string is valid as per {@code VALIDATION_REGEX}. + * + * @param test String to test. + * @return Result of test. */ public static boolean isValidPrice(String test) { return test.matches(VALIDATION_REGEX); } + /** + * Removes "$" sign (if any) from a price string. + * + * @param price Price string. + * @return Price string with "$" sign removed (if any). + */ + private String removeDollarSign(String price) { + if (price.startsWith("$")) { + return price.substring(1); + } + + return price; + } @Override public String toString() { diff --git a/src/main/java/seedu/ibook/model/tag/Tag.java b/src/main/java/seedu/ibook/model/tag/Tag.java deleted file mode 100644 index 679298b40e9..00000000000 --- a/src/main/java/seedu/ibook/model/tag/Tag.java +++ /dev/null @@ -1,54 +0,0 @@ -package seedu.ibook.model.tag; - -import static java.util.Objects.requireNonNull; -import static seedu.ibook.commons.util.AppUtil.checkArgument; - -/** - * Represents a Tag in the ibook. - * Guarantees: immutable; name is valid as declared in {@link #isValidTagName(String)} - */ -public class Tag { - - public static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric"; - public static final String VALIDATION_REGEX = "\\p{Alnum}+"; - - public final String tagName; - - /** - * Constructs a {@code Tag}. - * - * @param tagName A valid tag name. - */ - public Tag(String tagName) { - requireNonNull(tagName); - checkArgument(isValidTagName(tagName), MESSAGE_CONSTRAINTS); - this.tagName = tagName; - } - - /** - * Returns true if a given string is a valid tag name. - */ - public static boolean isValidTagName(String test) { - return test.matches(VALIDATION_REGEX); - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof Tag // instanceof handles nulls - && tagName.equals(((Tag) other).tagName)); // state check - } - - @Override - public int hashCode() { - return tagName.hashCode(); - } - - /** - * Format state as text for viewing. - */ - public String toString() { - return '[' + tagName + ']'; - } - -} diff --git a/src/main/java/seedu/ibook/model/util/SampleDataUtil.java b/src/main/java/seedu/ibook/model/util/SampleDataUtil.java index 5a6fa58195f..70727ab91bd 100644 --- a/src/main/java/seedu/ibook/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/ibook/model/util/SampleDataUtil.java @@ -1,9 +1,5 @@ package seedu.ibook.model.util; -import java.util.Arrays; -import java.util.Set; -import java.util.stream.Collectors; - import seedu.ibook.model.IBook; import seedu.ibook.model.ReadOnlyIBook; import seedu.ibook.model.product.Category; @@ -12,7 +8,6 @@ import seedu.ibook.model.product.Name; import seedu.ibook.model.product.Price; import seedu.ibook.model.product.Product; -import seedu.ibook.model.tag.Tag; /** * Contains utility methods for populating {@code AddressBook} with sample data. @@ -26,15 +21,6 @@ public static Product[] getSampleProducts() { }; } - /** - * Returns a tag set containing the list of strings given. - */ - public static Set getTagSet(String... strings) { - return Arrays.stream(strings) - .map(Tag::new) - .collect(Collectors.toSet()); - } - public static ReadOnlyIBook getSampleIBook() { IBook sampleIb = new IBook(); for (Product sampleProduct : getSampleProducts()) { diff --git a/src/main/java/seedu/ibook/storage/JsonAdaptedTag.java b/src/main/java/seedu/ibook/storage/JsonAdaptedTag.java deleted file mode 100644 index 26c104d708d..00000000000 --- a/src/main/java/seedu/ibook/storage/JsonAdaptedTag.java +++ /dev/null @@ -1,48 +0,0 @@ -package seedu.ibook.storage; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -import seedu.ibook.commons.exceptions.IllegalValueException; -import seedu.ibook.model.tag.Tag; - -/** - * Jackson-friendly version of {@link Tag}. - */ -class JsonAdaptedTag { - - private final String tagName; - - /** - * Constructs a {@code JsonAdaptedTag} with the given {@code tagName}. - */ - @JsonCreator - public JsonAdaptedTag(String tagName) { - this.tagName = tagName; - } - - /** - * Converts a given {@code Tag} into this class for Jackson use. - */ - public JsonAdaptedTag(Tag source) { - tagName = source.tagName; - } - - @JsonValue - public String getTagName() { - return tagName; - } - - /** - * Converts this Jackson-friendly adapted tag object into the model's {@code Tag} object. - * - * @throws IllegalValueException if there were any data constraints violated in the adapted tag. - */ - public Tag toModelType() throws IllegalValueException { - if (!Tag.isValidTagName(tagName)) { - throw new IllegalValueException(Tag.MESSAGE_CONSTRAINTS); - } - return new Tag(tagName); - } - -} diff --git a/src/main/java/seedu/ibook/ui/CommandBox.java b/src/main/java/seedu/ibook/ui/CommandBox.java index 97a9ad63dce..e648ea559e2 100644 --- a/src/main/java/seedu/ibook/ui/CommandBox.java +++ b/src/main/java/seedu/ibook/ui/CommandBox.java @@ -4,25 +4,28 @@ import javafx.scene.control.TextField; import javafx.scene.layout.HBox; -public class CommandBox extends UiPart { +/** + * CommandBox Ui class. + */ +public class CommandBox extends UiComponent { private static final String FXML = "CommandBox.fxml"; - private final CommandExecutor commandExecutor; - @FXML private TextField commandTextField; /** - * Creates a {@code CommandBox} with the given {@code CommandExecutor}. + * Creates a {@code CommandBox} with a {@code CommandExecutor} + * and a {@code popupAdd}. + * + * @param mainWindow The {@code MainWindow} that this component resides on. */ - public CommandBox(CommandExecutor commandExecutor) { - super(FXML); - this.commandExecutor = commandExecutor; + public CommandBox(MainWindow mainWindow) { + super(FXML, mainWindow); } /** - * Handles the Enter button pressed event. + * Handles the Enter button pressed event in the command line. */ @FXML private void handleCommandEntered() { @@ -31,20 +34,16 @@ private void handleCommandEntered() { return; } - commandExecutor.execute(commandText); + getMainWindow().executeCommand(commandText); commandTextField.setText(""); } /** - * Represents a function that can execute commands. + * Handles the add product button clicked event. */ - @FunctionalInterface - public interface CommandExecutor { - /** - * Executes the command and returns the result. - * - * @see seedu.ibook.logic.Logic#execute(String) - */ - void execute(String commandText); + @FXML + private void handleAddProductClicked() { + getMainWindow().showPopupAdd(); } + } diff --git a/src/main/java/seedu/ibook/ui/MainWindow.java b/src/main/java/seedu/ibook/ui/MainWindow.java index 5ad4170f344..6aba53eeec8 100644 --- a/src/main/java/seedu/ibook/ui/MainWindow.java +++ b/src/main/java/seedu/ibook/ui/MainWindow.java @@ -12,6 +12,9 @@ import seedu.ibook.logic.commands.CommandResult; import seedu.ibook.logic.commands.exceptions.CommandException; import seedu.ibook.logic.parser.exceptions.ParseException; +import seedu.ibook.model.product.Product; +import seedu.ibook.ui.popup.PopupHandler; +import seedu.ibook.ui.table.Table; /** * The Main Window. Provides the basic application layout containing @@ -31,11 +34,16 @@ public class MainWindow extends UiPart { private ResultWindow resultWindow; private Table table; + private PopupHandler popupHandler; + @FXML private VBox mainContent; /** - * Creates a {@code MainWindow} with the given {@code Stage} and {@code Logic}. + * Initializes a {@code MainWindow}. + * + * @param primaryStage The {@code Stage} of the application. + * @param logic The main code {@code Logic}. */ public MainWindow(Stage primaryStage, Logic logic) { super(FXML, primaryStage); @@ -45,6 +53,9 @@ public MainWindow(Stage primaryStage, Logic logic) { this.logic = logic; } + /** + * Shows the stage. + */ void show() { primaryStage.show(); } @@ -57,26 +68,32 @@ private void handleExit() { primaryStage.hide(); } + /** + * Gets the primary stage. + * @return The primary stage. + */ Stage getPrimaryStage() { return primaryStage; } /** - * Fills up all the placeholders of this window. + * Fills up the inner part of this window. */ void fillInnerParts() { ObservableList children = mainContent.getChildren(); - menuToolbar = new MenuToolbar(); + popupHandler = new PopupHandler(this); + + menuToolbar = new MenuToolbar(this); children.add(menuToolbar.getRoot()); - commandBox = new CommandBox(this::executeCommand); + commandBox = new CommandBox(this); children.add(commandBox.getRoot()); - resultWindow = new ResultWindow(); + resultWindow = new ResultWindow(this); children.add(resultWindow.getRoot()); - table = new Table(logic.getFilteredIBook()); + table = new Table(this); children.add(table.getRoot()); } @@ -85,7 +102,7 @@ void fillInnerParts() { * * @see seedu.ibook.logic.Logic#execute(String) */ - private void executeCommand(String commandText) { + public void executeCommand(String commandText) { try { CommandResult commandResult = logic.execute(commandText); logger.info("Result: " + commandResult.getFeedbackToUser()); @@ -94,10 +111,52 @@ private void executeCommand(String commandText) { if (commandResult.isExit()) { handleExit(); } - + hidePopup(); } catch (CommandException | ParseException e) { logger.info("Invalid command: " + commandText); - resultWindow.setFeedbackToUser(e.getMessage()); + setError(e.getMessage()); + } + } + + /** + * Shows the popup window for adding product. + */ + public void showPopupAdd() { + popupHandler.showPopupAdd(); + } + + /** + * Shows the popup window for updating product. + */ + public void showPopupUpdate(int index, Product product) { + popupHandler.showPopupUpdate(index, product); + } + + /** + * Shows the popup window for deleting product. + */ + public void showPopupDelete(int index, Product product) { + popupHandler.showPopupDelete(index, product); + } + + /** + * Gets the filtered list of {@code Product} from {@code Logic}. + * + * @return Get a filtered list of {@code Product}. + */ + public ObservableList getFilteredIBook() { + return logic.getFilteredIBook(); + } + + private void hidePopup() { + popupHandler.hidePopup(); + } + + private void setError(String message) { + if (popupHandler.isShowing()) { + popupHandler.setFeedbackToUser(message); + } else { + resultWindow.setFeedbackToUser(message); } } } diff --git a/src/main/java/seedu/ibook/ui/MenuToolbar.java b/src/main/java/seedu/ibook/ui/MenuToolbar.java index 0e14a919ab7..75f14abea79 100644 --- a/src/main/java/seedu/ibook/ui/MenuToolbar.java +++ b/src/main/java/seedu/ibook/ui/MenuToolbar.java @@ -2,12 +2,20 @@ import javafx.scene.control.MenuBar; -public class MenuToolbar extends UiPart { +/** + * The menu toolbar of the application. + */ +public class MenuToolbar extends UiComponent { private static final String FXML = "MenuToolbar.fxml"; - MenuToolbar() { - super(FXML); + /** + * Initializes a {@code MenuToolbar}. + * + * @param mainWindow The {@code MainWindow} that this component resides on. + */ + MenuToolbar(MainWindow mainWindow) { + super(FXML, mainWindow); } } diff --git a/src/main/java/seedu/ibook/ui/ProductCard.java b/src/main/java/seedu/ibook/ui/ProductCard.java deleted file mode 100644 index 80a8a073805..00000000000 --- a/src/main/java/seedu/ibook/ui/ProductCard.java +++ /dev/null @@ -1,47 +0,0 @@ -package seedu.ibook.ui; - -import javafx.fxml.FXML; -import javafx.scene.control.Label; -import javafx.scene.layout.HBox; -import seedu.ibook.model.product.Product; - -public class ProductCard extends UiPart { - - private static final String FXML = "ProductCard.fxml"; - - private final int id; - private final Product product; - - @FXML - private Label index; - @FXML - private Label name; - @FXML - private Label category; - @FXML - private Label expiryDate; - @FXML - private Label price; - @FXML - private Label description; - - @FXML - private HBox action; - - ProductCard(int index, Product product) { - super(FXML); - this.id = index; - this.product = product; - populateField(); - } - - void populateField() { - index.setText(String.valueOf(id)); - name.setText(product.getName().toString()); - category.setText(product.getCategory().toString()); - expiryDate.setText(product.getExpiryDate().toString()); - price.setText(product.getPrice().toString()); - description.setText(product.getDescription().toString()); - } - -} diff --git a/src/main/java/seedu/ibook/ui/ResultWindow.java b/src/main/java/seedu/ibook/ui/ResultWindow.java index 7940ac84269..b5779e745e7 100644 --- a/src/main/java/seedu/ibook/ui/ResultWindow.java +++ b/src/main/java/seedu/ibook/ui/ResultWindow.java @@ -2,23 +2,32 @@ import static java.util.Objects.requireNonNull; -import javafx.fxml.FXML; import javafx.scene.control.TextArea; -public class ResultWindow extends UiPart + + + + + + + + + + + + + diff --git a/src/main/resources/view/popup/PopupDelete.fxml b/src/main/resources/view/popup/PopupDelete.fxml new file mode 100644 index 00000000000..72e1c192dee --- /dev/null +++ b/src/main/resources/view/popup/PopupDelete.fxml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/popup/PopupUpdate.fxml b/src/main/resources/view/popup/PopupUpdate.fxml new file mode 100644 index 00000000000..b6011895a28 --- /dev/null +++ b/src/main/resources/view/popup/PopupUpdate.fxml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/seedu/ibook/logic/commands/AddCommandTest.java b/src/test/java/seedu/ibook/logic/commands/AddCommandTest.java index c3cfa5e6180..931f2145c7c 100644 --- a/src/test/java/seedu/ibook/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/ibook/logic/commands/AddCommandTest.java @@ -41,23 +41,23 @@ public void execute_productAcceptedByModel_addSuccessful() throws Exception { @Test public void equals() { - Product alice = new ProductBuilder().withName("Alice").build(); - Product bob = new ProductBuilder().withName("Bob").build(); - AddCommand addAliceCommand = new AddCommand(alice); - AddCommand addBobCommand = new AddCommand(bob); + Product productA = new ProductBuilder().withName("Product A").build(); + Product productB = new ProductBuilder().withName("Product B").build(); + AddCommand addProductACommand = new AddCommand(productA); + AddCommand addProductBCommand = new AddCommand(productB); // same object -> returns true - assertEquals(addAliceCommand, addAliceCommand); + assertEquals(addProductACommand, addProductACommand); // same values -> returns true - AddCommand addAliceCommandCopy = new AddCommand(alice); - assertEquals(addAliceCommand, addAliceCommandCopy); + AddCommand addProductACommandCopy = new AddCommand(productA); + assertEquals(addProductACommand, addProductACommandCopy); // null -> returns false - assertNotEquals(null, addAliceCommand); + assertNotEquals(null, addProductACommand); // different product -> returns false - assertNotEquals(addAliceCommand, addBobCommand); + assertNotEquals(addProductACommand, addProductBCommand); } /** diff --git a/src/test/java/seedu/ibook/logic/commands/CommandTestUtil.java b/src/test/java/seedu/ibook/logic/commands/CommandTestUtil.java index 65267ffd451..b83e2d31e5c 100644 --- a/src/test/java/seedu/ibook/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/ibook/logic/commands/CommandTestUtil.java @@ -49,7 +49,7 @@ public class CommandTestUtil { public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "Bread&"; // '&' not allowed in names public static final String INVALID_CATEGORY_DESC = " " + PREFIX_CATEGORY + "Bread&"; // '&' not allowed in category public static final String INVALID_EXPIRY_DATE_DESC = " " + PREFIX_EXPIRY_DATE + "2022 03 08"; // incorrect format - public static final String INVALID_DESCRIPTION_DESC = " " + PREFIX_DESCRIPTION; // empty string not allowed for desc + public static final String INVALID_DESCRIPTION_DESC = " " + PREFIX_DESCRIPTION + "Bread&"; // '&' not allowed public static final String INVALID_PRICE_DESC = " " + PREFIX_PRICE + "-1"; // price must be a positive amount public static final String PREAMBLE_WHITESPACE = "\t \r \n"; diff --git a/src/test/java/seedu/ibook/logic/commands/FindCommandTest.java b/src/test/java/seedu/ibook/logic/commands/FindCommandTest.java index 59be41aa0a8..2fde817c81c 100644 --- a/src/test/java/seedu/ibook/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/ibook/logic/commands/FindCommandTest.java @@ -50,7 +50,7 @@ public class FindCommandTest { new Category(VALID_CATEGORY_A), new ExpiryDate(VALID_EXPIRY_DATE_A), new Description(VALID_DESCRIPTION_A), - Price.WILDPRICE)); + Price.WILD_PRICE)); private ProductFulfillsFiltersPredicate kayaPredicate = new ProductFulfillsFiltersPredicate(KAYA_BREAD); diff --git a/src/test/java/seedu/ibook/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/ibook/logic/parser/AddCommandParserTest.java index 94a4fba3b46..795bef38a9a 100644 --- a/src/test/java/seedu/ibook/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/ibook/logic/parser/AddCommandParserTest.java @@ -7,8 +7,14 @@ import static seedu.ibook.logic.commands.CommandTestUtil.DESCRIPTION_FULL_B; import static seedu.ibook.logic.commands.CommandTestUtil.EXPIRY_DATE_FULL_A; import static seedu.ibook.logic.commands.CommandTestUtil.EXPIRY_DATE_FULL_B; +import static seedu.ibook.logic.commands.CommandTestUtil.INVALID_CATEGORY_DESC; +import static seedu.ibook.logic.commands.CommandTestUtil.INVALID_DESCRIPTION_DESC; +import static seedu.ibook.logic.commands.CommandTestUtil.INVALID_EXPIRY_DATE_DESC; +import static seedu.ibook.logic.commands.CommandTestUtil.INVALID_NAME_DESC; +import static seedu.ibook.logic.commands.CommandTestUtil.INVALID_PRICE_DESC; import static seedu.ibook.logic.commands.CommandTestUtil.NAME_FULL_A; import static seedu.ibook.logic.commands.CommandTestUtil.NAME_FULL_B; +import static seedu.ibook.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY; import static seedu.ibook.logic.commands.CommandTestUtil.PRICE_FULL_A; import static seedu.ibook.logic.commands.CommandTestUtil.PRICE_FULL_B; import static seedu.ibook.logic.commands.CommandTestUtil.VALID_CATEGORY_B; @@ -23,6 +29,11 @@ import org.junit.jupiter.api.Test; import seedu.ibook.logic.commands.AddCommand; +import seedu.ibook.model.product.Category; +import seedu.ibook.model.product.Description; +import seedu.ibook.model.product.ExpiryDate; +import seedu.ibook.model.product.Name; +import seedu.ibook.model.product.Price; import seedu.ibook.model.product.Product; import seedu.ibook.testutil.ProductBuilder; @@ -47,11 +58,6 @@ public void parse_compulsoryFieldMissing_failure() { VALID_NAME_B + CATEGORY_FULL_B + EXPIRY_DATE_FULL_B + DESCRIPTION_FULL_B + PRICE_FULL_B, expectedMessage); - // missing category prefix - assertParseFailure(parser, - NAME_FULL_B + VALID_CATEGORY_B + EXPIRY_DATE_FULL_B + DESCRIPTION_FULL_B + PRICE_FULL_B, - expectedMessage); - // missing expiry date prefix assertParseFailure(parser, NAME_FULL_B + CATEGORY_FULL_B + VALID_EXPIRY_DATE_B + DESCRIPTION_FULL_B + PRICE_FULL_B, @@ -73,7 +79,39 @@ public void parse_compulsoryFieldMissing_failure() { expectedMessage); } + @Test + public void parse_setDefaultCategory_success() { + // missing category + Product expectedProduct = new ProductBuilder(PRODUCT_A).withCategory(Category.DEFAULT_CATEGORY).build(); + assertParseSuccess(parser, NAME_FULL_A + EXPIRY_DATE_FULL_A + DESCRIPTION_FULL_A + PRICE_FULL_A, + new AddCommand(expectedProduct)); + } + @Test public void parse_invalidValue_failure() { + // invalid name + assertParseFailure(parser, INVALID_NAME_DESC + CATEGORY_FULL_B + EXPIRY_DATE_FULL_B + DESCRIPTION_FULL_B + + PRICE_FULL_B, Name.MESSAGE_CONSTRAINTS); + + // invalid category + assertParseFailure(parser, NAME_FULL_B + INVALID_CATEGORY_DESC + EXPIRY_DATE_FULL_B + DESCRIPTION_FULL_B + + PRICE_FULL_B, Category.MESSAGE_CONSTRAINTS); + + // invalid expiry date + assertParseFailure(parser, NAME_FULL_B + CATEGORY_FULL_B + INVALID_EXPIRY_DATE_DESC + DESCRIPTION_FULL_B + + PRICE_FULL_B, ExpiryDate.MESSAGE_CONSTRAINTS); + + // invalid description + assertParseFailure(parser, NAME_FULL_B + CATEGORY_FULL_B + EXPIRY_DATE_FULL_B + INVALID_DESCRIPTION_DESC + + PRICE_FULL_B, Description.MESSAGE_CONSTRAINTS); + + // invalid price + assertParseFailure(parser, NAME_FULL_B + CATEGORY_FULL_B + EXPIRY_DATE_FULL_B + DESCRIPTION_FULL_B + + INVALID_PRICE_DESC, Price.MESSAGE_CONSTRAINTS); + + // non-empty preamble + assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_FULL_B + CATEGORY_FULL_B + EXPIRY_DATE_FULL_B + + DESCRIPTION_FULL_B + PRICE_FULL_B, + String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } } diff --git a/src/test/java/seedu/ibook/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/ibook/logic/parser/FindCommandParserTest.java index 47f9fc6eba2..8a4b788267f 100644 --- a/src/test/java/seedu/ibook/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/ibook/logic/parser/FindCommandParserTest.java @@ -41,9 +41,9 @@ public void parse_validArgs_returnsFindCommand() { FindCommand expectedFindCommand2 = new FindCommand(new ProductFulfillsFiltersPredicate(new Product ( new Name("Maggi"), - Category.WILDCATEGORY, + Category.WILD_CATEGORY, new ExpiryDate("2022-01-01"), - Description.WILDDESCRIPTION, + Description.WILD_DESCRIPTION, new Price("3.00"))) ); diff --git a/src/test/java/seedu/ibook/model/IBookTest.java b/src/test/java/seedu/ibook/model/IBookTest.java index fef26473d08..37926b0cf0e 100644 --- a/src/test/java/seedu/ibook/model/IBookTest.java +++ b/src/test/java/seedu/ibook/model/IBookTest.java @@ -1,14 +1,13 @@ package seedu.ibook.model; -/* + 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.ibook.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; -import static seedu.ibook.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.ibook.logic.commands.CommandTestUtil.VALID_DESCRIPTION_B; +import static seedu.ibook.logic.commands.CommandTestUtil.VALID_PRICE_B; import static seedu.ibook.testutil.Assert.assertThrows; -import static seedu.ibook.testutil.TypicalPersons.ALICE; -import static seedu.ibook.testutil.TypicalPersons.getTypicalAddressBook; +import static seedu.ibook.testutil.TypicalProducts.PRODUCT_A; +import static seedu.ibook.testutil.TypicalProducts.getTypicalIBook; import java.util.Arrays; import java.util.Collection; @@ -19,87 +18,88 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import seedu.ibook.model.person.Person; -import seedu.ibook.model.person.exceptions.DuplicatePersonException; -import seedu.ibook.testutil.PersonBuilder; +import seedu.ibook.model.product.Product; +import seedu.ibook.model.product.exceptions.DuplicateProductException; +import seedu.ibook.testutil.ProductBuilder; - */ public class IBookTest { -/* - private final AddressBook addressBook = new AddressBook(); + private final IBook iBook = new IBook(); @Test public void constructor() { - assertEquals(Collections.emptyList(), addressBook.getPersonList()); + assertEquals(Collections.emptyList(), iBook.getProductList()); } @Test public void resetData_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> addressBook.resetData(null)); + assertThrows(NullPointerException.class, () -> iBook.resetData(null)); } @Test - public void resetData_withValidReadOnlyAddressBook_replacesData() { - AddressBook newData = getTypicalAddressBook(); - addressBook.resetData(newData); - assertEquals(newData, addressBook); + public void resetData_withValidReadOnlyIBook_replacesData() { + IBook newData = getTypicalIBook(); + iBook.resetData(newData); + assertEquals(newData, iBook); } @Test - public void resetData_withDuplicatePersons_throwsDuplicatePersonException() { - // Two persons with the same identity fields - Person editedAlice = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND) + public void resetData_withDuplicateProducts_throwsDuplicateProductException() { + // Two products with the same identity fields + Product editedProduct = new ProductBuilder(PRODUCT_A) + .withPrice(VALID_PRICE_B) + .withDescription(VALID_DESCRIPTION_B) .build(); - List newPersons = Arrays.asList(ALICE, editedAlice); - AddressBookStub newData = new AddressBookStub(newPersons); + List newProducts = Arrays.asList(PRODUCT_A, editedProduct); + IBookStub newData = new IBookStub(newProducts); - assertThrows(DuplicatePersonException.class, () -> addressBook.resetData(newData)); + assertThrows(DuplicateProductException.class, () -> iBook.resetData(newData)); } @Test - public void hasPerson_nullPerson_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> addressBook.hasPerson(null)); + public void hasProduct_nullProduct_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> iBook.hasProduct(null)); } @Test - public void hasPerson_personNotInAddressBook_returnsFalse() { - assertFalse(addressBook.hasPerson(ALICE)); + public void hasProduct_productNotInIBook_returnsFalse() { + assertFalse(iBook.hasProduct(PRODUCT_A)); } @Test - public void hasPerson_personInAddressBook_returnsTrue() { - addressBook.addPerson(ALICE); - assertTrue(addressBook.hasPerson(ALICE)); + public void hasProduct_productInIBook_returnsTrue() { + iBook.addProduct(PRODUCT_A); + assertTrue(iBook.hasProduct(PRODUCT_A)); } @Test - public void hasPerson_personWithSameIdentityFieldsInAddressBook_returnsTrue() { - addressBook.addPerson(ALICE); - Person editedAlice = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND) + public void hasProduct_productWithSameIdentityFieldsInIBook_returnsTrue() { + iBook.addProduct(PRODUCT_A); + Product editedProduct = new ProductBuilder(PRODUCT_A) + .withPrice(VALID_PRICE_B) + .withDescription(VALID_DESCRIPTION_B) .build(); - assertTrue(addressBook.hasPerson(editedAlice)); + assertTrue(iBook.hasProduct(editedProduct)); } @Test - public void getPersonList_modifyList_throwsUnsupportedOperationException() { - assertThrows(UnsupportedOperationException.class, () -> addressBook.getPersonList().remove(0)); + public void getProductList_modifyList_throwsUnsupportedOperationException() { + assertThrows(UnsupportedOperationException.class, () -> iBook.getProductList().remove(0)); } /** - * A stub ReadOnlyAddressBook whose persons list can violate interface constraints. - - private static class AddressBookStub implements ReadOnlyAddressBook { - private final ObservableList persons = FXCollections.observableArrayList(); + * A stub ReadOnlyIBook whose products list can violate interface constraints. + */ + private static class IBookStub implements ReadOnlyIBook { + private final ObservableList products = FXCollections.observableArrayList(); - AddressBookStub(Collection persons) { - this.persons.setAll(persons); + IBookStub(Collection products) { + this.products.setAll(products); } @Override - public ObservableList getPersonList() { - return persons; + public ObservableList getProductList() { + return products; } } - */ } diff --git a/src/test/java/seedu/ibook/model/ModelManagerTest.java b/src/test/java/seedu/ibook/model/ModelManagerTest.java index 09c99123eba..dbc6a844f2e 100644 --- a/src/test/java/seedu/ibook/model/ModelManagerTest.java +++ b/src/test/java/seedu/ibook/model/ModelManagerTest.java @@ -1,37 +1,30 @@ package seedu.ibook.model; -/* + 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.ibook.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import static seedu.ibook.model.Model.PREDICATE_SHOW_ALL_PRODUCTS; import static seedu.ibook.testutil.Assert.assertThrows; - -import static seedu.ibook.testutil.TypicalPersons.ALICE; -import static seedu.ibook.testutil.TypicalPersons.BENSON; - - +import static seedu.ibook.testutil.TypicalProducts.PRODUCT_A; +import static seedu.ibook.testutil.TypicalProducts.PRODUCT_B; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import org.junit.jupiter.api.Test; import seedu.ibook.commons.core.GuiSettings; -import seedu.ibook.model.person.NameContainsKeywordsPredicate; -import seedu.ibook.testutil.AddressBookBuilder; - +import seedu.ibook.model.product.ProductFulfillsFiltersPredicate; +import seedu.ibook.testutil.IBookBuilder; - */ public class ModelManagerTest { -/* private ModelManager modelManager = new ModelManager(); @Test public void constructor() { - assertEquals(new OldUserPrefs(), modelManager.getUserPrefs()); + assertEquals(new UserPrefs(), modelManager.getUserPrefs()); assertEquals(new GuiSettings(), modelManager.getGuiSettings()); - assertEquals(new AddressBook(), new AddressBook(modelManager.getAddressBook())); + assertEquals(new IBook(), new IBook(modelManager.getIBook())); } @Test @@ -41,15 +34,15 @@ public void setUserPrefs_nullUserPrefs_throwsNullPointerException() { @Test public void setUserPrefs_validUserPrefs_copiesUserPrefs() { - OldUserPrefs userPrefs = new OldUserPrefs(); - userPrefs.setAddressBookFilePath(Paths.get("address/book/file/path")); + UserPrefs userPrefs = new UserPrefs(); + userPrefs.setIBookFilePath(Paths.get("ibook/file/path")); userPrefs.setGuiSettings(new GuiSettings(1, 2, 3, 4)); modelManager.setUserPrefs(userPrefs); assertEquals(userPrefs, modelManager.getUserPrefs()); // Modifying userPrefs should not modify modelManager's userPrefs - OldUserPrefs oldUserPrefs = new OldUserPrefs(userPrefs); - userPrefs.setAddressBookFilePath(Paths.get("new/address/book/file/path")); + UserPrefs oldUserPrefs = new UserPrefs(userPrefs); + userPrefs.setIBookFilePath(Paths.get("new/ibook/file/path")); assertEquals(oldUserPrefs, modelManager.getUserPrefs()); } @@ -66,47 +59,47 @@ public void setGuiSettings_validGuiSettings_setsGuiSettings() { } @Test - public void setAddressBookFilePath_nullPath_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> modelManager.setAddressBookFilePath(null)); + public void setIBookFilePath_nullPath_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> modelManager.setIBookFilePath(null)); } @Test - public void setAddressBookFilePath_validPath_setsAddressBookFilePath() { - Path path = Paths.get("address/book/file/path"); - modelManager.setAddressBookFilePath(path); - assertEquals(path, modelManager.getAddressBookFilePath()); + public void setIBookFilePath_validPath_setsIBookFilePath() { + Path path = Paths.get("ibook/file/path"); + modelManager.setIBookFilePath(path); + assertEquals(path, modelManager.getIBookFilePath()); } @Test - public void hasPerson_nullPerson_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> modelManager.hasPerson(null)); + public void hasProduct_nullProduct_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> modelManager.hasProduct(null)); } @Test - public void hasPerson_personNotInAddressBook_returnsFalse() { - assertFalse(modelManager.hasPerson(ALICE)); + public void hasProduct_productNotInIBook_returnsFalse() { + assertFalse(modelManager.hasProduct(PRODUCT_A)); } @Test - public void hasPerson_personInAddressBook_returnsTrue() { - modelManager.addPerson(ALICE); - assertTrue(modelManager.hasPerson(ALICE)); + public void hasProduct_productInIBook_returnsTrue() { + modelManager.addProduct(PRODUCT_A); + assertTrue(modelManager.hasProduct(PRODUCT_A)); } @Test - public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException() { - assertThrows(UnsupportedOperationException.class, () -> modelManager.getFilteredPersonList().remove(0)); + public void getFilteredProductList_modifyList_throwsUnsupportedOperationException() { + assertThrows(UnsupportedOperationException.class, () -> modelManager.getFilteredProductList().remove(0)); } @Test public void equals() { - AddressBook addressBook = new AddressBookBuilder().withPerson(ALICE).withPerson(BENSON).build(); - AddressBook differentAddressBook = new AddressBook(); - OldUserPrefs userPrefs = new OldUserPrefs(); + IBook iBook = new IBookBuilder().withProduct(PRODUCT_A).withProduct(PRODUCT_B).build(); + IBook differentIBook = new IBook(); + UserPrefs userPrefs = new UserPrefs(); // same values -> returns true - modelManager = new ModelManager(addressBook, userPrefs); - ModelManager modelManagerCopy = new ModelManager(addressBook, userPrefs); + modelManager = new ModelManager(iBook, userPrefs); + ModelManager modelManagerCopy = new ModelManager(iBook, userPrefs); assertTrue(modelManager.equals(modelManagerCopy)); // same object -> returns true @@ -118,22 +111,20 @@ public void equals() { // different types -> returns false assertFalse(modelManager.equals(5)); - // different addressBook -> returns false - assertFalse(modelManager.equals(new ModelManager(differentAddressBook, userPrefs))); + // different iBook -> returns false + assertFalse(modelManager.equals(new ModelManager(differentIBook, userPrefs))); // different filteredList -> returns false - String[] keywords = ALICE.getName().fullName.split("\\s+"); - modelManager.updateFilteredPersonList(new NameContainsKeywordsPredicate(Arrays.asList(keywords))); - assertFalse(modelManager.equals(new ModelManager(addressBook, userPrefs))); + modelManager.updateFilteredProductList(new ProductFulfillsFiltersPredicate(PRODUCT_B)); + assertFalse(modelManager.equals(new ModelManager(iBook, userPrefs))); // resets modelManager to initial state for upcoming tests - modelManager.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + modelManager.updateFilteredProductList(PREDICATE_SHOW_ALL_PRODUCTS); // different userPrefs -> returns false - OldUserPrefs differentUserPrefs = new OldUserPrefs(); - differentUserPrefs.setAddressBookFilePath(Paths.get("differentFilePath")); - assertFalse(modelManager.equals(new ModelManager(addressBook, differentUserPrefs))); + UserPrefs differentUserPrefs = new UserPrefs(); + differentUserPrefs.setIBookFilePath(Paths.get("differentFilePath")); + assertFalse(modelManager.equals(new ModelManager(iBook, differentUserPrefs))); } - */ } diff --git a/src/test/java/seedu/ibook/model/tag/TagTest.java b/src/test/java/seedu/ibook/model/tag/TagTest.java deleted file mode 100644 index 2418d50b28c..00000000000 --- a/src/test/java/seedu/ibook/model/tag/TagTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package seedu.ibook.model.tag; - -import static seedu.ibook.testutil.Assert.assertThrows; - -import org.junit.jupiter.api.Test; - -public class TagTest { - - @Test - public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Tag(null)); - } - - @Test - public void constructor_invalidTagName_throwsIllegalArgumentException() { - String invalidTagName = ""; - assertThrows(IllegalArgumentException.class, () -> new Tag(invalidTagName)); - } - - @Test - public void isValidTagName() { - // null tag name - assertThrows(NullPointerException.class, () -> Tag.isValidTagName(null)); - } - -}