KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > jre12 > soda > collections > STOwnCollectionTTestCase


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.db4ounit.jre12.soda.collections;
22 import java.util.*;
23
24 import com.db4o.query.*;
25
26
27
28 public class STOwnCollectionTTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
29
30     MyCollection col;
31
32     public STOwnCollectionTTestCase() {
33
34     }
35
36     public STOwnCollectionTTestCase(Object JavaDoc[] arr) {
37         col = new MyCollection();
38         for (int i = 0; i < arr.length; i++) {
39             col.add(arr[i]);
40         }
41     }
42     
43     public Object JavaDoc[] createData() {
44         return new Object JavaDoc[] {
45             new STOwnCollectionTTestCase(),
46             new STOwnCollectionTTestCase(new Object JavaDoc[0]),
47             new STOwnCollectionTTestCase(new Object JavaDoc[] { new Integer JavaDoc(0), new Integer JavaDoc(0)}),
48             new STOwnCollectionTTestCase(
49                 new Object JavaDoc[] {
50                     new Integer JavaDoc(1),
51                     new Integer JavaDoc(17),
52                     new Integer JavaDoc(Integer.MAX_VALUE - 1)}),
53             new STOwnCollectionTTestCase(
54                 new Object JavaDoc[] {
55                     new Integer JavaDoc(3),
56                     new Integer JavaDoc(17),
57                     new Integer JavaDoc(25),
58                     new Integer JavaDoc(Integer.MAX_VALUE - 2)}),
59             new STOwnCollectionTTestCase(new Object JavaDoc[] { "foo", new STElement("bar", "barbar")}),
60             new STOwnCollectionTTestCase(new Object JavaDoc[] { "foo2", new STElement("bar", "barbar2")})
61         };
62     }
63     
64
65     public void testDefaultContainsInteger() {
66         Query q = newQuery();
67         
68         q.constrain(new STOwnCollectionTTestCase(new Object JavaDoc[] { new Integer JavaDoc(17)}));
69         expect(q, new int[] { 3, 4 });
70     }
71
72     public void testDefaultContainsString() {
73         Query q = newQuery();
74         
75         q.constrain(new STOwnCollectionTTestCase(new Object JavaDoc[] { "foo" }));
76         expect(q, new int[] { 5 });
77     }
78
79     public void testDefaultContainsTwo() {
80         Query q = newQuery();
81         
82         q.constrain(new STOwnCollectionTTestCase(new Object JavaDoc[] { new Integer JavaDoc(17), new Integer JavaDoc(25)}));
83         expect(q, new int[] { 4 });
84     }
85
86     public void testDescendOne() {
87         Query q = newQuery();
88         
89         q.constrain(STOwnCollectionTTestCase.class);
90         q.descend("col").constrain(new Integer JavaDoc(17));
91         expect(q, new int[] { 3, 4 });
92     }
93
94     public void testDescendTwo() {
95         Query q = newQuery();
96         
97         q.constrain(STOwnCollectionTTestCase.class);
98         Query qElements = q.descend("col");
99         qElements.constrain(new Integer JavaDoc(17));
100         qElements.constrain(new Integer JavaDoc(25));
101         expect(q, new int[] { 4 });
102     }
103
104     public void testDescendSmaller() {
105         Query q = newQuery();
106         
107         q.constrain(STOwnCollectionTTestCase.class);
108         Query qElements = q.descend("col");
109         qElements.constrain(new Integer JavaDoc(3)).smaller();
110         expect(q, new int[] { 2, 3 });
111     }
112
113     public void testDefaultContainsObject() {
114         Query q = newQuery();
115         
116         q.constrain(new STOwnCollectionTTestCase(new Object JavaDoc[] { new STElement("bar", null)}));
117         expect(q, new int[] { 5, 6 });
118     }
119
120     public void testDescendToObject() {
121         Query q = newQuery();
122         
123         q.constrain(new STOwnCollectionTTestCase());
124         q.descend("col").descend("foo1").constrain("bar");
125         expect(q, new int[] { 5, 6 });
126     }
127
128     public static class MyCollection implements Collection {
129         
130         ArrayList myList;
131         
132         public MyCollection(){
133             myList = new ArrayList();
134         }
135         
136         public int size() {
137             return myList.size();
138         }
139
140         public boolean isEmpty() {
141             return myList.isEmpty();
142         }
143
144         public boolean contains(Object JavaDoc o) {
145             return myList.contains(o);
146         }
147
148         public Iterator iterator() {
149             return myList.iterator();
150         }
151
152         public Object JavaDoc[] toArray() {
153             return myList.toArray();
154         }
155
156         public Object JavaDoc[] toArray(Object JavaDoc[] a) {
157             return myList.toArray(a);
158         }
159
160         public boolean add(Object JavaDoc o) {
161             return myList.add(o);
162         }
163
164         public boolean remove(Object JavaDoc o) {
165             return myList.remove(o);
166         }
167
168         public boolean containsAll(Collection c) {
169             return myList.containsAll(c);
170         }
171
172         public boolean addAll(Collection c) {
173             return myList.addAll(c);
174         }
175
176         public boolean removeAll(Collection c) {
177             return myList.removeAll(c);
178         }
179
180         public boolean retainAll(Collection c) {
181             return myList.retainAll(c);
182         }
183
184         public void clear() {
185             myList.clear();
186         }
187
188         public boolean equals(Object JavaDoc o) {
189             return myList.equals(o);
190         }
191
192         public int hashCode() {
193             return myList.hashCode();
194         }
195     }
196 }
197
Popular Tags