JeffGrigg icon

JUnit Hello World

JeffGrigg | PRO | 07/28/19 10:31:52 PM UTC | 0 ⭐ | 1315 👁️ | Never ⏰ | []
Java 5 |

0 B

|

None

|

0 👍

/

0 👎

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());
    }
 
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎