InventoryTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import static org.junit.Assert.*;
  2. import java.util.Arrays;
  3. import org.junit.Test;
  4. public class InventoryTest {
  5. @Test
  6. public void should_never_changes_quailty_of_Sulfuras() throws Exception {
  7. Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
  8. Inventory sut = new Inventory((Item[]) Arrays.asList(new Item("Sulfuras, Hand of Ragnaros", 0, 80)).toArray());
  9. sut.updateQuality();
  10. assertEquals(80, sulfuras.getQuality());
  11. }
  12. @Test
  13. public void should_never_changes_sellIn_of_Sulfuras() throws Exception {
  14. Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
  15. Inventory sut = new Inventory((Item[]) Arrays.asList(sulfuras).toArray());
  16. sut.updateQuality();
  17. assertEquals(0, sulfuras.getSellIn());
  18. }
  19. @Test
  20. public void should_lower_the_sellIn_by_one_for_normal_items() throws Exception {
  21. Item normalItem = new Item("+5 Dexterity Vest", 10, 20);
  22. Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
  23. sut.updateQuality();
  24. assertEquals(9, normalItem.getSellIn());
  25. }
  26. @Test
  27. public void should_lower_the_quality_by_one_for_normal_items() throws Exception {
  28. Item normalItem = new Item("+5 Dexterity Vest", 10, 20);
  29. Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
  30. sut.updateQuality();
  31. assertEquals(19, normalItem.getQuality());
  32. }
  33. @Test
  34. public void should_not_lower_the_quality_below_zero() throws Exception {
  35. Item normalItem = new Item("+5 Dexterity Vest", 10, 0);
  36. Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
  37. sut.updateQuality();
  38. assertEquals(0, normalItem.getQuality());
  39. }
  40. @Test
  41. public void should_lower_the_quality_twice_as_fast_once_the_sell_in_date_has_passed() throws Exception {
  42. Item normalItem = new Item("+5 Dexterity Vest", -1, 25);
  43. Inventory sut = new Inventory((Item[]) Arrays.asList(normalItem).toArray());
  44. sut.updateQuality();
  45. assertEquals(23, normalItem.getQuality());
  46. }
  47. @Test
  48. public void should_increase_the_quality_of_aged_brie_as_it_gets_older() throws Exception {
  49. Item agedBrie = new Item("Aged Brie", 10, 25);
  50. Inventory sut = new Inventory((Item[]) Arrays.asList(agedBrie).toArray());
  51. sut.updateQuality();
  52. assertEquals(26, agedBrie.getQuality());
  53. }
  54. @Test
  55. public void should_not_increase_the_quality_of_aged_brie_over_50() throws Exception {
  56. Item agedBrie = new Item("Aged Brie", 10, 50);
  57. Inventory sut = new Inventory((Item[]) Arrays.asList(agedBrie).toArray());
  58. sut.updateQuality();
  59. assertEquals(50, agedBrie.getQuality());
  60. }
  61. @Test
  62. public void should_lower_backstage_passes_to_zero_quality_once_concert_has_happened() throws Exception {
  63. Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", -1, 20);
  64. Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
  65. sut.updateQuality();
  66. assertEquals(0, backStagePass.getQuality());
  67. }
  68. @Test
  69. public void should_increase_backstage_passes_quality_by_1_when_the_concert_is_more_than_10_days_away() throws Exception {
  70. Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", 11, 20);
  71. Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
  72. sut.updateQuality();
  73. assertEquals(21, backStagePass.getQuality());
  74. }
  75. @Test
  76. public void should_increase_backstage_passes_quality_by_2_when_the_concert_is_10_days_or_less_away() throws Exception {
  77. Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", 10, 27);
  78. Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
  79. sut.updateQuality();
  80. assertEquals(29, backStagePass.getQuality());
  81. }
  82. @Test
  83. public void should_increase_backstage_passes_quality_by_3_when_the_concert_is_5_days_or_less_away() throws Exception {
  84. Item backStagePass = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 44);
  85. Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePass).toArray());
  86. sut.updateQuality();
  87. assertEquals(47, backStagePass.getQuality());
  88. }
  89. @Test
  90. public void should_not_increase_backstage_passes_above_a_quality_of_50() throws Exception {
  91. Item backStagePassMoreThan10DaysAway = new Item("Backstage passes to a TAFKAL80ETC concert", 15, 50);
  92. Item backStagePass10DaysAway = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49);
  93. Item backStagePass5DaysAway = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 48);
  94. Inventory sut = new Inventory((Item[]) Arrays.asList(backStagePassMoreThan10DaysAway, backStagePass10DaysAway, backStagePass5DaysAway).toArray());
  95. sut.updateQuality();
  96. assertEquals(50, backStagePassMoreThan10DaysAway.getQuality());
  97. assertEquals(50, backStagePass10DaysAway.getQuality());
  98. assertEquals(50, backStagePass5DaysAway.getQuality());
  99. }
  100. }