KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > framework > UserOutputImplTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.cli.framework;
25
26 import java.io.ByteArrayOutputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28 import junit.framework.*;
29 /**
30  *
31  * @author <a HREF="mailto:toby.h.ferguson@sun.com">Toby H Ferguson</a>
32  * @version $Revision: 1.4 $
33  */

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 JavaDoc) "object");
40         ui.println("eol");
41         ui.println((Object JavaDoc) "eol2");
42         ui.flush();
43         ui.close();
44     }
45         
46     public void testBasicConstruction() throws IOException JavaDoc {
47         final ByteArrayOutputStreamWithClosure s = new ByteArrayOutputStreamWithClosure();
48         final UserOutputImpl ui = new UserOutputImpl(s, true);
49         ui.print("message");
50         ui.print((Object JavaDoc) "object");
51         ui.println("eol");
52         ui.println((Object JavaDoc) "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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc
89 {
90     boolean closed = false;
91     public void close() throws IOException JavaDoc {
92         super.close();
93         closed = true;
94     }
95     public boolean isClosed(){
96         return closed;
97     }
98 }
99
100
101
Popular Tags