2
* $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/test/java/org/apache/http/impl/io/TestIdentitynputStream.java $
4
* $Date: 2009-02-14 17:39:33 +0100 (Sat, 14 Feb 2009) $
5
* ====================================================================
6
* Licensed to the Apache Software Foundation (ASF) under one
7
* or more contributor license agreements. See the NOTICE file
8
* distributed with this work for additional information
9
* regarding copyright ownership. The ASF licenses this file
10
* to you under the Apache License, Version 2.0 (the
11
* "License"); you may not use this file except in compliance
12
* with the License. You may obtain a copy of the License at
14
* http://www.apache.org/licenses/LICENSE-2.0
16
* Unless required by applicable law or agreed to in writing,
17
* software distributed under the License is distributed on an
18
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19
* KIND, either express or implied. See the License for the
20
* specific language governing permissions and limitations
22
* ====================================================================
24
* This software consists of voluntary contributions made by many
25
* individuals on behalf of the Apache Software Foundation. For more
26
* information on the Apache Software Foundation, please see
27
* <http://www.apache.org/>.
31
package org.apache.http.impl.io;
33
import org.apache.http.impl.io.IdentityInputStream;
34
import org.apache.http.io.SessionInputBuffer;
35
import org.apache.http.mockup.SessionInputBufferMockup;
37
import junit.framework.Test;
38
import junit.framework.TestCase;
39
import junit.framework.TestSuite;
42
* Simple tests for {@link IdentityInputStream}.
45
public class TestIdentitynputStream extends TestCase {
47
// ------------------------------------------------------------ Constructor
48
public TestIdentitynputStream(String testName) {
52
// ------------------------------------------------------------------- Main
53
public static void main(String args[]) {
54
String[] testCaseName = { TestIdentitynputStream.class.getName() };
55
junit.textui.TestRunner.main(testCaseName);
58
// ------------------------------------------------------- TestCase Methods
60
public static Test suite() {
61
return new TestSuite(TestIdentitynputStream.class);
64
public void testConstructor() throws Exception {
65
SessionInputBuffer receiver = new SessionInputBufferMockup(new byte[] {});
66
new IdentityInputStream(receiver);
68
new IdentityInputStream(null);
69
fail("IllegalArgumentException should have been thrown");
70
} catch (IllegalArgumentException ex) {
75
public void testBasicRead() throws Exception {
76
byte[] input = new byte[] {'a', 'b', 'c'};
77
SessionInputBufferMockup receiver = new SessionInputBufferMockup(input);
78
IdentityInputStream instream = new IdentityInputStream(receiver);
79
byte[] tmp = new byte[2];
80
assertEquals(2, instream.read(tmp, 0, tmp.length));
81
assertEquals('a', tmp[0]);
82
assertEquals('b', tmp[1]);
83
assertEquals('c', instream.read());
84
assertEquals(-1, instream.read(tmp, 0, tmp.length));
85
assertEquals(-1, instream.read());
86
assertEquals(-1, instream.read(tmp, 0, tmp.length));
87
assertEquals(-1, instream.read());
90
public void testClosedCondition() throws Exception {
91
byte[] input = new byte[] {'a', 'b', 'c'};
92
SessionInputBufferMockup receiver = new SessionInputBufferMockup(input);
93
IdentityInputStream instream = new IdentityInputStream(receiver);
98
assertTrue(instream.available() == 0);
99
byte[] tmp = new byte[2];
100
assertEquals(-1, instream.read(tmp, 0, tmp.length));
101
assertEquals(-1, instream.read());
102
assertEquals(-1, instream.read(tmp, 0, tmp.length));
103
assertEquals(-1, instream.read());
106
public void testAvailable() throws Exception {
107
byte[] input = new byte[] {'a', 'b', 'c'};
108
SessionInputBufferMockup receiver = new SessionInputBufferMockup(input);
109
IdentityInputStream instream = new IdentityInputStream(receiver);
110
assertTrue(instream.available() > 0);