KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > output2 > NbIOTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.output2;
21
22 import java.io.Reader JavaDoc;
23 import junit.framework.TestCase;
24
25 /**
26  *
27  * @author mkleint
28  */

29 public class NbIOTest extends TestCase {
30
31     public NbIOTest(String JavaDoc testName) {
32         super(testName);
33     }
34
35     public void test54117() throws Exception JavaDoc {
36         NbIO io = new NbIO("test");
37         assertFalse(io.isClosed());
38         Reader JavaDoc str = io.getIn();
39         assertNotNull(str);
40         assertEquals(NbIO.IOReader.class, str.getClass());
41         writeText(str);
42         int read = str.read(new char[100]);
43         // not eof..
44
assertTrue(read != -1);
45         writeEof(str);
46         read = str.read(new char[100]);
47         assertTrue(read == -1);
48         //reseting
49
io.getOut().close();
50         io.getErr().close();
51         io.dispose();
52         io.getOut().reset();
53         io.getErr().reset();
54         
55         str = io.getIn();
56         writeText(str);
57         read = str.read(new char[100]);
58         // not eof..
59
assertTrue(read != -1);
60         writeEof(str);
61         read = str.read(new char[100]);
62         assertTrue(read == -1);
63         
64     }
65     
66     private void writeText(final Reader JavaDoc reader) {
67               NbIO.IOReader rdr = (NbIO.IOReader)reader;
68               rdr.pushText("hello");
69
70     }
71     private void writeEof(final Reader JavaDoc reader) {
72               NbIO.IOReader rdr = (NbIO.IOReader)reader;
73               rdr.eof();
74     }
75     
76 }
77
Popular Tags