mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-19 08:21:37 +00:00
Implement faster quality decrease after sellIn
Quality decreases by 2 after the sellIn reaches 0
This commit is contained in:
parent
e9f47d84b4
commit
7e3e5d0d7c
@ -6,6 +6,8 @@ public class DefaultQualityBehavior implements QualityBehavior {
|
||||
|
||||
public static final int MAX_QUALITY_LEVEL = 50;
|
||||
public static final int MIN_QUALITY_LEVEL = 0;
|
||||
public static final int DEFAULT_QUALITY_DECREASE = 1;
|
||||
public static final int FASTER_QUALITY_DECREASE = 2;
|
||||
|
||||
@Override
|
||||
public void processQualityUpdate(Item item) {
|
||||
@ -13,9 +15,12 @@ public class DefaultQualityBehavior implements QualityBehavior {
|
||||
}
|
||||
|
||||
private void decreaseQuality(Item item) {
|
||||
item.quality = limitQuality(item.quality - 1);
|
||||
item.quality = limitQuality(item.quality - getQualityDecreaseAmount(item));
|
||||
}
|
||||
|
||||
private int getQualityDecreaseAmount(Item item) {
|
||||
return item.sellIn > 0 ? DEFAULT_QUALITY_DECREASE : FASTER_QUALITY_DECREASE;
|
||||
}
|
||||
private int limitQuality(int newQuality) {
|
||||
return Math.max(MIN_QUALITY_LEVEL, Math.min(MAX_QUALITY_LEVEL, newQuality));
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ public class DefaultQualityBehaviorTest {
|
||||
|
||||
@Test
|
||||
void decreaseQuality() {
|
||||
Item item = getItem(10);
|
||||
Item item = getItem(5,10);
|
||||
qualityBehavior.processQualityUpdate(item);
|
||||
|
||||
assertEquals(9, item.quality);
|
||||
@ -25,7 +25,7 @@ public class DefaultQualityBehaviorTest {
|
||||
|
||||
@Test
|
||||
void decreaseNegativeQuality() {
|
||||
Item item = getItem(-10);
|
||||
Item item = getItem(5,-10);
|
||||
qualityBehavior.processQualityUpdate(item);
|
||||
|
||||
assertEquals(0, item.quality);
|
||||
@ -33,13 +33,37 @@ public class DefaultQualityBehaviorTest {
|
||||
|
||||
@Test
|
||||
void decreaseQualityZero() {
|
||||
Item item = getItem(0);
|
||||
Item item = getItem(5,0);
|
||||
qualityBehavior.processQualityUpdate(item);
|
||||
|
||||
assertEquals(0, item.quality);
|
||||
}
|
||||
|
||||
private Item getItem(int quality) {
|
||||
return new Item("SomeItem", 0, quality);
|
||||
@Test
|
||||
void decreaseQualityFaster() {
|
||||
Item item = getItem(0,4);
|
||||
qualityBehavior.processQualityUpdate(item);
|
||||
|
||||
assertEquals(2, item.quality);
|
||||
}
|
||||
|
||||
@Test
|
||||
void decreaseQualityFasterNegativeSellIn() {
|
||||
Item item = getItem(-1,4);
|
||||
qualityBehavior.processQualityUpdate(item);
|
||||
|
||||
assertEquals(2, item.quality);
|
||||
}
|
||||
|
||||
@Test
|
||||
void decreaseQualityFasterRespectLowerLimit() {
|
||||
Item item = getItem(0,1);
|
||||
qualityBehavior.processQualityUpdate(item);
|
||||
|
||||
assertEquals(0, item.quality);
|
||||
}
|
||||
|
||||
private Item getItem(int sellIn, int quality) {
|
||||
return new Item("SomeItem", sellIn, quality);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user