mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 16:01:42 +00:00
First simplification of app + unittests
This commit is contained in:
parent
181b48aff7
commit
d83aa3ca8c
@ -3,60 +3,88 @@ package com.gildedrose;
|
||||
class GildedRose {
|
||||
Item[] items;
|
||||
|
||||
String itemName;
|
||||
int itemQuality;
|
||||
int itemSellIn;
|
||||
|
||||
public GildedRose(Item[] items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public void updateQuality() {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (!items[i].name.equals("Aged Brie")
|
||||
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].quality > 0) {
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].quality = items[i].quality - 1;
|
||||
itemName = items[i].name;
|
||||
itemQuality = items[i].quality;
|
||||
itemSellIn = items[i].sellIn;
|
||||
|
||||
if (!itemIsAgedBrie(itemName)
|
||||
&& !itemIsBackstagePasses(itemName)) {
|
||||
if (itemQuality > 0) {
|
||||
if (!itemIsSulfuras(itemName)) {
|
||||
decreaseByOne(itemQuality);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
if (itemQuality < 50) {
|
||||
itemQuality = itemQuality + 1;
|
||||
|
||||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].sellIn < 11) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
if (itemIsBackstagePasses(itemName)) {
|
||||
if (itemSellIn < 11) {
|
||||
if (itemQuality < 50) {
|
||||
increaseByOne(itemQuality);
|
||||
}
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 6) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
if (itemSellIn < 6) {
|
||||
if (itemQuality < 50) {
|
||||
increaseByOne(itemQuality);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].sellIn = items[i].sellIn - 1;
|
||||
if (!itemIsSulfuras(itemName)) {
|
||||
decreaseByOne(itemSellIn);
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 0) {
|
||||
if (!items[i].name.equals("Aged Brie")) {
|
||||
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].quality > 0) {
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].quality = items[i].quality - 1;
|
||||
if (itemSellIn < 0) {
|
||||
if (!itemIsAgedBrie(itemName)) {
|
||||
if (!itemIsBackstagePasses(itemName)) {
|
||||
if (itemQuality > 0) {
|
||||
if (!itemIsSulfuras(itemName)) {
|
||||
decreaseByOne(itemQuality);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
items[i].quality = items[i].quality - items[i].quality;
|
||||
decreaseByOne(itemQuality);
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
if (itemQuality < 50) {
|
||||
increaseByOne(itemQuality);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void increaseByOne (int itemValue) {
|
||||
itemValue++;
|
||||
}
|
||||
|
||||
public void decreaseByOne (int itemValue) {
|
||||
itemValue--;
|
||||
}
|
||||
|
||||
public boolean itemIsSulfuras(String itemName) {
|
||||
return ProjectConstants.SULFURAS.equals(itemName) ? true : false;
|
||||
}
|
||||
|
||||
public boolean itemIsBackstagePasses(String itemName) {
|
||||
return ProjectConstants.BACKSTAGE_PASSES.equals(itemName) ? true : false;
|
||||
}
|
||||
|
||||
public boolean itemIsAgedBrie(String itemName) {
|
||||
return ProjectConstants.AGED_BRIE.equals(itemName) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
7
Java/src/main/java/com/gildedrose/ProjectConstants.java
Normal file
7
Java/src/main/java/com/gildedrose/ProjectConstants.java
Normal file
@ -0,0 +1,7 @@
|
||||
package com.gildedrose;
|
||||
|
||||
class ProjectConstants {
|
||||
public static final String AGED_BRIE = "Aged Brie";
|
||||
public static final String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert";
|
||||
public static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
|
||||
}
|
||||
@ -1,17 +1,46 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
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);
|
||||
app.updateQuality();
|
||||
assertEquals("fixme", app.items[0].name);
|
||||
GildedRose app;
|
||||
|
||||
@BeforeAll
|
||||
public void init() {
|
||||
Item[] items = new Item[] { new Item(ProjectConstants.SULFURAS, 0, 0) };
|
||||
app = new GildedRose(items);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void increaseByOne() {
|
||||
int initial = 2;
|
||||
app.increaseByOne(initial);
|
||||
assertEquals("3", initial);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decreaseByOne() {
|
||||
int initial = 2;
|
||||
app.decreaseByOne(initial);
|
||||
assertEquals("1", initial);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemIsSulfuras() {
|
||||
String itemName = app.items[0].name;
|
||||
boolean result = app.itemIsSulfuras(itemName);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ItemIsAgedBrieFalse() {
|
||||
String itemName = app.items[0].name;
|
||||
boolean result = app.itemIsAgedBrie(itemName);
|
||||
assertFalse(result);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user