KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > util > DataByteArrayOutputStreamTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. 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 package org.apache.activemq.util;
19
20 import junit.framework.TestCase;
21
22 import java.io.IOException JavaDoc;
23
24 public class DataByteArrayOutputStreamTest extends TestCase {
25
26     /**
27      * This test case assumes that an ArrayIndexOutOfBoundsException will be thrown when the buffer fails to resize
28      * @throws IOException
29      */

30     public void testResize() throws IOException JavaDoc {
31         int initSize = 64;
32         DataByteArrayOutputStream out = new DataByteArrayOutputStream();
33
34         fillOut(out, initSize);
35         // Should resized here
36
out.writeBoolean(true);
37
38         fillOut(out, initSize);
39         // Should resized here
40
out.writeByte(1);
41
42         fillOut(out, initSize);
43         // Should resized here
44
out.writeBytes("test");
45
46         fillOut(out, initSize);
47         // Should resized here
48
out.writeChar('C');
49
50         fillOut(out, initSize);
51         // Should resized here
52
out.writeChars("test");
53
54         fillOut(out, initSize);
55         // Should resized here
56
out.writeDouble(3.1416);
57
58         fillOut(out, initSize);
59         // Should resized here
60
out.writeFloat((float)3.1416);
61
62         fillOut(out, initSize);
63         // Should resized here
64
out.writeInt(12345);
65
66         fillOut(out, initSize);
67         // Should resized here
68
out.writeLong(12345);
69
70         fillOut(out, initSize);
71         // Should resized here
72
out.writeShort(1234);
73
74         fillOut(out, initSize);
75         // Should resized here
76
out.writeUTF("test");
77
78         fillOut(out, initSize);
79         // Should resized here
80
out.write(1234);
81
82         fillOut(out, initSize);
83         // Should resized here
84
out.write(new byte[10], 5, 5);
85
86         fillOut(out, initSize);
87         // Should resized here
88
out.write(new byte[10]);
89     }
90
91     /**
92      * This method restarts the stream to the init size, and fills it up with data
93      * @param out
94      * @param size
95      * @throws IOException
96      */

97     public void fillOut(DataByteArrayOutputStream out, int size) throws IOException JavaDoc {
98         out.restart(size);
99         out.write(new byte[size]);
100     }
101 }
102
Popular Tags