1   package org.apache.jcs.admin;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }