FileDocCategorySizeDatePackage
InputsAndOutputsTest.javaAPI DocGlassfish v2 API7367Fri May 04 22:25:30 BST 2007com.sun.enterprise.cli.framework

InputsAndOutputsTest

public class InputsAndOutputsTest extends TestCase
author
Toby H Ferguson
version
$Revision: 1.5 $

Fields Summary
InputsAndOutputs
io
Constructors Summary
public InputsAndOutputsTest(String name)

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        if (args.length == 0){
            junit.textui.TestRunner.run(InputsAndOutputsTest.class);
        } else {
            junit.textui.TestRunner.run(makeSuite(args));
        }
    
private static junit.framework.TestSuitemakeSuite(java.lang.String[] args)

        final TestSuite ts = new TestSuite();
        for (int i = 0; i < args.length; i++){
            ts.addTest(new InputsAndOutputsTest(args[i]));
        }
        return ts;
    
private voidnyi()

        fail("Not Yet Implemented");
    
protected voidsetUp()

        io = InputsAndOutputs.getInstance();
    
protected voidtearDown()

    
public voidtestAssignment()

        io.setInstance(InputsAndOutputs.getInstance());
        assertEquals(io, InputsAndOutputs.getInstance());
    
public voidtestConstruction()

        assertNotNull(io.getUserOutput());
    
public voidtestSetGetErrorOutputStream()

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        io.setErrorOutput(baos);
        final IErrorOutput uo = io.getErrorOutput();
        uo.print("foo");
        uo.close();
        assertEquals("foo", baos.toString());
    
public voidtestSetGetUserErrorStreamToFile()

        final File f = File.createTempFile("InputsAndOutputsTest_testSetGetUserOutputStreamToFile", "tmp");
        f.deleteOnExit();
        io.setErrorOutputFile(f.toString());
        final IErrorOutput uo = io.getErrorOutput();
        uo.println("foo");
        uo.close();
        final BufferedReader fr= new BufferedReader(new FileReader(f));
        assertEquals("foo", fr.readLine());
    
public voidtestSetGetUserInput()

        final ByteArrayInputStream in = new ByteArrayInputStream("one\ntwo".getBytes());
        final UserInput ui = new UserInput(in);
        io.setUserInput(ui);
        assertEquals(ui, io.getUserInput());
        assertEquals("one", io.getUserInput().getLine());
    
public voidtestSetGetUserInputEncoding()

        final ByteArrayInputStream in = new ByteArrayInputStream("one\ntwo".getBytes());
        io.setUserInput(in, "ISO-8859-1");
        final IUserInput ui = io.getUserInput();
        assertEquals("one", ui.getLine());
    
public voidtestSetGetUserInputStream()

        final ByteArrayInputStream in = new ByteArrayInputStream("one\ntwo".getBytes());
        io.setUserInput(in);
        final IUserInput ui = io.getUserInput();
        assertEquals("one", ui.getLine());
    
public voidtestSetGetUserOutputStream()

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        io.setUserOutput(baos);
        final IUserOutput uo = io.getUserOutput();
        uo.print("foo");
//        uo.close();
        assertEquals("foo", baos.toString());
    
public voidtestSetGetUserOutputStreamToFile()

        final File f = File.createTempFile("InputsAndOutputsTest_testSettingOutputStreamToFile", "tmp");
        f.deleteOnExit();
        io.setUserOutputFile(f.toString());
        final IUserOutput uo = io.getUserOutput();
        uo.println("foo");
//        uo.close();
        final BufferedReader fr= new BufferedReader(new FileReader(f));
        assertEquals("foo", fr.readLine());
    
public voidtestSettingUserInputFile()

        final File f = File.createTempFile("InputsAndOutputsTest_testSettingUserInputFile", "tmp");
        f.deleteOnExit();
        final PrintWriter pw = new PrintWriter(new FileWriter(f));
        pw.println("line one");
        pw.println("line two");
        pw.close();
        io.setUserInputFile(f.toString());
        final IUserInput ui = io.getUserInput();
        assertEquals("line one", ui.getLine());
        assertEquals("line two", ui.getLine());
        assertNull(ui.getLine());
    
public voidtestSettingUserInputFileWithEncoding()

        final String enc = "ISO-8859-1";
        final File f = File.createTempFile("InputsAndOutputsTest_testSettingUserInputFileWithEncoding", "tmp");
        f.deleteOnExit();
        final PrintWriter pw = new PrintWriter (new OutputStreamWriter(new FileOutputStream(f), enc));
        pw.println("line one");
        pw.println("line two");
        pw.close();
        io.setUserInputFile(f.toString(), enc);
        final IUserInput ui = io.getUserInput();
        assertEquals("line one", ui.getLine());
        assertEquals("line two", ui.getLine());
        assertNull(ui.getLine());