Add OutputCapture test class
This commit is contained in:
@@ -16,41 +16,21 @@
|
||||
|
||||
package org.springframework.boot.sample.xml;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.sample.xml.SampleSpringXmlApplication;
|
||||
import org.springframework.boot.OutputCapture;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SampleSpringXmlApplicationTests {
|
||||
|
||||
private static PrintStream savedOutput;
|
||||
private static ByteArrayOutputStream output;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
savedOutput = System.out;
|
||||
output = new ByteArrayOutputStream();
|
||||
System.setOut(new PrintStream(output));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void clear() {
|
||||
System.setOut(savedOutput);
|
||||
}
|
||||
|
||||
private static String getOutput() {
|
||||
return output.toString();
|
||||
}
|
||||
@Rule
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
|
||||
@Test
|
||||
public void testDefaultSettings() throws Exception {
|
||||
SampleSpringXmlApplication.main(new String[0]);
|
||||
String output = getOutput();
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello World"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user