KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > internal > util > TestIoUtil


1 /*
2  * ========================================================================
3  *
4  * Copyright 2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.internal.util;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 import junit.framework.TestCase;
26
27 /**
28  * Unit tests for the {@link IoUtil} class.
29  *
30  * @version $Id: TestIoUtil.java,v 1.1 2004/05/22 11:34:46 vmassol Exp $
31  */

32 public class TestIoUtil extends TestCase
33 {
34     /**
35      * Verify that the <code>getText()</code> method reads properly all bytes
36      * from an input stream.
37      *
38      * @exception IOException on error
39      */

40     public void testGetTextOk() throws IOException JavaDoc
41     {
42         String JavaDoc expected =
43             "<html><head/>\n<body>A GET request</body>\n</html>\n";
44         ByteArrayInputStream JavaDoc in = new ByteArrayInputStream JavaDoc(expected.getBytes());
45
46         String JavaDoc result = IoUtil.getText(in);
47
48         assertEquals(expected, result);
49     }
50
51     /**
52      * Verify that the <code>getText()</code> method works when the input
53      * stream does not contain any data.
54      *
55      * @exception IOException on error
56      */

57     public void testGetTextEmpty() throws IOException JavaDoc
58     {
59         ByteArrayInputStream JavaDoc in = new ByteArrayInputStream JavaDoc("".getBytes());
60
61         String JavaDoc result = IoUtil.getText(in);
62
63         assertEquals("", result);
64     }
65 }
66
Popular Tags