diff --git a/components/server/src/test/java/integration/config/ConfigFileTest.java b/components/server/src/test/java/integration/config/ConfigFileTest.java index 6a188a0..76ceafc 100644 --- a/components/server/src/test/java/integration/config/ConfigFileTest.java +++ b/components/server/src/test/java/integration/config/ConfigFileTest.java @@ -4,14 +4,11 @@ import static util.spring.io.ResourceLocation.classpath; import static util.spring.io.ResourceLocation.filepathFromCwd; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; +import java.io.*; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.springframework.boot.test.OutputCapture; import util.config.ConfigProvider; import util.spring.io.ResourceLocation; @@ -20,10 +17,22 @@ public abstract class ConfigFileTest { - - @Rule - public final OutputCapture generatedConfig = new OutputCapture(); - + + private static void writeStdoutToFile(File f, Runnable outWriter) + throws IOException { + FileOutputStream fileContents = new FileOutputStream(f); + PrintStream ps = new PrintStream(fileContents); + PrintStream currentStdout = System.out; + try { + System.setOut(ps); + outWriter.run(); + System.out.flush(); + } finally { + System.setOut(currentStdout); + } + } + + @Rule public final TemporaryFolder configDirUnderPwd = new TemporaryFolder(new File("./")); @@ -32,23 +41,13 @@ public abstract class ConfigFileTest { protected abstract RunnableApp getFileGenerator(); protected abstract ConfigProvider getFileContents(); - - protected String generateFile() { - getFileGenerator().run(null); - - String fileContents = generatedConfig.toString(); - return fileContents; - } - - protected ResourceLocation writeFile() throws IOException { - String fileContents = generateFile(); - + + private ResourceLocation writeFile() throws IOException { String fileName = getConfigProvider().getConfigFileName(); File configFile = configDirUnderPwd.newFile(fileName); - PrintWriter out = new PrintWriter(configFile); - out.print(fileContents); - out.close(); - + + writeStdoutToFile(configFile, () -> getFileGenerator().run(null)); + String configDirName = configDirUnderPwd.getRoot().getName(); return filepathFromCwd(configDirName, fileName); }