| Home >> All >> org >> apache >> http >> [ io Javadoc ] |
Source code: org/apache/http/io/TestIdentityOutputStream.java
1 /* 2 * $HeadURL: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/tags/4.0-alpha2/src/test/org/apache/http/io/TestIdentityOutputStream.java $ 3 * $Revision: 321483 $ 4 * $Date: 2005-10-15 22:32:14 +0200 (Sat, 15 Oct 2005) $ 5 * ==================================================================== 6 * 7 * Copyright 2002-2004 The Apache Software Foundation 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * ==================================================================== 21 * 22 * This software consists of voluntary contributions made by many 23 * individuals on behalf of the Apache Software Foundation. For more 24 * information on the Apache Software Foundation, please see 25 * <http://www.apache.org/>. 26 * 27 */ 28 29 package org.apache.http.io; 30 31 import java.io.ByteArrayOutputStream; 32 import java.io.IOException; 33 import java.io.OutputStream; 34 35 import org.apache.http.mockup.HttpDataTransmitterMockup; 36 37 import junit.framework.Test; 38 import junit.framework.TestCase; 39 import junit.framework.TestSuite; 40 41 public class TestIdentityOutputStream extends TestCase { 42 43 public TestIdentityOutputStream(String testName) { 44 super(testName); 45 } 46 47 // ------------------------------------------------------- TestCase Methods 48 49 public static Test suite() { 50 return new TestSuite(TestIdentityOutputStream.class); 51 } 52 53 // ------------------------------------------------------------------- Main 54 public static void main(String args[]) { 55 String[] testCaseName = { TestIdentityOutputStream.class.getName() }; 56 junit.textui.TestRunner.main(testCaseName); 57 } 58 59 public void testConstructors() throws Exception { 60 new IdentityOutputStream(new HttpDataTransmitterMockup()); 61 try { 62 new IdentityOutputStream(null); 63 fail("IllegalArgumentException should have been thrown"); 64 } catch (IllegalArgumentException ex) { 65 // expected 66 } 67 } 68 69 public void testBasics() throws Exception { 70 ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 71 HttpDataTransmitterMockup datatransmitter = new HttpDataTransmitterMockup(buffer); 72 OutputStream out = new IdentityOutputStream(datatransmitter); 73 74 byte[] tmp = new byte[10]; 75 out.write(tmp, 0, 10); 76 out.write(tmp); 77 out.write(1); 78 out.flush(); 79 out.close(); 80 byte[] data = datatransmitter.getData(); 81 assertEquals(21, data.length); 82 } 83 84 public void testClose() throws Exception { 85 ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 86 HttpDataTransmitterMockup datatransmitter = new HttpDataTransmitterMockup(buffer); 87 OutputStream out = new IdentityOutputStream(datatransmitter); 88 out.close(); 89 out.close(); 90 byte[] tmp = new byte[10]; 91 try { 92 out.write(tmp); 93 fail("IOException should have been thrown"); 94 } catch (IOException ex) { 95 // expected 96 } 97 try { 98 out.write(1); 99 fail("IOException should have been thrown"); 100 } catch (IOException ex) { 101 // expected 102 } 103 } 104 105 } 106