KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.*;
27 import java.io.ByteArrayInputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.UnsupportedEncodingException JavaDoc;
30 /**
31  *
32  * @author <a HREF="mailto:toby.h.ferguson@sun.com">Toby H Ferguson</a>
33  * @version $Revision: 1.4 $
34  */

35
36 public class UserInputTest extends TestCase {
37     public void testEncodingProblem() {
38         try {
39             ui.setEncoding("fee");
40             fail("Expected an exception");
41         }
42         catch (IOException JavaDoc ie){
43             assertEquals("fee", ie.getMessage());
44         }
45     }
46
47     public void testEncoding() throws Exception JavaDoc {
48         in = new ByteArrayInputStream JavaDoc("one\ntwo\nthree".getBytes());
49         ui = new UserInput(in);
50         ui.setEncoding("ISO-8859-1");
51         assertEquals('o', ui.getChar());
52         assertEquals("ne", ui.getLine());
53         assertEquals("two", ui.getLine());
54         assertEquals("three", ui.getLine());
55     }
56     
57         
58     
59     public void testReading() throws Exception JavaDoc {
60         in = new ByteArrayInputStream JavaDoc("one\ntwo\nthree".getBytes());
61         ui = new UserInput(in);
62         assertEquals('o', ui.getChar());
63         assertEquals("ne", ui.getLine());
64         assertEquals("two", ui.getLine());
65         assertEquals("three", ui.getLine());
66     }
67     
68         
69     public void testSimpleCase() throws IOException JavaDoc {
70         assertTrue(ui.isInteractive());
71         ui.close();
72     }
73
74     public UserInputTest(String JavaDoc name){
75         super(name);
76     }
77
78     ByteArrayInputStream JavaDoc in;
79     
80     UserInput ui;
81     
82
83     protected void setUp() {
84         in = new ByteArrayInputStream JavaDoc(new byte[0]);
85         ui = new UserInput(in);
86     }
87
88     protected void tearDown() {
89     }
90
91     private void nyi(){
92         fail("Not Yet Implemented");
93     }
94
95     public static void main(String JavaDoc args[]){
96         if (args.length == 0){
97             junit.textui.TestRunner.run(UserInputTest.class);
98         } else {
99             junit.textui.TestRunner.run(makeSuite(args));
100         }
101     }
102     private static TestSuite makeSuite(String JavaDoc args[]){
103         final TestSuite ts = new TestSuite();
104         for (int i = 0; i < args.length; i++){
105             ts.addTest(new UserInputTest(args[i]));
106         }
107         return ts;
108     }
109 }
110
Popular Tags