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 UserOutputImplTest extends TestCase { 36 public void testNullCOnstruction(){ 37 final UserOutputImpl ui = new UserOutputImpl(null, true); 38 ui.print("message"); 39 ui.print((Object ) "object"); 40 ui.println("eol"); 41 ui.println((Object ) "eol2"); 42 ui.flush(); 43 ui.close(); 44 } 45 46 public void testBasicConstruction() throws IOException { 47 final ByteArrayOutputStreamWithClosure s = new ByteArrayOutputStreamWithClosure(); 48 final UserOutputImpl ui = new UserOutputImpl(s, true); 49 ui.print("message"); 50 ui.print((Object ) "object"); 51 ui.println("eol"); 52 ui.println((Object ) "eol2"); 53 ui.flush(); 54 ui.close(); 55 assertEquals("messageobjecteol"+System.getProperty("line.separator") +"eol2"+System.getProperty("line.separator"), s.toString()); 56 assertTrue(s.isClosed()); 57 } 58 59 public UserOutputImplTest(String name){ 60 super(name); 61 } 62 63 protected void setUp() { 64 } 65 66 protected void tearDown() { 67 } 68 69 private void nyi(){ 70 fail("Not Yet Implemented"); 71 } 72 73 public static void main(String args[]){ 74 if (args.length == 0){ 75 junit.textui.TestRunner.run(UserOutputImplTest.class); 76 } else { 77 junit.textui.TestRunner.run(makeSuite(args)); 78 } 79 } 80 private static TestSuite makeSuite(String args[]){ 81 final TestSuite ts = new TestSuite(); 82 for (int i = 0; i < args.length; i++){ 83 ts.addTest(new UserOutputImplTest(args[i])); 84 } 85 return ts; 86 } 87 } 88 class ByteArrayOutputStreamWithClosure extends ByteArrayOutputStream 89 { 90 boolean closed = false; 91 public void close() throws IOException { 92 super.close(); 93 closed = true; 94 } 95 public boolean isClosed(){ 96 return closed; 97 } 98 } 99 100 101 | Popular Tags |