Created
January 21, 2016 14:39
-
-
Save rradczewski/8593213fa1eea130b181 to your computer and use it in GitHub Desktop.
Downloads (cached) and runs the GuildedRose TextTestFixtureTest(TestTestTest)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gildedrose; | |
import org.junit.BeforeClass; | |
import org.junit.Test; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.URL; | |
import java.nio.file.Files; | |
import java.nio.file.StandardCopyOption; | |
import static org.hamcrest.core.Is.is; | |
import static org.junit.Assert.assertThat; | |
public class TextTestTest { | |
private static File fixtureFile = new File("./fixture.txt"); | |
private static String fixture; | |
@BeforeClass | |
public static void downloadTextTestFixtureIfNotExist() throws IOException { | |
if(!fixtureFile.exists()) { | |
URL fixture = new URL("https://raw.githubusercontent.com/emilybache/GildedRose-Refactoring-Kata/master/texttests/ThirtyDays/stdout.gr"); | |
InputStream in = fixture.openStream(); | |
Files.copy(in, fixtureFile.toPath(), StandardCopyOption.REPLACE_EXISTING); | |
in.close(); | |
} | |
fixture = new String(Files.readAllBytes(fixtureFile.toPath())); | |
} | |
@Test | |
public void itShouldYieldTheSameTextTestResult() { | |
assertThat(getTextTestResult(), is(fixture)); | |
} | |
public String getTextTestResult() { | |
StringBuilder sb = new StringBuilder(); | |
sb.append("OMGHAI!"); sb.append("\n"); | |
Item[] items = new Item[] { | |
new Item("+5 Dexterity Vest", 10, 20), // | |
new Item("Aged Brie", 2, 0), // | |
new Item("Elixir of the Mongoose", 5, 7), // | |
new Item("Sulfuras, Hand of Ragnaros", 0, 80), // | |
new Item("Sulfuras, Hand of Ragnaros", -1, 80), | |
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), | |
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), | |
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), | |
// this conjured item does not work properly yet | |
new Item("Conjured Mana Cake", 3, 6) }; | |
GildedRose app = new GildedRose(items); | |
int days = 31; | |
for (int i = 0; i < days; i++) { | |
sb.append("-------- day " + i + " --------"); sb.append("\n"); | |
sb.append("name, sellIn, quality"); sb.append("\n"); | |
for (Item item : items) { | |
sb.append(item); sb.append("\n"); | |
} | |
sb.append("\n"); | |
app.updateQuality(); | |
} | |
return sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment