Permalink
Browse files

[#5] Move the constants out of the GildedRose class

In order to refactor and clean the code of GildedRose
- Make MAX_QUALITY, MIN_QUALITY & MIN_SELL_IN_DATE as local variables ItemVisitor
- Move AGED_BRIE string to the AgedBrie class
- Move SULFURAS string to the Sulfuras class
- Move CONCERT string to the Concert class
- Adapt the tests accordingly
  • Loading branch information...
aatwi committed Dec 25, 2017
1 parent f854a22 commit f57840938c38e1c0c598d6d8d2020bffbc77441e
@@ -1,9 +1,9 @@
package com.gildedrose;
import static com.gildedrose.GildedRose.AGED_BRIE;
public final class AgedBrie extends ItemVisitable {
protected static final String AGED_BRIE = "Aged Brie";
public AgedBrie(int sellIn, int quality) {
super(AGED_BRIE, sellIn, quality);
}
@@ -1,9 +1,9 @@
package com.gildedrose;
import static com.gildedrose.GildedRose.CONCERT;
public final class Concert extends ItemVisitable {
protected static final String CONCERT = "Backstage passes to a TAFKAL80ETC concert";
public Concert(int sellIn, int quality) {
super(CONCERT, sellIn, quality);
}
@@ -5,14 +5,6 @@
public final class GildedRose {
protected static final String AGED_BRIE = "Aged Brie";
protected static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
protected static final String CONCERT = "Backstage passes to a TAFKAL80ETC concert";
protected static final int MAX_QUALITY = 50;
protected static final int MIN_QUALITY = 0;
protected static final int MIN_SELL_IN_DATE = 0;
private final List<ItemVisitable> itemsList = new ArrayList<>();
public GildedRose(Item[] items) {
@@ -1,15 +1,13 @@
package com.gildedrose;
import static com.gildedrose.GildedRose.*;
public final class ItemFactory {
public static ItemVisitable newItem(Item item) {
if (item.name.equals(CONCERT)) {
if (item.name.equals(Concert.CONCERT)) {
return new Concert(item.sellIn, item.quality);
} else if (item.name.equals(AGED_BRIE)) {
} else if (item.name.equals(AgedBrie.AGED_BRIE)) {
return new AgedBrie(item.sellIn, item.quality);
} else if (item.name.equals(SULFURAS)) {
} else if (item.name.equals(Sulfuras.SULFURAS)) {
return new Sulfuras(item.sellIn, item.quality);
}
return new OtherItem(item.name, item.sellIn, item.quality);
@@ -1,9 +1,11 @@
package com.gildedrose;
import static com.gildedrose.GildedRose.*;
public class ItemVisitor implements Visitor {
private static final int MAX_QUALITY = 50;
private static final int MIN_QUALITY = 0;
private static final int MIN_SELL_IN_DATE = 0;
@Override
public void visit(AgedBrie agedBrie) {
increaseQuality(agedBrie);
@@ -1,9 +1,9 @@
package com.gildedrose;
import static com.gildedrose.GildedRose.SULFURAS;
public final class Sulfuras extends ItemVisitable {
protected static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
public Sulfuras(int sellIn, int quality) {
super(SULFURAS, sellIn, quality);
}
@@ -2,7 +2,7 @@
import org.junit.Test;
import static com.gildedrose.GildedRose.AGED_BRIE;
import static com.gildedrose.AgedBrie.AGED_BRIE;
import static com.gildedrose.ItemBuilder.anItemBuilder;
public class AgedBrieTest extends GildedRoseTest {
@@ -2,7 +2,7 @@
import org.junit.Test;
import static com.gildedrose.GildedRose.CONCERT;
import static com.gildedrose.Concert.CONCERT;
import static com.gildedrose.ItemBuilder.anItemBuilder;
public class ConcertTest extends GildedRoseTest {
@@ -2,8 +2,8 @@
import org.junit.Test;
import static com.gildedrose.GildedRose.SULFURAS;
import static com.gildedrose.ItemBuilder.anItemBuilder;
import static com.gildedrose.Sulfuras.SULFURAS;
public class SulfurasTest extends GildedRoseTest {
@@ -1,6 +1,8 @@
package com.gildedrose;
import static com.gildedrose.GildedRose.*;
import static com.gildedrose.AgedBrie.AGED_BRIE;
import static com.gildedrose.Concert.CONCERT;
import static com.gildedrose.Sulfuras.SULFURAS;
public class TexttestFixture {
public static void main(String[] args) {

0 comments on commit f578409

Please sign in to comment.