From b772bac368e3f347cfc165d5eb901ac1afb158ac Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 16:45:08 +0100 Subject: [PATCH] Added: Price Of Multiple Identical Items Test --- .../java/de/hs_fulda/ciip/projjpn/Item.java | 12 +++++++++-- .../de/hs_fulda/ciip/projjpn/ItemTest.java | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java index 44fc02d..c92998d 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java @@ -2,12 +2,12 @@ package de.hs_fulda.ciip.projjpn; public class Item { - // price + private int price; // customerReview // productTitle // description // tags - int availability = 0; + private int availability = 0; public boolean inStock() { return availability > 0; @@ -16,4 +16,12 @@ public class Item { public void updateAvailability(int newAmount) { availability = newAmount; } + + public void updatePrice(int price) { + this.price = price; + } + + public int getCurrentPrice() { + return price; + } } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java index 1ba1359..d06afe2 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java @@ -24,4 +24,25 @@ public class ItemTest extends TestCase { // Then assertTrue(inStock); } + + public void test_priceOfMultipleIdenticalItems() { + // Given + Item item = new Item(); + int quantity = 3; + int price = 5; + item.updateAvailability(quantity); + item.updatePrice(price); + + // When + int expectedPrice = quantity * price; + + // Then + int actualPrice = 0; + for(int i = 0; i < quantity; i++) { + actualPrice += item.getCurrentPrice(); + } + + + assertEquals(expectedPrice, actualPrice); + } }