01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: 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.jre5.collections;
22:
23: import com.db4o.collections.*;
24: import com.db4o.ext.*;
25: import com.db4o.reflect.*;
26:
27: import db4ounit.*;
28: import db4ounit.extensions.*;
29:
30: /**
31: * @exclude
32: */
33: public class CollectionsUtil {
34: @SuppressWarnings("unchecked")
35: public static ArrayList4<Integer> retrieveAndAssertNullArrayList4(
36: ExtObjectContainer oc, Reflector reflector)
37: throws Exception {
38: ArrayList4<Integer> list = (ArrayList4<Integer>) AbstractDb4oTestCase
39: .retrieveOnlyInstance(oc, ArrayList4.class);
40: assertNullArrayList4(list, reflector);
41: return list;
42: }
43:
44: private static void assertNullArrayList4(ArrayList4<Integer> list,
45: Reflector reflector) throws Exception {
46: Assert.isNull(getField(reflector, list, "elements"));
47: Assert.areEqual(0, getField(reflector, list, "capacity"));
48: Assert.areEqual(0, getField(reflector, list, "listSize"));
49: }
50:
51: private static Object getField(Reflector reflector, Object parent,
52: String fieldName) {
53: ReflectClass parentClazz = reflector.forObject(parent);
54: ReflectField field = parentClazz.getDeclaredField(fieldName);
55: field.setAccessible();
56: return field.get(parent);
57: }
58:
59: private static void assertRetrieveStatus(Reflector reflector,
60: ArrayMap4<String, Integer> map) {
61: Assert.isNull(getField(reflector, map, "_keys"));
62: Assert.isNull(getField(reflector, map, "_values"));
63: Assert.areEqual(0, getField(reflector, map, "_startIndex"));
64: Assert.areEqual(0, getField(reflector, map, "_endIndex"));
65: }
66:
67: @SuppressWarnings("unchecked")
68: public static ArrayMap4<String, Integer> retrieveMapFromDB(
69: ExtObjectContainer oc, Reflector reflector) {
70: ArrayMap4<String, Integer> map = (ArrayMap4<String, Integer>) AbstractDb4oTestCase
71: .retrieveOnlyInstance(oc, ArrayMap4.class);
72: assertRetrieveStatus(reflector, map);
73: return map;
74: }
75: }
|