diff --git a/StockMasterData.txt b/StockMasterData.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/Diagrams/Images/Itemlist/AddCommand_SequenceDiagram.png b/docs/Diagrams/Images/Itemlist/AddCommand_SequenceDiagram.png index 63eab435b1..970784ed45 100644 Binary files a/docs/Diagrams/Images/Itemlist/AddCommand_SequenceDiagram.png and b/docs/Diagrams/Images/Itemlist/AddCommand_SequenceDiagram.png differ diff --git a/docs/Diagrams/Images/Storage/Storage.png b/docs/Diagrams/Images/Storage/Storage.png deleted file mode 100644 index a633a2adfd..0000000000 Binary files a/docs/Diagrams/Images/Storage/Storage.png and /dev/null differ diff --git a/docs/Diagrams/Images/Storage/Storage_ClassDiagram.png b/docs/Diagrams/Images/Storage/Storage_ClassDiagram.png index 882e1dd604..3c1a885d78 100644 Binary files a/docs/Diagrams/Images/Storage/Storage_ClassDiagram.png and b/docs/Diagrams/Images/Storage/Storage_ClassDiagram.png differ diff --git a/docs/Diagrams/Images/Storage/Storage_class_diagram.png b/docs/Diagrams/Images/Storage/Storage_class_diagram.png deleted file mode 100644 index 23ab02f3db..0000000000 Binary files a/docs/Diagrams/Images/Storage/Storage_class_diagram.png and /dev/null differ diff --git a/docs/Diagrams/Images/Storage/Storage_sequenceDiagram.png b/docs/Diagrams/Images/Storage/Storage_sequenceDiagram.png index 0d331b2b72..93d2c6bf21 100644 Binary files a/docs/Diagrams/Images/Storage/Storage_sequenceDiagram.png and b/docs/Diagrams/Images/Storage/Storage_sequenceDiagram.png differ diff --git a/docs/Diagrams/PUML files/Itemlist/AddCommand_SequenceDiagram.puml b/docs/Diagrams/PUML files/Itemlist/AddCommand_SequenceDiagram.puml index e03bf52445..bb09b1e541 100644 --- a/docs/Diagrams/PUML files/Itemlist/AddCommand_SequenceDiagram.puml +++ b/docs/Diagrams/PUML files/Itemlist/AddCommand_SequenceDiagram.puml @@ -2,32 +2,31 @@ !include ../Style.puml actor User -participant "Parser" as Parser -participant "AddCommand" as AddCommand -participant "Itemlist" as Itemlist -participant "EditCommand" as EditCommand +participant ":Parser" as Parser +participant ":AddCommand" as AddCommand +participant ":Itemlist" as Itemlist +participant ":EditCommand" as EditCommand User -> Parser: add command activate Parser Parser -> AddCommand: prepareAdd(userInput) activate AddCommand -AddCommand -> Itemlist: itemIsExist(itemName) activate Itemlist alt Item exists - Itemlist -> AddCommand: true AddCommand -> EditCommand: edit Item activate EditCommand EditCommand -> Itemlist: editQuantity(index, newQuantity) deactivate EditCommand + Itemlist --> AddCommand AddCommand -> User: Output success message else Item does not exist -Itemlist -> AddCommand: false AddCommand -> Itemlist: addItem(item) - deactivate Itemlist + Itemlist --> AddCommand AddCommand -> User: Output success message deactivate AddCommand -deactivate Parser end +deactivate Itemlist +deactivate Parser @enduml diff --git a/docs/Diagrams/PUML files/Storage/Storage_ClassDiagram.puml b/docs/Diagrams/PUML files/Storage/Storage_ClassDiagram.puml index bedd73d016..e61470ee65 100644 --- a/docs/Diagrams/PUML files/Storage/Storage_ClassDiagram.puml +++ b/docs/Diagrams/PUML files/Storage/Storage_ClassDiagram.puml @@ -1,5 +1,5 @@ @startuml -hide circle +!include ../Style.puml class Storage { +readFromFile(fileName: String) diff --git a/docs/Diagrams/PUML files/Storage/Storage_sequenceDiagram.puml b/docs/Diagrams/PUML files/Storage/Storage_sequenceDiagram.puml index a804cb4202..d41e1ecff8 100644 --- a/docs/Diagrams/PUML files/Storage/Storage_sequenceDiagram.puml +++ b/docs/Diagrams/PUML files/Storage/Storage_sequenceDiagram.puml @@ -1,5 +1,5 @@ @startuml -hide footbox +!include ../Style.puml participant Client participant Storage participant Itemlist diff --git a/docs/team/Fureimi.md b/docs/team/fureimi.md similarity index 84% rename from docs/team/Fureimi.md rename to docs/team/fureimi.md index e7c21e9d4a..03989d2079 100644 --- a/docs/team/Fureimi.md +++ b/docs/team/fureimi.md @@ -16,11 +16,13 @@ manage and operate their business. to keep track of their inventory. It also provides a convenient way for users to check a item of a certain category as they may have many items in the whole item list, making it hard to search for specific items. In addition, users might only want to see their marked items. The mark feature is explained below. + - **New Feature**: Added the ability to mark and unmark specific items in the item list. - **What it does**: Allows users to mark specific item in the item list. The user can also unmark a marked item. - **Justification**: Users might want to mark items for many reasons, such as to keep track of their sales as they may be a high in demand item. These items might also be from different categories, so user cannot list them by category. This feature hence provides a convenient way for users to access items they want to keep an eye on. + - **New Feature**: Added the ability to edit current item parameters. - **What it does**: Allows users to edit specific parameters of existing items, such as quantity, category, name, etc. - **Justification**: This feature is crucial to our application as it allows users to rectify user errors when @@ -30,11 +32,13 @@ only want to see their marked items. The mark feature is explained below. - **Highlights**: The implementation was challenging as it required integration with `Itemlist` as well as `item` to ensure that the parameters are edited accurately. In addition, this enhancement allows users to edit multiple parameters at once, which increases convenience for the user. -- **Code Contributed** : [RepoSense Link](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2024-02-23&tabOpen=true&tabType=authorship&tabAuthor=Fureimi&tabRepo=AY2324S2-CS2113-T15-4%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code&authorshipIsBinaryFileTypeChecked=false&authorshipIsIgnoredFilesChecked=false) + +- **Code Contributed** : [RepoSense Link](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=fureimi&breakdown=true) + - **Documentation**: - User Guide: - Added documentation for the features `list_items`, `mark`, `unmark` and `edit` - Update the command summary - Developer Guide: - Added class diagram of the `EditCommand` class. - - Added implementation details and sequence diagram of both the `list_items` and `edit` features. \ No newline at end of file + - Added implementation details and sequence diagram of both the `list_items` and `edit` features. diff --git a/docs/team/joellimjr.md b/docs/team/joellimjr.md index fe3835683a..afb669b2fb 100644 --- a/docs/team/joellimjr.md +++ b/docs/team/joellimjr.md @@ -39,6 +39,13 @@ manage and operate their business. and warn the user about the items that are running low in stock. +- **New Feature:** Detailed help command + - What it does: An extension of the help command, it gives users more detailed information about + a specific command along with examples. + - Justification: Some of the commands have many input variables, some of which are optional. + This feature aims to help users understand the specific requirements of the commands + + - **Code Contributed:** [RepoSense link](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2024-02-23&tabOpen=true&tabType=authorship&tabAuthor=Joellimjr&tabRepo=AY2324S2-CS2113-T15-4%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code&authorshipIsBinaryFileTypeChecked=false&authorshipIsIgnoredFilesChecked=false) @@ -48,4 +55,15 @@ manage and operate their business. - Update the command summary - Developer Guide: - Added implementation details and class diagram of the `Parser` class. - - Added implementation details and sequence diagram of the `add` feature. \ No newline at end of file + - Added implementation details and sequence diagram of the `add` feature. + + +- **J-Unit Testing** + - Added J-Unit testing: + - ParserTest + - AddCommandTest + - EditCommandTest + - HelpCommandTest + - SellCommandTest + - LowStockCommandTest + \ No newline at end of file diff --git a/src/main/java/command/EditCommand.java b/src/main/java/command/EditCommand.java index ba62935a32..1e0b1a5b1d 100644 --- a/src/main/java/command/EditCommand.java +++ b/src/main/java/command/EditCommand.java @@ -59,7 +59,7 @@ public float getNewSellPrice() { } /** - * Edits the relevant params of the item in the item list + * Edits the relevant params of the item in the item list and prints out to the user. */ @Override public void execute() { diff --git a/src/main/java/storage/PromotionStorage.java b/src/main/java/storage/PromotionStorage.java index fd5f44fc13..c12f0029e0 100644 --- a/src/main/java/storage/PromotionStorage.java +++ b/src/main/java/storage/PromotionStorage.java @@ -105,6 +105,9 @@ public static void readFromFile(String fileName) { } catch (InvalidDateException | CommandFormatException e) { LOGGER.log(Level.WARNING, "Other exception occurred.", e); System.out.println(e);; + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println(fileName + " is not written in a correct format."); + LOGGER.warning("Incorrect documentation format."); } scanner.close(); } diff --git a/src/test/java/command/EditCommandTest.java b/src/test/java/command/EditCommandTest.java new file mode 100644 index 0000000000..74a78986fd --- /dev/null +++ b/src/test/java/command/EditCommandTest.java @@ -0,0 +1,146 @@ +package command; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import itemlist.Itemlist; +import promotion.Promotionlist; +import storage.PromotionStorage; +import storage.Storage; +import storage.TransactionLogs; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +public class EditCommandTest { + + private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream(); + + @BeforeEach + public void setUp() { + System.setOut(new PrintStream(outputStreamCaptor)); + } + + @AfterEach + void tearDown() { + // This will be run after each test, cleaning up + Itemlist.getItems().clear(); // clear the list for next test + Promotionlist.getAllPromotion().clear(); + Storage.updateFile("", false); + PromotionStorage.updateFile("", false); + TransactionLogs.updateFile("", false); + } + + @Test + public void testExecuteEditItemNotFound() { + new EditCommand("NonExistentItem", "NewTestItem", -1, "NA", "NA", -1, -1).execute(); + String expectedOutput = "item not found!" + System.lineSeparator() + + "End of Edits" + System.lineSeparator() + System.lineSeparator(); + assertEquals(expectedOutput, outputStreamCaptor.toString()); + } + + @Test + public void testExecuteEditItemName() { + new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute(); + new EditCommand("TestItem", "NewTestItem", -1, "NA", "NA", -1, -1).execute(); + String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" + + System.lineSeparator() + "\n" + + "Edited: " + System.lineSeparator() + + "Name of TestItem from TestItem to NewTestItem" + System.lineSeparator() + + "End of Edits" + System.lineSeparator() + System.lineSeparator(); + assertEquals(expectedOutput, outputStreamCaptor.toString()); + } + + @Test + public void testExecuteEditQuantity() { + new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute(); + new EditCommand("TestItem", "NA", 50, "NA", "NA", -1, -1).execute(); + String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" + + System.lineSeparator() + "\n" + + "Edited: " + System.lineSeparator() + + "Quantity of TestItem from 10 to 50" + System.lineSeparator() + + "End of Edits" + System.lineSeparator() + System.lineSeparator(); + assertEquals(expectedOutput, outputStreamCaptor.toString()); + } + + @Test + public void testExecuteEditInvalidQuantity() { + new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute(); + new EditCommand("TestItem", "NA", -100, "NA", "NA", -1, -1).execute(); + String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" + + System.lineSeparator() + "\n" + + "Edited: " + System.lineSeparator() + + "Quantity of TestItem from 10 to -100" + System.lineSeparator() + + "End of Edits" + System.lineSeparator() + System.lineSeparator(); + assertEquals(expectedOutput, outputStreamCaptor.toString()); + } + + @Test + public void testExecuteEditUnitOfMeasurement() { + new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute(); + new EditCommand("TestItem", "NA", -1, "kg", "NA", -1, -1).execute(); + String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" + + System.lineSeparator() + "\n" + + "Edited: " + System.lineSeparator() + + "Unit of Measurement of TestItem from pcs to kg" + System.lineSeparator() + + "End of Edits" + System.lineSeparator() + System.lineSeparator(); + assertEquals(expectedOutput, outputStreamCaptor.toString()); + } + + @Test + public void testExecuteEditCategory() { + new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute(); + new EditCommand("TestItem", "NA", -1, "NA", "NewTestCategory", -1, -1).execute(); + String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" + + System.lineSeparator() + "\n" + + "Edited: " + System.lineSeparator() + + "Category of TestItem from TestCategory to NewTestCategory" + System.lineSeparator() + + "End of Edits" + System.lineSeparator() + System.lineSeparator(); + assertEquals(expectedOutput, outputStreamCaptor.toString()); + } + + @Test + public void testExecuteEditBuyPrice() { + new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute(); + new EditCommand("TestItem", "NA", -1, "NA", "NA", 6.0f, -1).execute(); + String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" + + System.lineSeparator() + "\n" + + "Edited: " + System.lineSeparator() + + "Buy Price of TestItem from 5.0 to 6.00" + System.lineSeparator() + + "End of Edits" + System.lineSeparator() + System.lineSeparator(); + assertEquals(expectedOutput, outputStreamCaptor.toString()); + } + + @Test + public void testExecuteEditSellPrice() { + new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute(); + new EditCommand("TestItem", "NA", -1, "NA", "NA", -1, 12.0f).execute(); + String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" + + System.lineSeparator() + "\n" + + "Edited: " + System.lineSeparator() + + "Sell Price of TestItem from 10.0 to 12.00" + System.lineSeparator() + + "End of Edits" + System.lineSeparator() + System.lineSeparator(); + assertEquals(expectedOutput, outputStreamCaptor.toString()); + } + + @Test + public void testExecuteEditMultipleAttributes() { + new AddCommand("TestItem", 10, "pcs", "TestCategory", 5.0f, 10.0f).execute(); + new EditCommand("TestItem", "NewTestItem", 50, "kg", "NewTestCategory", 6.0f, 12.0f).execute(); + String expectedOutput = "added: testitem (Qty: 10 pcs, Buy: $5.00, Sell: $10.00) to TestCategory" + + System.lineSeparator() + "\n" + + "Edited: " + System.lineSeparator() + + "Name of TestItem from TestItem to NewTestItem" + System.lineSeparator() + + "Quantity of TestItem from 10 to 50" + System.lineSeparator() + + "Unit of Measurement of TestItem from pcs to kg" + System.lineSeparator() + + "Category of TestItem from TestCategory to NewTestCategory" + System.lineSeparator() + + "Buy Price of TestItem from 5.0 to 6.00" + System.lineSeparator() + + "Sell Price of TestItem from 10.0 to 12.00" + System.lineSeparator() + + "End of Edits" + System.lineSeparator() + System.lineSeparator(); + assertEquals(expectedOutput, outputStreamCaptor.toString()); + } + +} diff --git a/src/test/java/item/ItemTest.java b/src/test/java/item/ItemTest.java new file mode 100644 index 0000000000..bd718cae5d --- /dev/null +++ b/src/test/java/item/ItemTest.java @@ -0,0 +1,84 @@ +package item; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ItemTest { + + private Item item; + + @BeforeEach + void setUp() { + // Initialize Item object before each test + item = new Item("Apple", 10, "Kg", "Fruit", 0.50f, 1.00f); + } + + @Test + void testItemCreation() { + assertNotNull(item, "Item should not be null after creation"); + assertEquals("Apple", item.getItemName(), "Check item name"); + assertEquals(10, item.getQuantity(), "Check quantity"); + assertEquals("Kg", item.getUnitOfMeasurement(), "Check unit of measurement"); + assertEquals("Fruit", item.getCategory(), "Check category"); + assertEquals(0.50f, item.getBuyPrice(), "Check buy price"); + assertEquals(1.00f, item.getSellPrice(), "Check sell price"); + assertFalse(item.getIsOOS(), "Item should not be out of stock"); + } + + @Test + void testSetItemName() { + item.setItemName("Banana"); + assertEquals("Banana", item.getItemName(), "Item name should be updated to Banana"); + } + + @Test + void testSetQuantity() { + item.setQuantity(20); + assertEquals(20, item.getQuantity(), "Quantity should be updated to 20"); + assertFalse(item.getIsOOS(), "Item should not be marked out of stock with quantity 20"); + + // Testing out of stock scenario + item.setQuantity(0); + assertEquals(0, item.getQuantity(), "Quantity should be updated to 0"); + assertTrue(item.getIsOOS(), "Item should be marked out of stock"); + } + + @Test + void testSetUnitOfMeasurement() { + item.setUnitOfMeasurement("Boxes"); + assertEquals("Boxes", item.getUnitOfMeasurement(), "Unit of measurement should be updated to Boxes"); + } + + @Test + void testSetCategory() { + item.setCategory("Snacks"); + assertEquals("Snacks", item.getCategory(), "Category should be updated to Snacks"); + } + + @Test + void testSetBuyPrice() { + item.setBuyPrice(0.75f); + assertEquals(0.75f, item.getBuyPrice(), "Buy price should be updated to 0.75"); + } + + @Test + void testSetSellPrice() { + item.setSellPrice(1.50f); + assertEquals(1.50f, item.getSellPrice(), "Sell price should be updated to 1.50"); + } + + @Test + void testMarkUnmarkItem() { + item.mark(); + assertTrue(item.getMarkStatus(), "Item should be marked"); + + item.unmark(); + assertFalse(item.getMarkStatus(), "Item should be unmarked"); + } +} + diff --git a/src/test/java/seedu/duke/StockMasterTest.java b/src/test/java/seedu/duke/StockMasterTest.java index 9e4f7147e0..1195625794 100644 --- a/src/test/java/seedu/duke/StockMasterTest.java +++ b/src/test/java/seedu/duke/StockMasterTest.java @@ -1,12 +1,17 @@ package seedu.duke; -import static org.junit.jupiter.api.Assertions.assertTrue; - +import exceptions.CommandFormatException; +import exceptions.EmptyListException; +import exceptions.InvalidDateException; import org.junit.jupiter.api.Test; -class StockMasterTest { + +import java.io.IOException; + +public class StockMasterTest { + @Test - public void sampleTest() { - assertTrue(true); + public void testStockMaster() throws CommandFormatException, InvalidDateException, IOException, EmptyListException { + StockMaster stockMaster = new StockMaster(); } }