You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.0 KiB

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);
}
}