Jenkins
3 years ago
8 changed files with 319 additions and 0 deletions
-
8projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java
-
25projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java
-
88projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java
-
28projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Warehouse.java
-
15projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java
-
89projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java
-
3projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java
-
63projjpn/src/test/java/de/hs_fulda/ciip/projjpn/WarehouseTest.java
@ -0,0 +1,88 @@ |
|||||
|
package de.hs_fulda.ciip.projjpn; |
||||
|
|
||||
|
public class Item { |
||||
|
|
||||
|
private String productTitle; |
||||
|
private String description; |
||||
|
private int availability = 0; |
||||
|
private float price; |
||||
|
|
||||
|
/** |
||||
|
* Creation of blank Item. |
||||
|
*/ |
||||
|
public Item() { |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Creation of Item. |
||||
|
* @param titel |
||||
|
* @param description |
||||
|
* @param quantity |
||||
|
* @param price |
||||
|
*/ |
||||
|
public Item(String titel, |
||||
|
String description, |
||||
|
int quantity, |
||||
|
float price) { |
||||
|
this.productTitle = titel; |
||||
|
this.description = description; |
||||
|
this.availability = quantity; |
||||
|
this.price = price; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @return true if at least one item is in stock. |
||||
|
*/ |
||||
|
public boolean inStock() { |
||||
|
return availability > 0; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @return current number of this items |
||||
|
*/ |
||||
|
public float getCurrentStock() { |
||||
|
return availability; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param newAmount of items |
||||
|
*/ |
||||
|
public void updateAvailability(int newAmount) { |
||||
|
availability = newAmount; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param newPrice of this item. |
||||
|
*/ |
||||
|
public void updatePrice(float newPrice) { |
||||
|
this.price = newPrice; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @return Current Price of the Item. |
||||
|
*/ |
||||
|
public float getCurrentPrice() { |
||||
|
return price; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @return Current public Title of this Item. |
||||
|
*/ |
||||
|
public String getTitel() { |
||||
|
return this.productTitle; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @return Current public Description of this Item. |
||||
|
*/ |
||||
|
public String getDescription() { |
||||
|
return this.description; |
||||
|
} |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
package de.hs_fulda.ciip.projjpn; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
|
||||
|
public class Warehouse { |
||||
|
protected HashMap<String, Item> pool = new HashMap<String, Item>(); |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param item Item to insert. |
||||
|
* @return the inserted Item or null. |
||||
|
*/ |
||||
|
public Item insertItem(Item item) { |
||||
|
return pool.putIfAbsent(item.getTitel(), item); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @return The total amount of all Items. |
||||
|
*/ |
||||
|
public int getCountOfStock() { |
||||
|
int sumItems = 0; |
||||
|
for (HashMap.Entry<String, Item> set : pool.entrySet()) { |
||||
|
sumItems += set.getValue().getCurrentStock(); |
||||
|
} |
||||
|
return sumItems; |
||||
|
} |
||||
|
} |
@ -0,0 +1,89 @@ |
|||||
|
package de.hs_fulda.ciip.projjpn; |
||||
|
|
||||
|
import junit.framework.TestCase; |
||||
|
|
||||
|
public class ItemTest extends TestCase { |
||||
|
/** |
||||
|
* No Items are in Stock. |
||||
|
* Check the inStock() Method. |
||||
|
*/ |
||||
|
public void test_ItemNotInStock() { |
||||
|
// Given |
||||
|
Item item = new Item(); |
||||
|
|
||||
|
// When |
||||
|
boolean notInStock = item.inStock(); |
||||
|
|
||||
|
// Then |
||||
|
assertFalse(notInStock); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Stock is not Empty. |
||||
|
* Check the inStock() Method. |
||||
|
*/ |
||||
|
public void test_ItemInStock() { |
||||
|
// Given |
||||
|
Item item = new Item(); |
||||
|
item.updateAvailability(1); |
||||
|
// When |
||||
|
boolean inStock = item.inStock(); |
||||
|
|
||||
|
// Then |
||||
|
assertTrue(inStock); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* One and the same type of an item costs the same. |
||||
|
* check getCurrentPrice() |
||||
|
*/ |
||||
|
public void test_priceOfMultipleIdenticalItems() { |
||||
|
// Given |
||||
|
Item item = new Item(); |
||||
|
int quantity = 3; |
||||
|
float price = 5; |
||||
|
item.updateAvailability(quantity); |
||||
|
item.updatePrice(price); |
||||
|
|
||||
|
// When |
||||
|
float expectedPrice = quantity * price; |
||||
|
|
||||
|
// Then |
||||
|
float actualPrice = 0; |
||||
|
for(int i = 0; i < quantity; i++) { |
||||
|
actualPrice += item.getCurrentPrice(); |
||||
|
} |
||||
|
|
||||
|
assertEquals(expectedPrice, actualPrice); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Check if creating a complete item with all attributes works as intended. |
||||
|
*/ |
||||
|
public void test_buildCompleteItem() { |
||||
|
// Given |
||||
|
String expectedTitel = "Logitec Maus"; |
||||
|
String expectedDescription = "Gaming Maus fuer Fortgeschrittene."; |
||||
|
int expectedQuantity = 10; |
||||
|
float expectedPrice = 69.99f; |
||||
|
|
||||
|
// When |
||||
|
Item itemNotNull = new Item(expectedTitel, expectedDescription, expectedQuantity, expectedPrice); |
||||
|
|
||||
|
// Then |
||||
|
assertNotNull(itemNotNull); |
||||
|
|
||||
|
// When |
||||
|
boolean validDescription = itemNotNull.getDescription().equals(expectedDescription); |
||||
|
assertTrue(validDescription); |
||||
|
|
||||
|
boolean validTitle = itemNotNull.getTitel().equals(expectedTitel); |
||||
|
assertTrue(validTitle); |
||||
|
|
||||
|
boolean validQuantity = itemNotNull.getCurrentStock() == expectedQuantity; |
||||
|
assertTrue(validQuantity); |
||||
|
|
||||
|
boolean validPrice = itemNotNull.getCurrentPrice() == expectedPrice; |
||||
|
assertTrue(validPrice); |
||||
|
} |
||||
|
} |
@ -0,0 +1,63 @@ |
|||||
|
package de.hs_fulda.ciip.projjpn; |
||||
|
|
||||
|
import junit.framework.TestCase; |
||||
|
|
||||
|
public class WarehouseTest extends TestCase { |
||||
|
/** |
||||
|
* Check if the insertion of an Item works properly. |
||||
|
*/ |
||||
|
public void test_insertItemInWarehouse() { |
||||
|
// Given |
||||
|
Warehouse warehouse = new Warehouse(); |
||||
|
|
||||
|
String expectedTitel = "Logitec Maus"; |
||||
|
String expectedDescription = "Gaming Maus fuer Fortgeschrittene."; |
||||
|
int expectedQuantity = 10; |
||||
|
float expectedPrice = 69.69f; |
||||
|
|
||||
|
// When |
||||
|
Item expectedItem = new Item(expectedTitel, expectedDescription, expectedQuantity, expectedPrice); |
||||
|
assertNotNull(expectedItem); |
||||
|
warehouse.insertItem(expectedItem); |
||||
|
|
||||
|
Item gotItem = warehouse.pool.get(expectedTitel); |
||||
|
|
||||
|
// Then |
||||
|
assertEquals(expectedTitel, gotItem.getTitel()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Test the total Sum of Items in the whole Warehouse. |
||||
|
*/ |
||||
|
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); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Empty Warehouse means there are a total of zero Items. |
||||
|
*/ |
||||
|
public void test_emptyWarehouse() { |
||||
|
// Given |
||||
|
Warehouse warehouse = new Warehouse(); |
||||
|
|
||||
|
// When |
||||
|
int expectedSum = 0; |
||||
|
|
||||
|
// Then |
||||
|
int actualSumOfAllItems = warehouse.getCountOfStock(); |
||||
|
assertEquals(expectedSum, actualSumOfAllItems); |
||||
|
|
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue