Skip to content

Commit

Permalink
Merge pull request #37 from imanamirshah/JUnitTest-Add
Browse files Browse the repository at this point in the history
Add JUnit test for addItem
  • Loading branch information
nur-haziq authored Mar 14, 2024
2 parents 7b38eb3 + ebb6e16 commit 8928a9e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/java/seedu/binbash/ItemListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,25 @@ void deleteItem_oneItemInItemList_noItemInItemList() {

assertEquals(0, itemList.getItemCount());
}

@Test
void addItem_noItemInItemList_oneItemInItemList() {
ItemList itemList = new ItemList();

itemList.addItem("testItem", "A test item");
assertEquals(1, itemList.getItemCount());
}

@Test
void addItem_itemNameAndDescription_correctItemNameAndDescription() {
ItemList itemList = new ItemList();

itemList.addItem("testItem", "A test item");
Item item = itemList.getItemList().get(0);

assertEquals(item.getItemName(), "testItem");
assertEquals(item.getItemDescription(), "A test item");
}


}
18 changes: 18 additions & 0 deletions src/test/java/seedu/binbash/command/AddCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package seedu.binbash.command;

import org.junit.jupiter.api.Test;
import seedu.binbash.ItemList;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AddCommandTest {

@Test
void execute_item_oneItemInItemList() {
ItemList itemList = new ItemList();
AddCommand addCommand = new AddCommand(itemList, "testItem", "A test item");

addCommand.execute();
assertEquals(1, itemList.getItemCount());
}
}

0 comments on commit 8928a9e

Please sign in to comment.