mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
break down the method
breaking down the method updateQuality for to various scopes as a refactoring
This commit is contained in:
parent
1302ae4686
commit
aefb4310a9
@ -7,53 +7,61 @@ class GildedRose {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public void updateQuality() {
|
||||
public void updateInventory() {
|
||||
for (Item item : items) {
|
||||
if (!item.name.equals("Aged Brie")
|
||||
&& !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.quality > 0) {
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.quality--;
|
||||
updateItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateItem(Item item) {
|
||||
updateQuality(item);
|
||||
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.sellIn--;
|
||||
}
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
if (!item.name.equals("Aged Brie")) {
|
||||
if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.quality > 0) {
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.quality--;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
item.quality = 0;
|
||||
}
|
||||
} else {
|
||||
if (item.quality < 50) {
|
||||
item.quality++;
|
||||
|
||||
if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.sellIn < 11) {
|
||||
if (item.quality < 50) {
|
||||
item.quality++;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.sellIn < 6) {
|
||||
if (item.quality < 50) {
|
||||
item.quality++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.sellIn--;
|
||||
private static void updateQuality(Item item) {
|
||||
if (!item.name.equals("Aged Brie")
|
||||
&& !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.quality > 0) {
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.quality--;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (item.quality < 50) {
|
||||
item.quality++;
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
if (!item.name.equals("Aged Brie")) {
|
||||
if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.quality > 0) {
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.quality--;
|
||||
}
|
||||
if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.sellIn < 11) {
|
||||
if (item.quality < 50) {
|
||||
item.quality++;
|
||||
}
|
||||
} else {
|
||||
item.quality = 0;
|
||||
}
|
||||
} else {
|
||||
if (item.quality < 50) {
|
||||
item.quality++;
|
||||
|
||||
if (item.sellIn < 6) {
|
||||
if (item.quality < 50) {
|
||||
item.quality++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ class GildedRoseTest {
|
||||
void foo() {
|
||||
Item[] items = new Item[] { new Item("foo", 0, 0) };
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
assertEquals("foo", app.items[0].name);
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ class GildedRoseTest {
|
||||
final Item standardItem = new Item("spam", startingSellin, startingQuality);
|
||||
GildedRose app = new GildedRose(new Item[]{standardItem});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(standardItem.sellIn).isEqualTo(startingSellin - 1);
|
||||
assertThat(standardItem.quality).isEqualTo(startingQuality - 1);
|
||||
@ -34,7 +34,7 @@ class GildedRoseTest {
|
||||
Item secondItem = new Item("Second Standard Item", 3, 2);
|
||||
GildedRose app = new GildedRose(new Item[]{firstItem, secondItem});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(firstItem.sellIn).isEqualTo(4);
|
||||
assertThat(firstItem.quality).isEqualTo(3);
|
||||
@ -47,7 +47,7 @@ class GildedRoseTest {
|
||||
Item item = new Item("Standard Item", -1, 6);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(item.quality).isEqualTo(4);
|
||||
}
|
||||
@ -57,7 +57,7 @@ class GildedRoseTest {
|
||||
Item item = new Item("Standard Item", 1, 6);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(item.quality).isEqualTo(5);
|
||||
}
|
||||
@ -67,7 +67,7 @@ class GildedRoseTest {
|
||||
Item item = new Item("Standard Item", 5, 1);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(item.quality).isZero();
|
||||
}
|
||||
@ -77,7 +77,7 @@ class GildedRoseTest {
|
||||
Item item = new Item("First Standard Item", 4, 0);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(item.quality).isZero();
|
||||
}
|
||||
@ -87,7 +87,7 @@ class GildedRoseTest {
|
||||
Item item = new Item("Aged Brie", 5, 6);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(item.quality).isEqualTo(7);
|
||||
}
|
||||
@ -97,7 +97,7 @@ class GildedRoseTest {
|
||||
Item item = new Item("Aged Brie", 5, 49);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(item.quality).isEqualTo(50);
|
||||
}
|
||||
@ -107,7 +107,7 @@ class GildedRoseTest {
|
||||
Item item = new Item("Aged Brie", 0, 6);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(item.quality).isEqualTo(8);
|
||||
}
|
||||
@ -117,7 +117,7 @@ class GildedRoseTest {
|
||||
Item item = new Item("Aged Brie", 0, 50);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(item.quality).isEqualTo(50);
|
||||
}
|
||||
@ -127,7 +127,7 @@ class GildedRoseTest {
|
||||
Item item = new Item("Aged Brie", 5, 50);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(item.quality).isEqualTo(50);
|
||||
}
|
||||
@ -137,7 +137,7 @@ class GildedRoseTest {
|
||||
Item item = new Item("Sulfuras, Hand of Ragnaros", -1, 80);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
|
||||
assertThat(item.sellIn).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class TexttestFixture {
|
||||
System.out.println(item);
|
||||
}
|
||||
System.out.println();
|
||||
app.updateQuality();
|
||||
app.updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user