Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

assert system.out.println

private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private final PrintStream originalOut = System.out;
private final PrintStream originalErr = System.err;

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

@After
public void restoreStreams() {
    System.setOut(originalOut);
    System.setErr(originalErr);
}

sample test cases:

@Test
public void out() {
    System.out.print("hello");
    assertEquals("hello", outContent.toString());
}

@Test
public void err() {
    System.err.print("hello again");
    assertEquals("hello again", errContent.toString());
}
Comment

PREVIOUS NEXT
Code Example
Java :: check if string is null or empty java 
Java :: glide dependency android java 
Java :: how to play audio files java 
Java :: circle line intersection java 
Java :: onclicklistener in android studio 
Java :: keytool error: java.io.IOException: keystore password was incorrect java.io.IOException: keystore password was incorrect flutter 
Java :: coding collections clear method java 
Java :: minecraft java arguments 
Java :: how to pass enum in postman body 
Java :: String array into LinkedList java 
Java :: Java code to print odd number 
Java :: how to remove components from a JFRame java 
Java :: Multiply two Strings Leetcode 
Java :: fibunacci java 
Java :: convert local datetime to instant java 
Java :: cloning of list in java 
Java :: sort array java 
Java :: how to convert int array to integer list in java 
Java :: no main manifest attribute java 
Java :: jackson localdate 
Java :: get first character of string java 
Java :: worldedit set random blocks 
Java :: how to count an replace substring string in java 
Java :: loop list java 
Java :: object to double java 
Java :: java create image 
Java :: Uri from bitmap java android 
Java :: java calendar hour vs hour of day 
Java :: java uuid 
Java :: android alertdialog setSingleChoiceItems 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =