mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
create Conjured class
create conjured class implement StorageItem methods move declaration to each class create test cases for conjured methods
This commit is contained in:
parent
284a01fac5
commit
e04bd79518
@ -53,6 +53,15 @@
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven.maven-surefire-plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class AgeddBrie extends StorageItem {
|
||||
public static final String NAME = "Aged Brie";
|
||||
|
||||
public AgeddBrie(Item item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class BackstagePasses extends StorageItem {
|
||||
public static final String NAME = "Backstage passes to a TAFKAL80ETC concert";
|
||||
|
||||
public BackstagePasses(Item item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
14
Java/src/main/java/com/gildedrose/Conjured.java
Normal file
14
Java/src/main/java/com/gildedrose/Conjured.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class Conjured extends StorageItem {
|
||||
|
||||
public static final String NAME = "Conjured";
|
||||
public Conjured(Item item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decreaseQuality() {
|
||||
item.quality = Math.max(0,item.quality-2);
|
||||
}
|
||||
}
|
||||
@ -1,21 +1,21 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class StorageItem {
|
||||
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";
|
||||
protected Item item;
|
||||
|
||||
public static StorageItem createItem(Item item) {
|
||||
if (item.name.equals(AGED_BRIE)) {
|
||||
if (item.name.equals(AgeddBrie.NAME)) {
|
||||
return new AgeddBrie(item);
|
||||
}
|
||||
if (item.name.equals(BACKSTAGE_PASSES)) {
|
||||
if (item.name.equals(BackstagePasses.NAME)) {
|
||||
return new BackstagePasses(item);
|
||||
}
|
||||
if (item.name.equals(SULFURAS)) {
|
||||
if (item.name.equals(Sulfuras.NAME)) {
|
||||
return new Sulfuras(item);
|
||||
}
|
||||
if (item.name.equals(Conjured.NAME)) {
|
||||
return new Conjured(item);
|
||||
}
|
||||
return new StorageItem(item);
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class Sulfuras extends StorageItem {
|
||||
public static final String NAME = "Sulfuras, Hand of Ragnaros";
|
||||
|
||||
public Sulfuras(Item item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@ -124,21 +124,51 @@ class GildedRoseTest {
|
||||
|
||||
@Test
|
||||
void quality_of_an_item_is_never_greater_than_50() {
|
||||
Item item = new Item("Aged Brie", 5, 50);
|
||||
Item item = new Item("Aged Brie", 50, 100);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateStorage();
|
||||
|
||||
assertThat(item.quality).isEqualTo(50);
|
||||
assertThat(item.quality).isEqualTo(100);
|
||||
}
|
||||
|
||||
@Test
|
||||
void legendary_items_never_have_to_be_sold() {
|
||||
Item item = new Item("Sulfuras, Hand of Ragnaros", -1, 80);
|
||||
Item item = new Item("Sulfuras, Hand of Ragnaros", -1, 100);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateStorage();
|
||||
|
||||
assertThat(item.sellIn).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void conjured_items_degrade_in_quality_twice_as_fast() {
|
||||
Item item = new Item("Conjured", 10, 10);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateStorage();
|
||||
|
||||
assertThat(item.quality).isEqualTo(8);
|
||||
assertThat(item.sellIn).isEqualTo(9);
|
||||
}
|
||||
|
||||
@Test
|
||||
void conjured_item_degrade_in_quality_by_four_if_expired(){
|
||||
Item item = new Item("Conjured", 0, 10);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateStorage();
|
||||
|
||||
assertThat(item.quality).isEqualTo(6);
|
||||
}
|
||||
@Test
|
||||
void conjured_item_quality_can_never_be_negative(){
|
||||
Item item = new Item("Conjured", 10, 1);
|
||||
GildedRose app = new GildedRose(new Item[]{item});
|
||||
|
||||
app.updateStorage();
|
||||
|
||||
assertThat(item.quality).isEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user