mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-04 09:11:39 +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() {
|
||||
for (Item item : items) {
|
||||
if (!item.name.equals("Aged Brie")
|
||||
&& !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (!item.getName().equals("Aged Brie")
|
||||
&& !item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,7 @@ class GildedRose {
|
||||
if (item.quality < 50) {
|
||||
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.quality < 50) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
if (!item.name.equals("Aged Brie")) {
|
||||
if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (!item.getName().equals("Aged Brie")) {
|
||||
if (!item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ package com.gildedrose;
|
||||
|
||||
public class Item {
|
||||
|
||||
public String name;
|
||||
private final String name;
|
||||
|
||||
public int sellIn;
|
||||
|
||||
@ -14,6 +14,10 @@ public class Item {
|
||||
this.quality = quality;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + ", " + this.sellIn + ", " + this.quality;
|
||||
|
||||
@ -7,11 +7,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
class GildedRoseTest {
|
||||
|
||||
@Test
|
||||
void foo() {
|
||||
Item[] items = new Item[] { new Item("foo", 0, 0) };
|
||||
GildedRose app = new GildedRose(items);
|
||||
void givenListOfItems_whenUpdateQuality_thenNameRemainsUnchanged() {
|
||||
final var name = "foo";
|
||||
|
||||
var items = new Item[] { new Item(name, 0, 0) };
|
||||
var app = new GildedRose(items);
|
||||
|
||||
app.updateQuality();
|
||||
assertEquals("foo", app.items[0].name);
|
||||
|
||||
assertEquals(name, app.items[0].getName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user