1 package org.apache.jcs.admin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 /***
25 * Tests for the counting only output stream.
26 *
27 * @author Aaron Smuts
28 *
29 */
30 public class CountingStreamUnitTest
31 extends TestCase
32 {
33
34 /***
35 * Write a single byte and verify the count.
36 *
37 * @throws Exception
38 */
39 public void testSingleByte() throws Exception
40 {
41 CountingOnlyOutputStream out = new CountingOnlyOutputStream();
42 out.write( 1 );
43 assertEquals( "Wrong number of bytes written.", 1, out.getCount() );
44 out.write( 1 );
45 assertEquals( "Wrong number of bytes written.", 2, out.getCount() );
46 }
47
48 /***
49 * This should count the size of the array.
50 *
51 * @throws Exception
52 */
53 public void testByteArray() throws Exception
54 {
55 CountingOnlyOutputStream out = new CountingOnlyOutputStream();
56 byte[] array = new byte[]{1,2,3,4,5};
57 out.write( array );
58 assertEquals( "Wrong number of bytes written.", array.length, out.getCount() );
59 }
60
61 /***
62 * This should count the len -- the tird arg
63 *
64 * @throws Exception
65 */
66 public void testByteArrayLenCount() throws Exception
67 {
68 CountingOnlyOutputStream out = new CountingOnlyOutputStream();
69 byte[] array = new byte[]{1,2,3,4,5};
70 int len = 3;
71 out.write( array, 0, len );
72 assertEquals( "Wrong number of bytes written.", len, out.getCount() );
73 }
74 }