Created
September 21, 2012 14:09
-
-
Save benjmin-r/3761664 to your computer and use it in GitHub Desktop.
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
import static org.hamcrest.CoreMatchers.equalTo; | |
import static org.hamcrest.CoreMatchers.is; | |
import static org.junit.Assert.*; | |
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.PrintStream; | |
import org.apache.commons.io.IOUtils; | |
import org.junit.Test; | |
import com.adaptionsoft.games.trivia.runner.GameRunner; | |
import com.adaptionsoft.games.uglytrivia.Game; | |
public class GoldenMasterTest { | |
@Test | |
public void create_initial_test_data() throws FileNotFoundException { | |
PrintStream fileOutput = new PrintStream(new File("golden-master.txt")); | |
System.setOut(fileOutput); | |
GameRunner.main(new String[] {"1"}); | |
} | |
private String runGame() { | |
ByteArrayOutputStream stream = new ByteArrayOutputStream(); | |
System.setOut(new PrintStream(stream)); | |
GameRunner.main(new String[] {"1"}); | |
return stream.toString(); | |
} | |
private void assertSameOutputAsGoldenMaster(String output) throws IOException { | |
InputStream goldenMasterStream = null; | |
String goldenMaster = null; | |
try { | |
goldenMasterStream = new FileInputStream("golden-master.txt"); | |
goldenMaster = IOUtils.toString(goldenMasterStream); | |
} finally { | |
IOUtils.closeQuietly(goldenMasterStream); | |
} | |
assertThat(output, is(equalTo(goldenMaster))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment