From 17c8a8833900b6375bc0cf7f8a874406d9c8d3ee Mon Sep 17 00:00:00 2001 From: Jakub Gruber <jakubgruber96@gmail.com> Date: Fri, 26 Oct 2018 16:18:36 +0200 Subject: [PATCH 1/3] ZKS JUnit test --- .../cz/cvut/eshop/storage/StorageTest.java | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 src/test/java/cz/cvut/eshop/storage/StorageTest.java diff --git a/src/test/java/cz/cvut/eshop/storage/StorageTest.java b/src/test/java/cz/cvut/eshop/storage/StorageTest.java new file mode 100644 index 0000000..9576616 --- /dev/null +++ b/src/test/java/cz/cvut/eshop/storage/StorageTest.java @@ -0,0 +1,156 @@ +package cz.cvut.eshop.storage; + +import cz.cvut.eshop.shop.Order; +import cz.cvut.eshop.shop.ShoppingCart; +import cz.cvut.eshop.shop.StandardItem; +import org.junit.Test; + +import java.util.Iterator; + +import static org.junit.Assert.*; + +public class StorageTest { + + @Test + public void getStockEntries_noEntries_shouldReturnEmptyCollection() { + Storage storage = new Storage(); + assertTrue(storage.getStockEntries().isEmpty()); + } + + @Test + public void getStockEntries_insertNewEntry_shouldReturnListWithOneEntry() { + Storage storage = new Storage(); + StandardItem item = new StandardItem(1, "apple", 1f, "food", 15); + storage.insertItems(item, 1); + + assertEquals(1, storage.getStockEntries().size()); + + Iterator<ItemStock> it = storage.getStockEntries().iterator(); + assertEquals(item.getID(), it.next().getItem().getID()); + assertFalse(it.hasNext()); + } + + @Test + public void getStockEntries_insertSameEntry_shouldIncreaseCount() { + Storage storage = new Storage(); + StandardItem item = new StandardItem(1, "apple", 1f, "food", 15); + storage.insertItems(item, 1); + storage.insertItems(item, 1); + + assertEquals(1, storage.getStockEntries().size()); + + Iterator<ItemStock> it = storage.getStockEntries().iterator(); + assertEquals(2, it.next().getCount()); + } + + @Test(expected = NoItemInStorage.class) + public void removeItems_noItems_shouldThrowException() throws NoItemInStorage { + Storage storage = new Storage(); + + StandardItem item = new StandardItem(1, "apple", 1f, "food", 15); + + storage.removeItems(item, 10); + } + + @Test(expected = NoItemInStorage.class) + public void removeItems_insertOneItem_removeTwoItems_shouldThrowException() throws NoItemInStorage { + Storage storage = new Storage(); + + StandardItem item = new StandardItem(1, "apple", 1f, "food", 15); + + storage.insertItems(item, 1); + + storage.removeItems(item, 2); + } + + @Test + public void removeItems_insertItem_removeItem_shouldDecreaseCount() throws NoItemInStorage { + Storage storage = new Storage(); + + StandardItem item = new StandardItem(1, "apple", 1f, "food", 15); + + storage.insertItems(item, 1); + storage.removeItems(item, 1); + + assertEquals(0, storage.getStockEntries().iterator().next().getCount()); + } + + @Test + public void processOrder_emptyShoppingCard_shouldJustRun() throws NoItemInStorage { + Order order = new Order(new ShoppingCart()); + new Storage().processOrder(order); + } + + @Test(expected = NoItemInStorage.class) + public void processOrder_itemNotInStorage_shouldThrowException() throws NoItemInStorage { + ShoppingCart cart = new ShoppingCart(); + cart.addItem(new StandardItem(1, "apple", 1f, "food", 15)); + Order order = new Order(cart); + new Storage().processOrder(order); + } + + @Test + public void getItemCount_noSuchItem_shouldReturnZero() { + Storage storage = new Storage(); + StandardItem item = new StandardItem(1, "apple", 1f, "food", 15); + storage.insertItems(item, 1); + + StandardItem unknownItem = new StandardItem(10, "apple", 1f, "food", 15); + + assertEquals(0, storage.getItemCount(unknownItem)); + } + + @Test + public void getItemCount_itemFound_shouldReturnNumberOfInsertedItems() { + Storage storage = new Storage(); + StandardItem item = new StandardItem(1, "apple", 1f, "food", 15); + storage.insertItems(item, 15); + + assertEquals(15, storage.getItemCount(item)); + } + + @Test + public void getItemCount_byId_noSuchItem_shouldReturnZero() { + Storage storage = new Storage(); + StandardItem item = new StandardItem(1, "apple", 1f, "food", 15); + storage.insertItems(item, 1); + + StandardItem unknownItem = new StandardItem(10, "apple", 1f, "food", 15); + + assertEquals(0, storage.getItemCount(unknownItem.getID())); + } + + @Test + public void getItemCount_byId_itemFound_shouldReturnNumberOfInsertedItems() { + Storage storage = new Storage(); + StandardItem item = new StandardItem(1, "apple", 1f, "food", 15); + storage.insertItems(item, 15); + + assertEquals(15, storage.getItemCount(item.getID())); + } + + @Test + public void getPriceOfWholeStock_emptyStack_shouldReturnZero() { + Storage storage = new Storage(); + + assertEquals(0, storage.getPriceOfWholeStock()); + } + + @Test + public void getPriceOfWholeStock_nonEmptyStack_shouldReturnSumOfPrices() { + Storage storage = new Storage(); + StandardItem item = new StandardItem(1, "apple", 55F, "food", 15); + + storage.insertItems(item, 1); + + assertEquals(55F, storage.getPriceOfWholeStock(), 0); + } + + @Test + public void getItemsOfCategorySortedByPrice_unknownCategory_shouldReturnEmptyColection() { + Storage storage = new Storage(); + assertTrue(storage.getItemsOfCategorySortedByPrice("unknown").isEmpty()); + + } + +} \ No newline at end of file -- GitLab From 5c751693185ce21acd678fa4258b9f4b7959a332 Mon Sep 17 00:00:00 2001 From: Jakub Gruber <jakubgruber96@gmail.com> Date: Fri, 26 Oct 2018 16:19:50 +0200 Subject: [PATCH 2/3] ZKS JUnit test - forgotten file --- .../cz/cvut/eshop/storage/ItemStockTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/java/cz/cvut/eshop/storage/ItemStockTest.java diff --git a/src/test/java/cz/cvut/eshop/storage/ItemStockTest.java b/src/test/java/cz/cvut/eshop/storage/ItemStockTest.java new file mode 100644 index 0000000..759f868 --- /dev/null +++ b/src/test/java/cz/cvut/eshop/storage/ItemStockTest.java @@ -0,0 +1,25 @@ +package cz.cvut.eshop.storage; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ItemStockTest { + + @Test + public void increaseItemCount() { + ItemStock itemStock = new ItemStock(null); + itemStock.IncreaseItemCount(10); + + assertEquals(10, itemStock.getCount()); + } + + @Test + public void decreaseItemCount() { + ItemStock itemStock = new ItemStock(null); + itemStock.decreaseItemCount(10); + + assertEquals(-10, itemStock.getCount()); + } + +} \ No newline at end of file -- GitLab From 7e92733e6525537ad7a86008a1b27c66f35bef6f Mon Sep 17 00:00:00 2001 From: Jakub Gruber <grubejak@fel.cvut.cz> Date: Fri, 26 Oct 2018 20:17:04 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1517fb7..35d53d1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -[![pipeline status](https://gitlab.fel.cvut.cz/frajtak/eShop/badges/master/pipeline.svg)](https://gitlab.fel.cvut.cz/frajtak/eShop/commits/master) +[![pipeline status](https://gitlab.fel.cvut.cz/grubejak/eShop/badges/master/pipeline.svg)](https://gitlab.fel.cvut.cz/grubejak/eShop/commits/master) -[![coverage report](https://gitlab.fel.cvut.cz/frajtak/eShop/badges/master/coverage.svg)](https://gitlab.fel.cvut.cz/frajtak/eShop/commits/master)frajtak \ No newline at end of file +[![coverage report](https://gitlab.fel.cvut.cz/grubejak/eShop/badges/master/coverage.svg)](https://gitlab.fel.cvut.cz/grubejak/eShop/commits/master) \ No newline at end of file -- GitLab