InventoryTest.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 Holy Water";
  11. private static final int minimumQuality = 0;
  12. private Item sulfuras;
  13. private Item normalItem;
  14. private Item conjuredItem;
  15. @Before
  16. public void setup(){
  17. sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
  18. normalItem = new Item(NORMAL_ITEM_NAME, 10, 20);
  19. conjuredItem = new Item(CONJURED_ITEM_NAME, 10, MAX_QUALITY);
  20. }
  21. @Test
  22. public void testUpdate_ForSulfurasQuality() throws Exception {
  23. int expectedQuality = sulfuras.getQuality();
  24. Item[] items = {sulfuras};
  25. Inventory sut = new Inventory(items);
  26. sut.updateQuality();
  27. assertEquals(expectedQuality, sulfuras.getQuality());
  28. }
  29. @Test
  30. public void testUpdate_ForSulfurasSellIn() throws Exception {
  31. int expectedSellIn = sulfuras.getSellIn();
  32. Item[] items = {sulfuras};
  33. Inventory sut = new Inventory(items);
  34. sut.updateQuality();
  35. assertEquals(expectedSellIn, sulfuras.getSellIn());
  36. }
  37. @Test
  38. public void testUpdate_ForNormalItemSellIn() throws Exception {
  39. int expectedSellIn = normalItem.getSellIn() - 1;
  40. Item[] items = {normalItem};
  41. Inventory sut = new Inventory(items);
  42. sut.updateQuality();
  43. assertEquals(expectedSellIn, normalItem.getSellIn());
  44. }
  45. @Test
  46. public void testUpdate_ForNormalItemQuantity() throws Exception {
  47. int expectedQuality = normalItem.getQuality() - 1;
  48. Item[] items = {normalItem};
  49. Inventory sut = new Inventory(items);
  50. sut.updateQuality();
  51. assertEquals(expectedQuality, normalItem.getQuality());
  52. }
  53. @Test
  54. public void testUpdate_ForSoldOutItem() throws Exception {
  55. int minimumQuality = 0;
  56. Item normalItemWithMinimumQuality = new Item(NORMAL_ITEM_NAME, 10, minimumQuality);
  57. Item[] items = {normalItemWithMinimumQuality};
  58. Inventory sut = new Inventory(items);
  59. sut.updateQuality();
  60. assertEquals(minimumQuality, normalItemWithMinimumQuality.getQuality());
  61. }
  62. @Test
  63. public void testUpdate_ForNormalItemOnceTheSellInDatePassed() throws Exception {
  64. Item normalItemWithPassedSellDate = new Item(NORMAL_ITEM_NAME, -1, 25);
  65. int expectedQuality = normalItemWithPassedSellDate.getQuality() - 2;
  66. Item[] items = {normalItemWithPassedSellDate};
  67. Inventory sut = new Inventory(items);
  68. sut.updateQuality();
  69. assertEquals(expectedQuality, normalItemWithPassedSellDate.getQuality());
  70. }
  71. @Test
  72. public void testUpdate_AgedBrie() throws Exception {
  73. Item agedBrie = new Item(AGED_BRIE_NAME, 10, 25);
  74. int expectedQuality = agedBrie.getQuality() + 1;
  75. Item[] items = {agedBrie};
  76. Inventory sut = new Inventory(items);
  77. sut.updateQuality();
  78. assertEquals(expectedQuality, agedBrie.getQuality());
  79. }
  80. @Test
  81. public void testUpdate_WhenAgedBrieIsAtMaxQuality() throws Exception {
  82. Item agedBrie = new Item(AGED_BRIE_NAME, 10, MAX_QUALITY);
  83. Item[] items = {agedBrie};
  84. Inventory sut = new Inventory(items);
  85. sut.updateQuality();
  86. assertEquals(MAX_QUALITY, agedBrie.getQuality());
  87. }
  88. @Test
  89. public void testUpdate_WhenAgedBrieOnceTheSellInDatePassed() throws Exception {
  90. Item agedBrie = new Item(AGED_BRIE_NAME, -1, 20);
  91. int expectedQuality = agedBrie.getQuality() + 2;
  92. Item[] items = {agedBrie};
  93. Inventory sut = new Inventory(items);
  94. sut.updateQuality();
  95. assertEquals(expectedQuality, agedBrie.getQuality());
  96. }
  97. @Test
  98. public void testUpdate_WhenConjuredItem() throws Exception {
  99. Item conjuredItem = new Item(CONJURED_ITEM_NAME, 10, 25);
  100. int expectedQuality = conjuredItem.getQuality() - 1;
  101. Item[] items = {conjuredItem};
  102. Inventory sut = new Inventory(items);
  103. sut.updateQuality();
  104. assertEquals(expectedQuality, conjuredItem.getQuality());
  105. }
  106. @Test
  107. public void testUpdate_WhenConjuredItemIsMaxQuality() throws Exception {
  108. Item agedBrie = new Item(CONJURED_ITEM_NAME, 10, MAX_QUALITY);
  109. int expectedQuality = conjuredItem.getQuality();
  110. Item[] items = {conjuredItem};
  111. Inventory sut = new Inventory(items);
  112. sut.updateQuality();
  113. assertEquals(expectedQuality, conjuredItem.getQuality());
  114. }
  115. @Test
  116. public void testUpdate_WhenConjuredItemOnceTheSellInDatePassed() throws Exception {
  117. Item conjuredItem = new Item(CONJURED_ITEM_NAME, -1, 10);
  118. int expectedQuality = conjuredItem.getQuality() - 2;
  119. Item[] items = {conjuredItem};
  120. Inventory sut = new Inventory(items);
  121. sut.updateQuality();
  122. assertEquals(expectedQuality, conjuredItem.getQuality());
  123. }
  124. }