mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 16:01:42 +00:00
Added By Shanmugam on Code Cleanup of GildedRose
Mail Id :Shanmugamcse@gmail.com
This commit is contained in:
parent
181b48aff7
commit
72aa0fef8f
8
Java/src/main/java/com/gildedrose/Constants.java
Normal file
8
Java/src/main/java/com/gildedrose/Constants.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class Constants {
|
||||||
|
public static final String AgedBrie = "Aged Brie";
|
||||||
|
public static final String Backstage = "Backstage passes to a TAFKAL80ETC concert";
|
||||||
|
public static final String Sulfuras = "Sulfuras, Hand of Ragnaros";
|
||||||
|
public static final String Conjured = "Conjured";
|
||||||
|
}
|
||||||
@ -8,55 +8,8 @@ class GildedRose {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (Item item : items) {
|
||||||
if (!items[i].name.equals("Aged Brie")
|
ItemFactory.create(item).update();
|
||||||
&& !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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (items[i].quality < 50) {
|
|
||||||
items[i].quality = items[i].quality + 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 (items[i].sellIn < 6) {
|
|
||||||
if (items[i].quality < 50) {
|
|
||||||
items[i].quality = items[i].quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
|
||||||
items[i].sellIn = items[i].sellIn - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
items[i].quality = items[i].quality - items[i].quality;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (items[i].quality < 50) {
|
|
||||||
items[i].quality = items[i].quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
Java/src/main/java/com/gildedrose/ItemFactory.java
Normal file
18
Java/src/main/java/com/gildedrose/ItemFactory.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class ItemFactory {
|
||||||
|
public static ItemWrapper create(Item item) {
|
||||||
|
switch (item.name) {
|
||||||
|
case Constants.AgedBrie:
|
||||||
|
return new updateBrie(item);
|
||||||
|
case Constants.Backstage:
|
||||||
|
return new updateBackstage(item);
|
||||||
|
case Constants.Sulfuras:
|
||||||
|
return new updateLegendary(item);
|
||||||
|
case Constants.Conjured:
|
||||||
|
return new updateConjured(item);
|
||||||
|
default:
|
||||||
|
return new updateOther(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Java/src/main/java/com/gildedrose/ItemWrapper.java
Normal file
11
Java/src/main/java/com/gildedrose/ItemWrapper.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public abstract class ItemWrapper {
|
||||||
|
protected final Item item;
|
||||||
|
|
||||||
|
public ItemWrapper(Item item) {
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void update();
|
||||||
|
}
|
||||||
30
Java/src/main/java/com/gildedrose/updateBackstage.java
Normal file
30
Java/src/main/java/com/gildedrose/updateBackstage.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class updateBackstage extends ItemWrapper {
|
||||||
|
public updateBackstage(Item item) {
|
||||||
|
super(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
if (item.quality < 50) {
|
||||||
|
item.quality = item.quality + 1;
|
||||||
|
|
||||||
|
if (item.sellIn < 11) {
|
||||||
|
if (item.quality < 50) {
|
||||||
|
item.quality = item.quality + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.sellIn < 6) {
|
||||||
|
if (item.quality < 50) {
|
||||||
|
item.quality = item.quality + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.sellIn = item.sellIn - 1;
|
||||||
|
if (item.sellIn < 0) {
|
||||||
|
item.quality = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
Java/src/main/java/com/gildedrose/updateBrie.java
Normal file
20
Java/src/main/java/com/gildedrose/updateBrie.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class updateBrie extends ItemWrapper {
|
||||||
|
public updateBrie(Item item) {
|
||||||
|
super(item);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
if (item.quality < 50) {
|
||||||
|
item.quality = item.quality + 1;
|
||||||
|
}
|
||||||
|
item.sellIn = item.sellIn - 1;
|
||||||
|
if (item.sellIn < 0 && item.quality < 50) {
|
||||||
|
item.quality = item.quality + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
18
Java/src/main/java/com/gildedrose/updateConjured.java
Normal file
18
Java/src/main/java/com/gildedrose/updateConjured.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class updateConjured extends ItemWrapper {
|
||||||
|
public updateConjured(Item item) {
|
||||||
|
super(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
if (item.quality > 1) {
|
||||||
|
item.quality = item.quality - 2;
|
||||||
|
}
|
||||||
|
item.sellIn = item.sellIn - 1;
|
||||||
|
if (item.sellIn < 0 && item.quality > 1) {
|
||||||
|
item.quality = item.quality - 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Java/src/main/java/com/gildedrose/updateLegendary.java
Normal file
12
Java/src/main/java/com/gildedrose/updateLegendary.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class updateLegendary extends ItemWrapper {
|
||||||
|
public updateLegendary(Item item) {
|
||||||
|
super(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Java/src/main/java/com/gildedrose/updateOther.java
Normal file
18
Java/src/main/java/com/gildedrose/updateOther.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.gildedrose;
|
||||||
|
|
||||||
|
public class updateOther extends ItemWrapper {
|
||||||
|
public updateOther(Item item) {
|
||||||
|
super(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
if (item.quality > 0) {
|
||||||
|
item.quality = item.quality - 1;
|
||||||
|
}
|
||||||
|
item.sellIn = item.sellIn - 1;
|
||||||
|
if (item.sellIn < 0 && item.quality > 0) {
|
||||||
|
item.quality = item.quality - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
@ -7,11 +8,68 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
class GildedRoseTest {
|
class GildedRoseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void foo() {
|
@DisplayName("Test Aged Brie functionality")
|
||||||
Item[] items = new Item[] { new Item("foo", 0, 0) };
|
void testAgedBrie() {
|
||||||
|
Item[] items = new Item[] { new Item("Aged Brie", 10, 80) };
|
||||||
GildedRose app = new GildedRose(items);
|
GildedRose app = new GildedRose(items);
|
||||||
app.updateQuality();
|
app.updateQuality();
|
||||||
assertEquals("fixme", app.items[0].name);
|
assertEquals(Constants.AgedBrie, app.items[0].name);
|
||||||
|
assertEquals(9, app.items[0].sellIn);
|
||||||
|
assertEquals(80, app.items[0].quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test BackStage functionality")
|
||||||
|
void testBackStageSellIn() {
|
||||||
|
Item[] items = new Item[] { new Item("Backstage passes to a TAFKAL80ETC concert", 20, 50) };
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
app.updateQuality();
|
||||||
|
assertEquals(Constants.Backstage, app.items[0].name);
|
||||||
|
assertEquals(19, app.items[0].sellIn);
|
||||||
|
assertEquals(50, app.items[0].quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test BackStage Quality functionality")
|
||||||
|
void testBackStageQuality() {
|
||||||
|
Item[] items = new Item[] { new Item("Backstage passes to a TAFKAL80ETC concert", 10, 45) };
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
app.updateQuality();
|
||||||
|
assertEquals(Constants.Backstage, app.items[0].name);
|
||||||
|
assertEquals(9, app.items[0].sellIn);
|
||||||
|
assertEquals(47, app.items[0].quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test BackStage Quality with least functionality")
|
||||||
|
void testBackStageQualitywithLeast() {
|
||||||
|
Item[] items = new Item[] { new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49) };
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
app.updateQuality();
|
||||||
|
assertEquals(Constants.Backstage, app.items[0].name);
|
||||||
|
assertEquals(4, app.items[0].sellIn);
|
||||||
|
assertEquals(50, app.items[0].quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test Other functionality")
|
||||||
|
void testOther() {
|
||||||
|
Item[] items = new Item[] { new Item("Shan", 10, 20) };
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
app.updateQuality();
|
||||||
|
assertEquals("Shan", app.items[0].name);
|
||||||
|
assertEquals(9, app.items[0].sellIn);
|
||||||
|
assertEquals(19, app.items[0].quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test Conjured functionality")
|
||||||
|
void testConjured() {
|
||||||
|
Item[] items = new Item[] { new Item("Conjured", 10, 10) };
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
app.updateQuality();
|
||||||
|
assertEquals(Constants.Conjured, app.items[0].name);
|
||||||
|
assertEquals(9, app.items[0].sellIn);
|
||||||
|
assertEquals(8, app.items[0].quality);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user