不要被这个世界改变!|

unit test for system out

这本来是个分享的,但插件不好使了,等有时间在搞一个
 
						package test;


import static org.junit.Assert.assertEquals;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class mainTest {

  private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
  private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();

  @Before
  public void setUpStreams() {
    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));
  }

  @After
  public void restoreStreams() {
    System.setOut(System.out);
    System.setErr(System.err);
  }

  @Test
  public void mainTest(){
    three.main(new String[]{});
    assertEquals("pish tegj glob glob is 42\\n"
        + "glob prok Silver is 68 Credits\\n"
        + "glob prok Gold is 57800 Credits\\n"
        + "glob prok Iron is 782 Credits\\n"
        + "I have no idea what you are talking about\\n", outContent.toString());
  }
}
						//该余额宝领红包码来自于http://www.codesnippet.cn/detail/1306201815281.html