1 23 24 package com.sun.enterprise.cli.framework; 25 26 import java.io.ByteArrayOutputStream ; 27 import java.io.IOException ; 28 import junit.framework.*; 29 34 35 public class OutputTest extends TestCase { 36 public void testNotClosedWhenDone() throws Exception { 37 final TestStream ts = new TestStream(); 38 final Output out = new Output(ts, false); 39 out.close(); 40 assertTrue("Expected test stream to still be open", !ts.isClosed()); 41 } 42 43 public void testClosedWhenDone() throws Exception { 44 final TestStream ts = new TestStream(); 45 final Output out = new Output(ts, true); 46 out.close(); 47 assertTrue("Expected test stream to be closed", ts.isClosed()); 48 } 49 50 public void testPrintlnObject() throws Exception { 51 final ByteArrayOutputStream bout = new ByteArrayOutputStream (); 52 final Output out = new Output(bout, true); 53 final Object o = new Object (); 54 out.println(o); 55 out.flush(); 56 assertEquals(o.toString() + System.getProperty("line.separator"), bout.toString()); 57 } 58 59 public void testPrintln() throws Exception { 60 final ByteArrayOutputStream bout = new ByteArrayOutputStream (); 61 final Output out = new Output(bout, true); 62 out.println("m"); 63 out.flush(); 64 assertEquals("m" + System.getProperty("line.separator"), bout.toString()); 65 } 66 67 public void testPrintObject() throws Exception { 68 final ByteArrayOutputStream bout = new ByteArrayOutputStream (); 69 final Output out = new Output(bout, true); 70 final Object o = new Object (); 71 out.print(o); 72 out.flush(); 73 assertEquals(o.toString()+"\n", bout.toString()); 75 } 76 77 public void testSimpleUse() throws Exception { 78 final ByteArrayOutputStream bout = new ByteArrayOutputStream (); 79 final Output out = new Output(bout, true); 80 out.print("m"); 81 out.flush(); 82 assertEquals("m", bout.toString()); 83 } 84 85 public OutputTest(String name){ 86 super(name); 87 } 88 89 protected void setUp() { 90 } 91 92 protected void tearDown() { 93 } 94 95 private void nyi(){ 96 fail("Not Yet Implemented"); 97 } 98 99 public static void main(String args[]){ 100 if (args.length == 0){ 101 junit.textui.TestRunner.run(OutputTest.class); 102 } else { 103 junit.textui.TestRunner.run(makeSuite(args)); 104 } 105 } 106 private static TestSuite makeSuite(String args[]){ 107 final TestSuite ts = new TestSuite(); 108 for (int i = 0; i < args.length; i++){ 109 ts.addTest(new OutputTest(args[i])); 110 } 111 return ts; 112 } 113 } 114 115 class TestStream extends ByteArrayOutputStream 116 { 117 private boolean closed = false; 118 public void close() throws IOException { 119 super.close(); 120 closed = true; 121 } 122 boolean isClosed() { 123 return closed; 124 } 125 } 126 | Popular Tags |