3 Commits

  1. 27
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java
  2. 48
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java

27
projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java

@ -0,0 +1,27 @@
package de.hs_fulda.ciip.projjpn;
public class Item {
private int price;
// customerReview
// productTitle
// description
// tags
private int availability = 0;
public boolean inStock() {
return availability > 0;
}
public void updateAvailability(int newAmount) {
availability = newAmount;
}
public void updatePrice(int price) {
this.price = price;
}
public int getCurrentPrice() {
return price;
}
}

48
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java

@ -0,0 +1,48 @@
package de.hs_fulda.ciip.projjpn;
import junit.framework.TestCase;
public class ItemTest extends TestCase {
public void test_ItemNotInStock() {
// Given
Item item = new Item();
// When
boolean notInStock = item.inStock();
// Then
assertFalse(notInStock);
}
public void test_ItemInStock() {
// Given
Item item = new Item();
item.updateAvailability(1);
// When
boolean inStock = item.inStock();
// 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);
}
}
Loading…
Cancel
Save