Skip to content

Instantly share code, notes, and snippets.

@benjmin-r
Created September 21, 2012 14:09
Show Gist options
  • Save benjmin-r/3761664 to your computer and use it in GitHub Desktop.
Save benjmin-r/3761664 to your computer and use it in GitHub Desktop.
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