Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import junit.framework.TestCase;
- import java.io.ByteArrayOutputStream;
- import java.io.PrintStream;
- public class HelloWorldTest extends TestCase {
- public static void main(final String[] args) {
- System.out.println("Hello World!");
- }
- public void testHelloWorld() {
- // [Arrange] Capture "Standard I/O" System output:
- final PrintStream oldSystemOut = System.out;
- final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- final PrintStream printStream = new PrintStream(byteArrayOutputStream);
- System.setOut(printStream);
- try {
- // [Act] Code Under Test:
- main(new String[0]);
- } finally {
- System.setOut(oldSystemOut);
- printStream.close();
- }
- // [Assert]
- assertEquals("Hello World!" + System.lineSeparator(), byteArrayOutputStream.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement