View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.collections.primitives;
18  
19  import junit.framework.Test;
20  import junit.framework.TestSuite;
21  
22  import org.apache.commons.collections.BulkTest;
23  
24  /**
25   * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $
26   * @author Rodney Waldhoff
27   */
28  public class TestArrayBooleanList extends TestBooleanList {
29  
30      // conventional
31      // ------------------------------------------------------------------------
32  
33      public TestArrayBooleanList(String testName) {
34          super(testName);
35      }
36  
37      public static Test suite() {
38          TestSuite suite = BulkTest.makeSuite(TestArrayBooleanList.class);
39          return suite;
40      }
41  
42      // collections testing framework
43      // ------------------------------------------------------------------------
44  
45      protected BooleanList makeEmptyBooleanList() {
46          return new ArrayBooleanList();
47      }
48  
49      public String[] ignoredTests() {
50          return new String[] { 
51  
52                  // having only two unique values breaks these:
53                  "TestArrayBooleanList.bulkTestSubList.testListEquals",
54                  "TestArrayBooleanList.bulkTestSubList.testCollectionRemoveAll",
55                  "TestArrayBooleanList.bulkTestSubList.testCollectionRetainAll",
56  
57                  // sublists are not serializable                
58              "TestArrayBooleanList.bulkTestSubList.testFullListSerialization",
59              "TestArrayBooleanList.bulkTestSubList.testEmptyListSerialization",
60              "TestArrayBooleanList.bulkTestSubList.testCanonicalEmptyCollectionExists",
61              "TestArrayBooleanList.bulkTestSubList.testCanonicalFullCollectionExists",
62              "TestArrayBooleanList.bulkTestSubList.testEmptyListCompatibility",
63              "TestArrayBooleanList.bulkTestSubList.testFullListCompatibility",
64              "TestArrayBooleanList.bulkTestSubList.testSerializeDeserializeThenCompare",
65              "TestArrayBooleanList.bulkTestSubList.testSimpleSerialization"
66          };
67      }
68  
69      // tests
70      // ------------------------------------------------------------------------
71  
72      /** @TODO need to add serialized form to cvs */
73      public void testCanonicalEmptyCollectionExists() {
74          // XXX FIX ME XXX
75          // need to add a serialized form to cvs
76      }
77  
78      public void testCanonicalFullCollectionExists() {
79          // XXX FIX ME XXX
80          // need to add a serialized form to cvs
81      }
82  
83      public void testEmptyListCompatibility() {
84          // XXX FIX ME XXX
85          // need to add a serialized form to cvs
86      }
87  
88      public void testFullListCompatibility() {
89          // XXX FIX ME XXX
90          // need to add a serialized form to cvs
91      }
92  
93      public void testZeroInitialCapacityIsValid() {
94          assertNotNull(new ArrayBooleanList(0));
95      }
96  
97      public void testNegativeInitialCapacityIsInvalid() {
98          try {
99              new ArrayBooleanList(-1);
100             fail("Expected IllegalArgumentException");
101         } catch(IllegalArgumentException e) {
102             // expected
103         }
104     }
105 
106     public void testCopyConstructor() {
107         ArrayBooleanList expected = new ArrayBooleanList();
108         for(int i=0;i<10;i++) {
109             expected.add(i%2==0);
110         }
111         ArrayBooleanList list = new ArrayBooleanList(expected);
112         assertEquals(10,list.size());
113         assertEquals(expected,list);
114     }
115 
116     public void testCopyConstructorWithNull() {
117         try {
118             new ArrayBooleanList((BooleanCollection) null);
119             fail("Expected NullPointerException");
120         } catch(NullPointerException e) {
121             // expected
122         }
123     }
124 
125     public void testArrayConstructor() {
126         ArrayBooleanList expected = new ArrayBooleanList();
127         for (int i = 0; i < 10; i++) {
128             expected.add(i % 2 == 0);
129         }
130         ArrayBooleanList list = new ArrayBooleanList(expected.toArray());
131         assertEquals(10, list.size());
132         assertEquals(expected, list);
133     }
134 
135     public void testArrayConstructorWithNull() {
136         try {
137             new ArrayBooleanList((boolean[]) null);
138             fail("Expected NullPointerException");
139         } catch (NullPointerException e) {
140             // expected
141         }
142     }
143 
144 
145     public void testTrimToSize() {
146         ArrayBooleanList list = new ArrayBooleanList();
147         for(int j=0;j<3;j++) {
148             assertTrue(list.isEmpty());
149     
150             list.trimToSize();
151     
152             assertTrue(list.isEmpty());
153             
154             for(int i=0;i<10;i++) {
155                 list.add(i%2==0);
156             }
157             
158             for(int i=0;i<10;i++) {
159                 assertEquals(i%2==0,list.get(i));
160             }
161             
162             list.trimToSize();
163     
164             for(int i=0;i<10;i++) {
165                 assertEquals(i%2==0,list.get(i));
166             }
167     
168             for(int i=0;i<5;i++) {
169                 list.removeElement(true);
170             }
171             
172             for(int i=0;i<5;i++) {
173                 assertEquals(false,list.get(i));
174             }
175     
176             list.trimToSize();
177                     
178             for(int i=0;i<5;i++) {
179                 assertEquals(false,list.get(i));
180             }
181 
182             list.trimToSize();
183                     
184             for(int i=0;i<5;i++) {
185                 assertEquals(false,list.get(i));
186             }
187     
188             list.clear();
189         }
190     }
191 
192 }