Example usage for java.lang System setOut

List of usage examples for java.lang System setOut

Introduction

In this page you can find the example usage for java.lang System setOut.

Prototype

public static void setOut(PrintStream out) 

Source Link

Document

Reassigns the "standard" output stream.

Usage

From source file:de.langmi.spring.batch.examples.basics.tasklet.CustomTaskletStepTest.java

@Before
public void setUp() {
    // catch and set new system out
    oldSysOut = System.out;
    System.setOut(new PrintStream(newSysOut));
}

From source file:ape_test.CLITest.java

public void testVersionPrint() {
    PrintStream originalOut = System.out;
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    System.setOut(ps);

    String[] theArgs = new String[1];
    theArgs[0] = "-V";
    Main.main(theArgs);/*from   www.j  av  a2s  .  c  o  m*/
    assertEquals("ChaosMonkey version: " + Main.getVersion() + "\n", os.toString());

    System.setOut(originalOut);
}

From source file:com.kotcrab.vis.editor.Log.java

/** Initializes logging facility, called once by VisEditor. */
public static void init() {
    if (initialized)
        throw new IllegalStateException("Log cannot be initialized twice!");
    initialized = true;//from w  w w .  j a  v a  2s. c o  m
    prepareLogFile();
    System.setOut(new PrintStream(new TeeOutputStream(System.out, logFileStream)));
    System.setErr(new PrintStream(new TeeOutputStream(System.err, logFileStream)));
}

From source file:de.langmi.spring.batch.examples.basics.tasklet.SimpleTaskletStepTest.java

@Before
public void setup() {
    // catch and set new system out
    oldSysOut = System.out;
    System.setOut(new PrintStream(newSysOut));
}

From source file:b2s.idea.mavenize.AppTest.java

@Before
public void setUp() throws Exception {
    output = new ByteArrayOutputStream();

    App.jarCombiner = combiner;/* w  ww  .j  a  v a2  s .c  o m*/
    originalSysOut = System.out;
    System.setOut(new PrintStream(output));

    ideaFolder = temporaryFolder.newFolder();
    outputFolder = temporaryFolder.newFolder();
    ideaLibFolder = new File(ideaFolder, "lib");
    IOUtils.write("build-version", new FileOutputStream(new File(ideaFolder, "build.txt")));
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.logging.LoggerDestinationFastTest.java

@Test
public void stdoutLoggerDestination() throws IOException, LoggerDestination.LoggerException {

    PrintStream outStream = null;

    try {/*from   w w  w. java 2 s  . c  o  m*/
        // redirect stdout to a file
        String outfile = OUTPUT_PATH + "stdout.txt";
        //noinspection IOResourceOpenedButNotSafelyClosed
        outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile)));
        System.setOut(outStream);
        // send message to logger destination
        StdoutLoggerDestination dest = new StdoutLoggerDestination();
        dest.setMinLevel(Level.DEBUG);
        String message = "THIS IS AN ERROR MESSAGE";
        dest.logToDestination(Level.ERROR, message);
        outStream.close();
        // read in output file and compare to expected
        assertEquals(message, readFirstLine(outfile));
        new File(outfile).deleteOnExit();
    } finally {
        IOUtils.closeQuietly(outStream);
    }
}

From source file:org.datacleaner.job.runner.ErrorAwareAnalysisListenerTest.java

@Override
protected void tearDown() throws Exception {
    super.tearDown();
    System.setOut(oldOut);
}

From source file:org.g_node.mergers.LktCliControllerTest.java

/**
 * Redirect Error and Out stream.//from w w  w  .  j ava 2 s . c o m
 * @throws Exception
 */
@Before
public void setUp() throws Exception {
    this.stdout = System.out;
    this.outStream = new ByteArrayOutputStream();
    System.setOut(new PrintStream(this.outStream));

    final String miniTTL = "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n\n_:a foaf:name\t\"TestName\"";
    FileUtils.write(this.testRdfFile, miniTTL);

    Logger rootLogger = Logger.getRootLogger();
    rootLogger.setLevel(Level.INFO);
    rootLogger.addAppender(new ConsoleAppender(new PatternLayout("[%-5p] %m%n")));
}

From source file:org.g_node.micro.commons.RDFServiceTest.java

/**
 * Redirect Out stream and create a test folder and the main
 * test file in the java temp directory.
 * @throws Exception/*  w w  w  . j av a 2  s . c  o m*/
 */
@Before
public void setUp() throws Exception {

    this.stdout = System.out;
    this.outStream = new ByteArrayOutputStream();
    System.setOut(new PrintStream(this.outStream));

    Logger rootLogger = Logger.getRootLogger();
    rootLogger.setLevel(Level.INFO);
    rootLogger.addAppender(new ConsoleAppender(new PatternLayout("[%-5p] %m%n")));

    final String testFileName = "test.txt";
    final File currTestFile = this.testFileFolder.resolve(testFileName).toFile();
    FileUtils.write(currTestFile, "This is a normal test file");
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.text.TextWriterTest.java

@Test
public void testStdOut() throws Exception {
    final String text = "This is a test";

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    PrintStream originalOut = System.out;
    try {/*from   w w w.  j av a 2s.com*/
        System.setOut(new PrintStream(baos));

        JCas jcas = JCasFactory.createJCas();
        jcas.setDocumentText(text);

        AnalysisEngineDescription writer = createEngineDescription(TextWriter.class);
        runPipeline(jcas, writer);

        System.out.close();
    } finally {
        System.setOut(originalOut);
    }

    assertEquals(text, baos.toString("UTF-8"));
}