Advertisement
JeffGrigg

Untitled

Nov 21st, 2017
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.95 KB | None | 0 0
  1. import junit.framework.TestCase;
  2.  
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.IOException;
  5. import java.io.OutputStream;
  6. import java.io.PrintStream;
  7.  
  8. public class NumberRectangleTest extends TestCase {
  9.  
  10.     public void test() throws IOException {
  11.         final PrintStream oldSystemOut = System.out;
  12.         final OutputStream outputStream = new ByteArrayOutputStream();
  13.         System.setOut(new PrintStream(outputStream));
  14.         try {
  15.  
  16.             YourMainClassNameHere.main(new String[0]);
  17.  
  18.         } finally {
  19.             System.setOut(oldSystemOut);
  20.         }
  21.         outputStream.flush();
  22.         outputStream.close();
  23.  
  24.         final String NL = System.getProperty("line.separator");
  25.         assertEquals("" +
  26.                         "1 5 9" + NL +
  27.                         "2 6 10" + NL +
  28.                         "3 7 11" + NL +
  29.                         "4 8 12" + NL,
  30.                 outputStream.toString());
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement