mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-20 08:51:08 +00:00
Add increasing quality behavior and test
This commit is contained in:
parent
45ef8fc2ad
commit
e9f47d84b4
@ -0,0 +1,22 @@
|
|||||||
|
package com.gildedrose.behavior.quality;
|
||||||
|
|
||||||
|
import com.gildedrose.Item;
|
||||||
|
|
||||||
|
public class IncreasingQualityBehavior implements QualityBehavior {
|
||||||
|
|
||||||
|
public static final int MAX_QUALITY_LEVEL = 50;
|
||||||
|
public static final int MIN_QUALITY_LEVEL = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processQualityUpdate(Item item) {
|
||||||
|
increaseQuality(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void increaseQuality(Item item) {
|
||||||
|
item.quality = limitQuality(item.quality + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int limitQuality(int newQuality) {
|
||||||
|
return Math.max(MIN_QUALITY_LEVEL, Math.min(MAX_QUALITY_LEVEL, newQuality));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
package com.gildedrose.behavior.quality;
|
||||||
|
|
||||||
|
import com.gildedrose.Item;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
public class IncreasingQualityBehaviorTest {
|
||||||
|
|
||||||
|
private QualityBehavior qualityBehavior;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
qualityBehavior = new IncreasingQualityBehavior();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void increaseQuality() {
|
||||||
|
Item item = getItem(10);
|
||||||
|
qualityBehavior.processQualityUpdate(item);
|
||||||
|
|
||||||
|
assertEquals(11, item.quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void increaseAboveTreshold() {
|
||||||
|
Item item = getItem(99);
|
||||||
|
qualityBehavior.processQualityUpdate(item);
|
||||||
|
|
||||||
|
assertEquals(50, item.quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void increaseQualityAtTreshold() {
|
||||||
|
Item item = getItem(50);
|
||||||
|
qualityBehavior.processQualityUpdate(item);
|
||||||
|
|
||||||
|
assertEquals(50, item.quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Item getItem(int quality) {
|
||||||
|
return new Item("SomeItem", 0, quality);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user