1 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 [] 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 [] createData() { 44 return new Object [] { 45 new STOwnCollectionTTestCase(), 46 new STOwnCollectionTTestCase(new Object [0]), 47 new STOwnCollectionTTestCase(new Object [] { new Integer (0), new Integer (0)}), 48 new STOwnCollectionTTestCase( 49 new Object [] { 50 new Integer (1), 51 new Integer (17), 52 new Integer (Integer.MAX_VALUE - 1)}), 53 new STOwnCollectionTTestCase( 54 new Object [] { 55 new Integer (3), 56 new Integer (17), 57 new Integer (25), 58 new Integer (Integer.MAX_VALUE - 2)}), 59 new STOwnCollectionTTestCase(new Object [] { "foo", new STElement("bar", "barbar")}), 60 new STOwnCollectionTTestCase(new Object [] { "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 [] { new Integer (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 [] { "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 [] { new Integer (17), new Integer (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 (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 (17)); 100 qElements.constrain(new Integer (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 (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 [] { 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 o) { 145 return myList.contains(o); 146 } 147 148 public Iterator iterator() { 149 return myList.iterator(); 150 } 151 152 public Object [] toArray() { 153 return myList.toArray(); 154 } 155 156 public Object [] toArray(Object [] a) { 157 return myList.toArray(a); 158 } 159 160 public boolean add(Object o) { 161 return myList.add(o); 162 } 163 164 public boolean remove(Object 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 o) { 189 return myList.equals(o); 190 } 191 192 public int hashCode() { 193 return myList.hashCode(); 194 } 195 } 196 } 197 | Popular Tags |