Browse Source

Added: Price Of Multiple Identical Items Test

feature-pr/shop
Maxim Volkov 3 years ago
parent
commit
b772bac368
  1. 12
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java
  2. 21
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java

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

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

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

@ -24,4 +24,25 @@ public class ItemTest extends TestCase {
// Then // Then
assertTrue(inStock); 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