Refactor normal item test cases to add messages

This commit is contained in:
Behnam Nikbakht 2023-08-09 08:19:12 -06:00
parent 4f26d09fa3
commit c2f198d9a9

View File

@ -3,6 +3,7 @@ package com.gildedrose;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
class GildedRoseTest { class GildedRoseTest {
@ -31,12 +32,12 @@ class GildedRoseTest {
@Test @Test
public void testNormalItemQualityAndSellInDecrease() { public void testNormalItemQualityAndSellInDecrease() {
app.updateQuality(); app.updateQuality();
assertEquals(19, items[0].quality); assertEquals(19, items[0].quality, "After first day: Normal Quality should decrease by 1");
assertEquals(9, items[0].sellIn); assertEquals(9, items[0].sellIn, "After first day: Normal SellIn should decrease by 1");
app.updateQuality(); app.updateQuality();
assertEquals(18, items[0].quality); assertEquals(18, items[0].quality, "After second day: Normal Quality should decrease by 2");
assertEquals(8, items[0].sellIn); assertEquals(8, items[0].sellIn, "After second day: Normal SellIn should decrease by 2");
} }
// The Quality of an item is never negative, quality of a normal item is decreasing each day // The Quality of an item is never negative, quality of a normal item is decreasing each day
@ -45,22 +46,19 @@ class GildedRoseTest {
for(int i=0; i<10; i++) { for(int i=0; i<10; i++) {
app.updateQuality(); app.updateQuality();
} }
assertEquals(0, items[2].quality); assertTrue(items[2].quality > -1, "Normal Quality should never be negative");
} }
// Once the sell by date has passed, Quality degrades twice as fast // Once the sell by date has passed, Quality degrades twice as fast
@Test @Test
public void testQualityDegradesTwiceAfterSellPassed() { public void testQualityDegradesTwiceAfterSellPassed() {
for(int i=0; i<10; i++) { for(int i=0; i<11; i++) {
app.updateQuality(); app.updateQuality();
} }
assertEquals(10, items[0].quality); assertEquals(8, items[0].quality, "Normal Quality should degrade twice after sell passed");
app.updateQuality(); app.updateQuality();
assertEquals(8, items[0].quality); assertEquals(6, items[0].quality, "Normal Quality should degrade twice after sell passed");
app.updateQuality();
assertEquals(6, items[0].quality);
} }
} }