1 package org.apache.commons.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
26
27
28
29
30 public class CountingStreamUnitTest
31 extends TestCase
32 {
33
34
35
36
37
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 out.close();
47 }
48
49
50
51
52
53
54 public void testByteArray() throws Exception
55 {
56 CountingOnlyOutputStream out = new CountingOnlyOutputStream();
57 byte[] array = new byte[]{1,2,3,4,5};
58 out.write( array );
59 assertEquals( "Wrong number of bytes written.", array.length, out.getCount() );
60 out.close();
61 }
62
63
64
65
66
67
68 public void testByteArrayLenCount() throws Exception
69 {
70 CountingOnlyOutputStream out = new CountingOnlyOutputStream();
71 byte[] array = new byte[]{1,2,3,4,5};
72 int len = 3;
73 out.write( array, 0, len );
74 assertEquals( "Wrong number of bytes written.", len, out.getCount() );
75 out.close();
76 }
77 }