InventoryTest.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import static org.junit.Assert.*;
  2. import java.util.Arrays;
  3. import org.junit.Test;
  4. import org.junit.Before;
  5. public class InventoryTest {
  6. private static final int MAX_QUALITY = 50;
  7. private static final String AGED_BRIE_NAME = "Aged Brie";
  8. private static final String BACKSTAGE_PASS_NAME = "Backstage passes to a TAFKAL80ETC concert";
  9. private static final String NORMAL_ITEM_NAME = "+5 Dexterity Vest";
  10. private static final String CONJURED_ITEM_NAME = "Conjured Mage Water";
  11. private Item sulfuras;
  12. private Item normalItem;
  13. @Before
  14. public void setup(){
  15. sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
  16. normalItem = new Item(NORMAL_ITEM_NAME, 10, 20);
  17. }
  18. @Test
  19. public void testUpdate_ForSulfurasQuality() throws Exception {
  20. int expectedQuality = sulfuras.getQuality();
  21. Item[] items = {sulfuras};
  22. Inventory sut = new Inventory(items);
  23. sut.updateQuality();
  24. assertEquals(expectedQuality, sulfuras.getQuality());
  25. }
  26. @Test
  27. public void testUpdate_ForSulfurasSellIn() throws Exception {
  28. int expectedSellIn = sulfuras.getSellIn();
  29. Item[] items = {sulfuras};
  30. Inventory sut = new Inventory(items);
  31. sut.updateQuality();
  32. assertEquals(expectedSellIn, sulfuras.getSellIn());
  33. }
  34. @Test
  35. public void testUpdate_ForNormalItemSellIn() throws Exception {
  36. int expectedSellIn = normalItem.getSellIn() - 1;
  37. Item[] items = {normalItem};
  38. Inventory sut = new Inventory(items);
  39. sut.updateQuality();
  40. assertEquals(expectedSellIn, normalItem.getSellIn());
  41. }
  42. @Test
  43. public void testUpdate_ForNormalItemQuantity() throws Exception {
  44. int expectedQuality = normalItem.getQuality() - 1;
  45. Item[] items = {normalItem};
  46. Inventory sut = new Inventory(items);
  47. sut.updateQuality();
  48. assertEquals(expectedQuality, normalItem.getQuality());
  49. }
  50. @Test
  51. public void testUpdate_ForSoldOutItem() throws Exception {
  52. int minimumQuality = 0;
  53. Item normalItemWithMinimumQuality = new Item(NORMAL_ITEM_NAME, 10, minimumQuality);
  54. Item[] items = {normalItemWithMinimumQuality};
  55. Inventory sut = new Inventory(items);
  56. sut.updateQuality();
  57. assertEquals(minimumQuality, normalItemWithMinimumQuality.getQuality());
  58. }
  59. @Test
  60. public void testUpdate_ForNormalItemOnceTheSellInDatePassed() throws Exception {
  61. Item normalItemWithPassedSellDate = new Item(NORMAL_ITEM_NAME, -1, 25);
  62. int expectedQuality = normalItemWithPassedSellDate.getQuality() - 2;
  63. Item[] items = {normalItemWithPassedSellDate};
  64. Inventory sut = new Inventory(items);
  65. sut.updateQuality();
  66. assertEquals(expectedQuality, normalItemWithPassedSellDate.getQuality());
  67. }
  68. @Test
  69. public void testUpdate_AgedBrie() throws Exception {
  70. Item agedBrie = new Item(AGED_BRIE_NAME, 10, 25);
  71. int expectedQuality = agedBrie.getQuality() + 1;
  72. Item[] items = {agedBrie};
  73. Inventory sut = new Inventory(items);
  74. sut.updateQuality();
  75. assertEquals(expectedQuality, agedBrie.getQuality());
  76. }
  77. @Test
  78. public void testUpdate_WhenAgedBrieIsAtMaxQuality() throws Exception {
  79. Item agedBrie = new Item(AGED_BRIE_NAME, 10, MAX_QUALITY);
  80. Item[] items = {agedBrie};
  81. Inventory sut = new Inventory(items);
  82. sut.updateQuality();
  83. assertEquals(MAX_QUALITY , agedBrie.getQuality());
  84. }
  85. @Test
  86. public void testUpdate_WhenAgedBrieOnceTheSellInDatePassed() throws Exception {
  87. Item agedBrie = new Item(AGED_BRIE_NAME, -1, 20);
  88. int expectedQuality = agedBrie.getQuality() + 2;
  89. Item[] items = {agedBrie};
  90. Inventory sut = new Inventory(items);
  91. sut.updateQuality();
  92. assertEquals(expectedQuality, agedBrie.getQuality());
  93. }
  94. @Test
  95. public void testUpdate_ConjuredItem() throws Exception {
  96. Item conjuredMageWater = new Item(CONJURED_ITEM_NAME, 10, 25);
  97. int expectedQuality = conjuredMageWater.getQuality() -2 ;
  98. Item[] items = {conjuredMageWater};
  99. Inventory sut = new Inventory(items);
  100. sut.updateQuality();
  101. assertEquals(expectedQuality, conjuredMageWater.getQuality());
  102. }
  103. @Test
  104. public void testUpdate_WhenConjuredItemIsAtMaxQuality() throws Exception {
  105. Item conjuredMageWater = new Item(CONJURED_ITEM_NAME, 10, MAX_QUALITY);
  106. Item[] items = {conjuredMageWater};
  107. Inventory sut = new Inventory(items);
  108. sut.updateQuality();
  109. assertEquals(MAX_QUALITY - 2, conjuredMageWater.getQuality());
  110. }
  111. @Test
  112. public void testUpdate_WhenConjuredItemOnceTheSellInDatePassed() throws Exception {
  113. Item conjuredMageWater = new Item(CONJURED_ITEM_NAME, -1, 20);
  114. int expectedQuality = conjuredMageWater.getQuality() - 4;
  115. Item[] items = {conjuredMageWater};
  116. Inventory sut = new Inventory(items);
  117. sut.updateQuality();
  118. assertEquals(expectedQuality, conjuredMageWater.getQuality());
  119. }
  120. }