Created
September 24, 2014 08:29
-
-
Save ragklaat/28dad2f3346ae11e6a6b to your computer and use it in GitHub Desktop.
JUnit test for methods writing to OutputStream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 SystemOutTest { | |
private final ByteArrayOutputStream output = new ByteArrayOutputStream(); | |
@Before | |
public void setUpStreams() { | |
System.setOut(new PrintStream(output)); | |
} | |
@After | |
public void cleanUpStreams() { | |
System.setOut(null); | |
} | |
@Test | |
public void testSystemOut() { | |
System.out.print("assertme!"); | |
assertEquals("assertme!", output.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment