1 23 24 package com.sun.enterprise.cli.framework; 25 26 import junit.framework.*; 27 import java.io.ByteArrayInputStream ; 28 import java.io.IOException ; 29 import java.io.UnsupportedEncodingException ; 30 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 ie){ 43 assertEquals("fee", ie.getMessage()); 44 } 45 } 46 47 public void testEncoding() throws Exception { 48 in = new ByteArrayInputStream ("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 { 60 in = new ByteArrayInputStream ("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 { 70 assertTrue(ui.isInteractive()); 71 ui.close(); 72 } 73 74 public UserInputTest(String name){ 75 super(name); 76 } 77 78 ByteArrayInputStream in; 79 80 UserInput ui; 81 82 83 protected void setUp() { 84 in = new ByteArrayInputStream (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 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 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 |