mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-10 12:11:20 +00:00
refactor: name never changes once an item is created
This commit is contained in:
parent
4698468083
commit
6564125ba3
@ -9,10 +9,10 @@ class GildedRose {
|
|||||||
|
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
if (!item.name.equals("Aged Brie")
|
if (!item.getName().equals("Aged Brie")
|
||||||
&& !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
&& !item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
if (item.quality > 0) {
|
if (item.quality > 0) {
|
||||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
item.quality = item.quality - 1;
|
item.quality = item.quality - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ class GildedRose {
|
|||||||
if (item.quality < 50) {
|
if (item.quality < 50) {
|
||||||
item.quality = item.quality + 1;
|
item.quality = item.quality + 1;
|
||||||
|
|
||||||
if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
if (item.sellIn < 11) {
|
if (item.sellIn < 11) {
|
||||||
if (item.quality < 50) {
|
if (item.quality < 50) {
|
||||||
item.quality = item.quality + 1;
|
item.quality = item.quality + 1;
|
||||||
@ -36,15 +36,15 @@ class GildedRose {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
item.sellIn = item.sellIn - 1;
|
item.sellIn = item.sellIn - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.sellIn < 0) {
|
if (item.sellIn < 0) {
|
||||||
if (!item.name.equals("Aged Brie")) {
|
if (!item.getName().equals("Aged Brie")) {
|
||||||
if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (!item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
if (item.quality > 0) {
|
if (item.quality > 0) {
|
||||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
item.quality = item.quality - 1;
|
item.quality = item.quality - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package com.gildedrose;
|
|||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
|
|
||||||
public String name;
|
private final String name;
|
||||||
|
|
||||||
public int sellIn;
|
public int sellIn;
|
||||||
|
|
||||||
@ -14,6 +14,10 @@ public class Item {
|
|||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name + ", " + this.sellIn + ", " + this.quality;
|
return this.name + ", " + this.sellIn + ", " + this.quality;
|
||||||
|
|||||||
@ -7,11 +7,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
class GildedRoseTest {
|
class GildedRoseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void foo() {
|
void givenListOfItems_whenUpdateQuality_thenNameRemainsUnchanged() {
|
||||||
Item[] items = new Item[] { new Item("foo", 0, 0) };
|
final var name = "foo";
|
||||||
GildedRose app = new GildedRose(items);
|
|
||||||
|
var items = new Item[] { new Item(name, 0, 0) };
|
||||||
|
var app = new GildedRose(items);
|
||||||
|
|
||||||
app.updateQuality();
|
app.updateQuality();
|
||||||
assertEquals("foo", app.items[0].name);
|
|
||||||
|
assertEquals(name, app.items[0].getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user