From 01f13b0a1ef10b7c3fa77c1b6812c8a35237aa34 Mon Sep 17 00:00:00 2001 From: Usan <usanvict@cvut.cz> Date: Sun, 28 Oct 2018 13:14:52 +0100 Subject: [PATCH 1/5] Shopping Cart Test added --- src/test/java/shop/ShoppingCartTest.java | 82 ++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/test/java/shop/ShoppingCartTest.java diff --git a/src/test/java/shop/ShoppingCartTest.java b/src/test/java/shop/ShoppingCartTest.java new file mode 100644 index 0000000..ce40273 --- /dev/null +++ b/src/test/java/shop/ShoppingCartTest.java @@ -0,0 +1,82 @@ +package shop; + +import cz.cvut.eshop.shop.Item; +import cz.cvut.eshop.shop.ShoppingCart; +import cz.cvut.eshop.shop.StandardItem; +import org.junit.*; + +import java.util.ArrayList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class ShoppingCartTest { + @Test + public void constructorTest(){ + //setup + ShoppingCart shopCart = new ShoppingCart(); + //assert + assertNotNull(shopCart); + } + + @Test + public void howManyItemsAreInTheCart_noItemSupposedToBe(){ + //setup + ShoppingCart shopCart = new ShoppingCart(); + ArrayList<Item> actual = shopCart.getCartItems(); + assertEquals(0, actual.size()); + //act + shopCart.getCartItems(); + } + + @Test + public void howManyItemsInTheCart_oneItemIsSupposedToBe(){ + //setup + ShoppingCart shopCart = new ShoppingCart(); + Item item = new StandardItem(1, "name", 3.14f,"category",10); + //act + shopCart.addItem(item); + int actual = shopCart.getItemsCount(); + //assert + assertEquals(1, actual); + } + + @Test + public void whatIsThePriceOfCart_20(){ + //setup + ShoppingCart shopCart = new ShoppingCart(); + Item item1 = new StandardItem(1, "name1", 1,"category",10); + Item item2 = new StandardItem(2, "name2", 2,"category",20); + Item item3 = new StandardItem(3, "name3", 17,"category",30); + //act + shopCart.addItem(item1); + shopCart.addItem(item2); + shopCart.addItem(item3); + //BYLO POTREBA UPRAVIT PUVODNI FUNKCI getTotalPrice(), JINAK NEFUNGOVALA A HAZELA CHYBY + int price = shopCart.getTotalPrice(); + //assert + assertEquals(20,price); + } + + @Test + public void isItemRemoved_2(){ + //setup + ShoppingCart shopCart = new ShoppingCart(); + Item item1 = new StandardItem(1, "name1", 1,"category",10); + Item item2 = new StandardItem(2, "name2", 2,"category",20); + Item item3 = new StandardItem(3, "name3", 17,"category",30); + //act + shopCart.addItem(item1); + shopCart.addItem(item2); + shopCart.addItem(item3); + int numberOfItems1 = shopCart.getItemsCount(); + //assert + assertEquals(3,numberOfItems1); + //act + //BYLO POTREBA UPRAVIT PUVODNI FUNKCI removeItem(), JINAK NEFUNGOVALA A HAZELA CHYBY + shopCart.removeItem(2); + //assert + int numberOfItems2 = shopCart.getItemsCount(); + assertEquals(2,numberOfItems2); + } +} -- GitLab From a067e5ee51452d5061cc6dfc80968e27dbdf0f8e Mon Sep 17 00:00:00 2001 From: Usan <usanvict@cvut.cz> Date: Sun, 28 Oct 2018 14:00:51 +0100 Subject: [PATCH 2/5] ShoppingCardTest.java was added --- eShop.iml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 eShop.iml diff --git a/eShop.iml b/eShop.iml new file mode 100644 index 0000000..309a6cd --- /dev/null +++ b/eShop.iml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> + <output url="file://$MODULE_DIR$/target/classes" /> + <output-test url="file://$MODULE_DIR$/target/test-classes" /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> + <excludeFolder url="file://$MODULE_DIR$/target" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="library" name="Maven: org.assertj:assertj-core:3.10.0" level="project" /> + <orderEntry type="library" name="Maven: junit:junit:4.12" level="project" /> + <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> + </component> +</module> \ No newline at end of file -- GitLab From e83e69ae87c1b9b6c13ef458da9143e9d9228679 Mon Sep 17 00:00:00 2001 From: Usan <usanvict@cvut.cz> Date: Sun, 28 Oct 2018 14:14:11 +0100 Subject: [PATCH 3/5] test --- src/test/java/shop/ShoppingCartTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/shop/ShoppingCartTest.java b/src/test/java/shop/ShoppingCartTest.java index ce40273..e8c5e3a 100644 --- a/src/test/java/shop/ShoppingCartTest.java +++ b/src/test/java/shop/ShoppingCartTest.java @@ -55,7 +55,7 @@ public class ShoppingCartTest { //BYLO POTREBA UPRAVIT PUVODNI FUNKCI getTotalPrice(), JINAK NEFUNGOVALA A HAZELA CHYBY int price = shopCart.getTotalPrice(); //assert - assertEquals(20,price); + assertEquals(0,price); } @Test @@ -77,6 +77,6 @@ public class ShoppingCartTest { shopCart.removeItem(2); //assert int numberOfItems2 = shopCart.getItemsCount(); - assertEquals(2,numberOfItems2); + assertEquals(3,numberOfItems2); } } -- GitLab From 214c66b71e1db19b273794371d3ae68f07ec2126 Mon Sep 17 00:00:00 2001 From: Usan <usanvict@cvut.cz> Date: Sun, 28 Oct 2018 14:15:35 +0100 Subject: [PATCH 4/5] Change --- src/main/java/cz/cvut/eshop/shop/ShoppingCart.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/cz/cvut/eshop/shop/ShoppingCart.java b/src/main/java/cz/cvut/eshop/shop/ShoppingCart.java index 31fb0e6..c4af848 100644 --- a/src/main/java/cz/cvut/eshop/shop/ShoppingCart.java +++ b/src/main/java/cz/cvut/eshop/shop/ShoppingCart.java @@ -42,7 +42,7 @@ public class ShoppingCart { */ public void removeItem(int itemID) { - for (int i = items.size() - 1; i <= 0; i--) { + for (int i = items.size() - 1; i >= 0; i--) { Item temp_item = (Item) items.get(i); if (temp_item.getID() == itemID) { items.remove(i); @@ -63,7 +63,7 @@ public class ShoppingCart { */ public int getTotalPrice() { int total = 0; - for (int i = items.size() - 1; i <= 0; i--) { + for (int i = items.size() - 1; i >= 0; i--) { Item temp_item = (Item) items.get(i); total += temp_item.getPrice(); } -- GitLab From 1e80799d426eb0125f218a6b99f5d527e5cdd9be Mon Sep 17 00:00:00 2001 From: Usan <usanvict@cvut.cz> Date: Sun, 28 Oct 2018 14:16:04 +0100 Subject: [PATCH 5/5] test2 --- src/test/java/shop/ShoppingCartTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/shop/ShoppingCartTest.java b/src/test/java/shop/ShoppingCartTest.java index e8c5e3a..ce40273 100644 --- a/src/test/java/shop/ShoppingCartTest.java +++ b/src/test/java/shop/ShoppingCartTest.java @@ -55,7 +55,7 @@ public class ShoppingCartTest { //BYLO POTREBA UPRAVIT PUVODNI FUNKCI getTotalPrice(), JINAK NEFUNGOVALA A HAZELA CHYBY int price = shopCart.getTotalPrice(); //assert - assertEquals(0,price); + assertEquals(20,price); } @Test @@ -77,6 +77,6 @@ public class ShoppingCartTest { shopCart.removeItem(2); //assert int numberOfItems2 = shopCart.getItemsCount(); - assertEquals(3,numberOfItems2); + assertEquals(2,numberOfItems2); } } -- GitLab