|
@ -3,6 +3,10 @@ package de.hs_fulda.ciip.projjpn; |
|
|
import junit.framework.TestCase; |
|
|
import junit.framework.TestCase; |
|
|
|
|
|
|
|
|
public class ItemTest extends TestCase { |
|
|
public class ItemTest extends TestCase { |
|
|
|
|
|
/** |
|
|
|
|
|
* No Items are in Stock. |
|
|
|
|
|
* Check the inStock() Method. |
|
|
|
|
|
*/ |
|
|
public void test_ItemNotInStock() { |
|
|
public void test_ItemNotInStock() { |
|
|
// Given |
|
|
// Given |
|
|
Item item = new Item(); |
|
|
Item item = new Item(); |
|
@ -14,6 +18,10 @@ public class ItemTest extends TestCase { |
|
|
assertFalse(notInStock); |
|
|
assertFalse(notInStock); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Stock is not Empty. |
|
|
|
|
|
* Check the inStock() Method. |
|
|
|
|
|
*/ |
|
|
public void test_ItemInStock() { |
|
|
public void test_ItemInStock() { |
|
|
// Given |
|
|
// Given |
|
|
Item item = new Item(); |
|
|
Item item = new Item(); |
|
@ -25,24 +33,57 @@ public class ItemTest extends TestCase { |
|
|
assertTrue(inStock); |
|
|
assertTrue(inStock); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* One and the same type of an item costs the same. |
|
|
|
|
|
* check getCurrentPrice() |
|
|
|
|
|
*/ |
|
|
public void test_priceOfMultipleIdenticalItems() { |
|
|
public void test_priceOfMultipleIdenticalItems() { |
|
|
// Given |
|
|
// Given |
|
|
Item item = new Item(); |
|
|
Item item = new Item(); |
|
|
int quantity = 3; |
|
|
int quantity = 3; |
|
|
int price = 5; |
|
|
|
|
|
|
|
|
float price = 5; |
|
|
item.updateAvailability(quantity); |
|
|
item.updateAvailability(quantity); |
|
|
item.updatePrice(price); |
|
|
item.updatePrice(price); |
|
|
|
|
|
|
|
|
// When |
|
|
// When |
|
|
int expectedPrice = quantity * price; |
|
|
|
|
|
|
|
|
float expectedPrice = quantity * price; |
|
|
|
|
|
|
|
|
// Then |
|
|
// Then |
|
|
int actualPrice = 0; |
|
|
|
|
|
|
|
|
float actualPrice = 0; |
|
|
for(int i = 0; i < quantity; i++) { |
|
|
for(int i = 0; i < quantity; i++) { |
|
|
actualPrice += item.getCurrentPrice(); |
|
|
actualPrice += item.getCurrentPrice(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedPrice, actualPrice); |
|
|
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); |
|
|
|
|
|
} |
|
|
} |
|
|
} |