123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import static org.junit.Assert.*;
- import java.util.Arrays;
- import org.junit.Test;
- import org.junit.Before;
-
- public class InventoryTest {
- private static final int MAX_QUALITY = 50;
- private static final String AGED_BRIE_NAME = "Aged Brie";
- private static final String BACKSTAGE_PASS_NAME = "Backstage passes to a TAFKAL80ETC concert";
- private static final String NORMAL_ITEM_NAME = "+5 Dexterity Vest";
-
- private Item sulfuras;
- private Item normalItem;
-
- @Before
- public void setup(){
- sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
- normalItem = new Item(NORMAL_ITEM_NAME, 10, 20);
- }
-
- @Test
- public void testUpdate_ForSulfurasQuality() throws Exception {
- int expectedQuality = sulfuras.getQuality();
- Item[] items = {sulfuras};
- Inventory sut = new Inventory(items);
-
- sut.updateQuality();
-
- assertEquals(expectedQuality, sulfuras.getQuality());
- }
- @Test
- public void testUpdate_ForSulfurasSellIn() throws Exception {
- int expectedSellIn = sulfuras.getSellIn();
- Item[] items = {sulfuras};
- Inventory sut = new Inventory(items);
-
- sut.updateQuality();
-
- assertEquals(expectedSellIn, sulfuras.getSellIn());
- }
-
- @Test
- public void testUpdate_ForNormalItemSellIn() throws Exception {
- int expectedSellIn = normalItem.getSellIn() - 1;
- Item[] items = {normalItem};
- Inventory sut = new Inventory(items);
-
- sut.updateQuality();
-
- assertEquals(expectedSellIn, normalItem.getSellIn());
- }
-
- @Test
- public void testUpdate_ForNormalItemQuantity() throws Exception {
- int expectedQuality = normalItem.getQuality() - 1;
- Item[] items = {normalItem};
- Inventory sut = new Inventory(items);
-
- sut.updateQuality();
-
- assertEquals(expectedQuality, normalItem.getQuality());
- }
-
- @Test
- public void testUpdate_ForSoldOutItem() throws Exception {
- int minimumQuality = 0;
- Item normalItemWithMinimumQuality = new Item(NORMAL_ITEM_NAME, 10, minimumQuality);
- Item[] items = {normalItemWithMinimumQuality};
- Inventory sut = new Inventory(items);
-
- sut.updateQuality();
-
- assertEquals(minimumQuality, normalItemWithMinimumQuality.getQuality());
- }
-
- @Test
- public void testUpdate_ForNormalItemOnceTheSellInDatePassed() throws Exception {
- Item normalItemWithPassedSellDate = new Item(NORMAL_ITEM_NAME, -1, 25);
- int expectedQuality = normalItemWithPassedSellDate.getQuality() - 2;
- Item[] items = {normalItemWithPassedSellDate};
- Inventory sut = new Inventory(items);
-
- sut.updateQuality();
-
- assertEquals(expectedQuality, normalItemWithPassedSellDate.getQuality());
- }
-
- @Test
- public void testUpdate_AgedBrie() throws Exception {
- Item agedBrie = new Item(AGED_BRIE_NAME, 10, 25);
- int expectedQuality = agedBrie.getQuality() + 1;
- Item[] items = {agedBrie};
- Inventory sut = new Inventory(items);
-
- sut.updateQuality();
-
- assertEquals(expectedQuality, agedBrie.getQuality());
- }
-
- @Test
- public void testUpdate_WhenAgedBrieIsAtMaxQuality() throws Exception {
- Item agedBrie = new Item(AGED_BRIE_NAME, 10, MAX_QUALITY);
- Item[] items = {agedBrie};
- Inventory sut = new Inventory(items);
-
- sut.updateQuality();
-
- assertEquals(MAX_QUALITY, agedBrie.getQuality());
- }
-
- @Test
- public void testUpdate_WhenAgedBrieOnceTheSellInDatePassed() throws Exception {
- Item agedBrie = new Item(AGED_BRIE_NAME, -1, 20);
- int expectedQuality = agedBrie.getQuality() + 2;
- Item[] items = {agedBrie};
- Inventory sut = new Inventory(items);
-
- sut.updateQuality();
-
- assertEquals(expectedQuality, agedBrie.getQuality());
- }
- }
|