KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > soda > classes > simple > STByteTestCase


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.common.soda.classes.simple;
22 import com.db4o.*;
23 import com.db4o.query.*;
24
25
26 public class STByteTestCase extends com.db4o.db4ounit.common.soda.util.SodaBaseTestCase{
27     
28     final static String JavaDoc DESCENDANT = "i_byte";
29     
30     public byte i_byte;
31     
32     
33     public STByteTestCase(){
34     }
35     
36     private STByteTestCase(byte a_byte){
37         i_byte = a_byte;
38     }
39     
40     public Object JavaDoc[] createData() {
41         return new Object JavaDoc[]{
42             new STByteTestCase((byte)0),
43             new STByteTestCase((byte)1),
44             new STByteTestCase((byte)99),
45             new STByteTestCase((byte)113)
46         };
47     }
48     
49     public void testEquals(){
50         Query q = newQuery();
51         q.constrain(new STByteTestCase((byte)0));
52         
53         // Primitive default values are ignored, so we need an
54
// additional constraint:
55
q.descend(DESCENDANT).constrain(new Byte JavaDoc((byte)0));
56         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[0]);
57     }
58     
59     public void testNotEquals(){
60         Query q = newQuery();
61         
62         q.constrain(_array[0]);
63         q.descend(DESCENDANT).constrain(new Byte JavaDoc((byte)0)).not();
64         expect(q, new int[] {1, 2, 3});
65     }
66     
67     public void testGreater(){
68         Query q = newQuery();
69         
70         q.constrain(new STByteTestCase((byte)9));
71         q.descend(DESCENDANT).constraints().greater();
72         
73         expect(q, new int[] {2, 3});
74     }
75     
76     public void testSmaller(){
77         Query q = newQuery();
78         
79         q.constrain(new STByteTestCase((byte)1));
80         q.descend(DESCENDANT).constraints().smaller();
81         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, _array[0]);
82     }
83     
84     public void testContains(){
85         Query q = newQuery();
86         
87         q.constrain(new STByteTestCase((byte)9));
88         q.descend(DESCENDANT).constraints().contains();
89         
90         expect(q, new int[] {2});
91     }
92     
93     public void testNotContains(){
94         Query q = newQuery();
95         
96         q.constrain(new STByteTestCase((byte)0));
97         q.descend(DESCENDANT).constrain(new Byte JavaDoc((byte)0)).contains().not();
98         
99         expect(q, new int[] {1, 2, 3});
100     }
101     
102     public void testLike(){
103         Query q = newQuery();
104         q.constrain(new STByteTestCase((byte)11));
105         q.descend(DESCENDANT).constraints().like();
106         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q, new STByteTestCase((byte)113));
107         
108         q = newQuery();
109         q.constrain(new STByteTestCase((byte)10));
110         q.descend(DESCENDANT).constraints().like();
111         expect(q, new int[] {});
112     }
113     
114     public void testNotLike(){
115         Query q = newQuery();
116         
117         q.constrain(new STByteTestCase((byte)1));
118         q.descend(DESCENDANT).constraints().like().not();
119         
120         expect(q, new int[] {0, 2});
121     }
122     
123     public void testIdentity(){
124         Query q = newQuery();
125         q.constrain(new STByteTestCase((byte)1));
126         ObjectSet set = q.execute();
127         STByteTestCase identityConstraint = (STByteTestCase)set.next();
128         identityConstraint.i_byte = 102;
129         q = newQuery();
130         q.constrain(identityConstraint).identity();
131         identityConstraint.i_byte = 1;
132         com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,_array[1]);
133     }
134     
135     public void testNotIdentity(){
136         Query q = newQuery();
137         q.constrain(new STByteTestCase((byte)1));
138         ObjectSet set = q.execute();
139         STByteTestCase identityConstraint = (STByteTestCase)set.next();
140         identityConstraint.i_byte = 102;
141         q = newQuery();
142         q.constrain(identityConstraint).identity().not();
143         identityConstraint.i_byte = 1;
144         
145         expect(q, new int[] {0, 2, 3});
146     }
147     
148     public void testConstraints(){
149         Query q = newQuery();
150         q.constrain(new STByteTestCase((byte)1));
151         q.constrain(new STByteTestCase((byte)0));
152         Constraints cs = q.constraints();
153         Constraint[] csa = cs.toArray();
154         if(csa.length != 2){
155             db4ounit.Assert.fail("Constraints not returned");
156         }
157     }
158     
159 }
160
161
Popular Tags