01: /*
02: * ========================================================================
03: *
04: * Copyright 2004 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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;
23: import java.io.IOException;
24:
25: import junit.framework.TestCase;
26:
27: /**
28: * Unit tests for the {@link IoUtil} class.
29: *
30: * @version $Id: TestIoUtil.java 238991 2004-05-22 11:34:50Z vmassol $
31: */
32: public class TestIoUtil extends TestCase {
33: /**
34: * Verify that the <code>getText()</code> method reads properly all bytes
35: * from an input stream.
36: *
37: * @exception IOException on error
38: */
39: public void testGetTextOk() throws IOException {
40: String expected = "<html><head/>\n<body>A GET request</body>\n</html>\n";
41: ByteArrayInputStream in = new ByteArrayInputStream(expected
42: .getBytes());
43:
44: String result = IoUtil.getText(in);
45:
46: assertEquals(expected, result);
47: }
48:
49: /**
50: * Verify that the <code>getText()</code> method works when the input
51: * stream does not contain any data.
52: *
53: * @exception IOException on error
54: */
55: public void testGetTextEmpty() throws IOException {
56: ByteArrayInputStream in = new ByteArrayInputStream(""
57: .getBytes());
58:
59: String result = IoUtil.getText(in);
60:
61: assertEquals("", result);
62: }
63: }
|