Browse Source

Added: Get Count Of Stock + Basic Test

feature-pr/shop
Maxim Volkov 3 years ago
parent
commit
681a7a7f59
  1. 10
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Warehouse.java
  2. 18
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/WarehouseTest.java

10
projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Warehouse.java

@ -4,12 +4,16 @@ import java.util.HashMap;
public class Warehouse {
protected HashMap<String, Item> pool = new HashMap<String, Item>();
public Item insertItem(Item item) {
return pool.putIfAbsent(item.getTitel(), item);
}
public int getCountOfStock() {
int sumItems = 0;
for (HashMap.Entry<String, Item> set : pool.entrySet()) {
sumItems += set.getValue().getCurrentStock();
}
return sumItems;
}
}

18
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/WarehouseTest.java

@ -28,4 +28,22 @@ public class WarehouseTest extends TestCase {
// Then
assertEquals(expectedTitel, gotItem.getTitel());
}
public void test_growingCountOfItemsInWarehouse() {
// Given
Warehouse warehouse = new Warehouse();
int unitsPerItemType = 3;
int expectedSize = 13;
for(int i = 0; i < expectedSize; i++) {
Item item = new Item("ItemDummy" + i, "DescriptionDummy" + i, unitsPerItemType, 12.0f);
warehouse.insertItem(item);
}
int expectedSum = expectedSize * unitsPerItemType;
int actualSumOfAllItems = warehouse.getCountOfStock();
// Then
assertEquals(expectedSum, actualSumOfAllItems);
}
}
Loading…
Cancel
Save