Advertisement
JeffGrigg

Untitled

Apr 2nd, 2021
2,318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.56 KB | None | 0 0
  1. import junit.framework.TestCase;
  2.  
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.PrintStream;
  5.  
  6. public class HelloWorldTest extends TestCase {
  7.     public void testHelloWorld() {
  8.         final var oldSystemOut = System.out;
  9.         final var outputStream = new ByteArrayOutputStream();
  10.         System.setOut(new PrintStream(outputStream));
  11.         try {
  12.             HelloWorld.main(null);
  13.         } finally {
  14.             System.setOut(oldSystemOut);
  15.         }
  16.         assertEquals("Hello world!" + System.lineSeparator(), outputStream.toString());
  17.     }
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement