mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Generalize backstage
This commit is contained in:
parent
5459470d10
commit
e07bca923b
@ -6,7 +6,6 @@ import java.util.stream.Stream;
|
||||
class GildedRose {
|
||||
Item[] items;
|
||||
|
||||
public static String backStagePasses = "Backstage passes to a TAFKAL80ETC concert";
|
||||
public static String agedBrie = "Aged Brie";
|
||||
public GildedRose(Item[] items) {
|
||||
this.items = items;
|
||||
@ -15,8 +14,8 @@ class GildedRose {
|
||||
public void updateQuality() {
|
||||
Item[] agingItems = Arrays.stream(items).filter(i -> !i.name.toLowerCase().contains("sulfuras")).toArray(Item[]::new);
|
||||
Stream<Item> bries = Arrays.stream(agingItems).filter(i -> i.name.equals(agedBrie));
|
||||
Stream<Item> backstagePasses = Arrays.stream(agingItems).filter(i -> i.name.equals(backStagePasses));
|
||||
Stream<Item> standardItems = Arrays.stream(agingItems).filter(i -> !i.name.equals(backStagePasses) && !i.name.equals(agedBrie));
|
||||
Stream<Item> backstagePasses = Arrays.stream(agingItems).filter(this::isBackstagePass);
|
||||
Stream<Item> standardItems = Arrays.stream(agingItems).filter(i -> !isBackstagePass(i) && !i.name.equals(agedBrie));
|
||||
for (Item item : agingItems) {
|
||||
item.sellIn--;
|
||||
}
|
||||
@ -44,4 +43,9 @@ class GildedRose {
|
||||
} else
|
||||
changeQuality(item, 1);
|
||||
}
|
||||
|
||||
private boolean isBackstagePass(Item i) {
|
||||
return i.name.toLowerCase().contains("backstage");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -90,16 +90,15 @@ class GildedRoseTest {
|
||||
|
||||
@Test
|
||||
void backStagePassesIncrease() {
|
||||
String backstage = GildedRose.backStagePasses;
|
||||
Item[] items = new Item[]{
|
||||
new Item(backstage, 100, 0),
|
||||
new Item(backstage, 11, 0),
|
||||
new Item(backstage, 10, 0),
|
||||
new Item(backstage, 6, 0),
|
||||
new Item(backstage, 5, 0),
|
||||
new Item(backstage, 1, 0),
|
||||
new Item(backstage, 0, 50),
|
||||
new Item(backstage, -1, 50),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 100, 0),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 11, 0),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 0),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 6, 0),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 0),
|
||||
new Item("Backstage passes to a IDK concert", 1, 0),
|
||||
new Item("Backstage passes to a Robbie Williams concert", 0, 50),
|
||||
new Item("Backstage passes to a Hank Williams concert", -1, 50),
|
||||
};
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuality();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user