01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.util;
17:
18: import org.kuali.kfs.context.KualiTestBase;
19: import org.kuali.module.chart.bo.Account;
20: import org.kuali.module.chart.bo.ProjectCode;
21:
22: /**
23: * This class tests the TypedArrayList methods.
24: */
25: public class TypedArrayListTest extends KualiTestBase {
26:
27: /**
28: * TypedArrayList should have to be initialized with a type.
29: */
30: public final void testInitialization() {
31: TypedArrayList list;
32: // should throw runtime
33: try {
34: list = new TypedArrayList(null);
35: fail("TypedArrayList accepted null initialization.");
36: } catch (RuntimeException e) {
37: }
38:
39: list = new TypedArrayList(Account.class);
40: assertEquals("Class not properly initialized", Account.class
41: .getName(), list.getListObjectType().getName());
42: }
43:
44: /**
45: * TypedArrayList should only allow objects of the initialized type to be added.
46: */
47: public final void testAdd() {
48: TypedArrayList list = new TypedArrayList(Account.class);
49: list.add(new Account());
50: assertTrue(list.get(0) instanceof Account);
51:
52: // should throw runtime
53: try {
54: list.add(new ProjectCode());
55: fail("TypedArrayList allowed add of wrong type");
56: } catch (RuntimeException e) {
57: }
58: }
59:
60: /**
61: * TypedArrayList will grow the list with the type if an index greater than the current size is requested.
62: */
63: public final void testGrow() {
64: TypedArrayList list = new TypedArrayList(Account.class);
65: list.add(new Account());
66: assertTrue(list.size() == 1);
67:
68: Object object = list.get(1);
69: assertTrue(object != null && object instanceof Account);
70: assertTrue(list.size() == 2);
71:
72: object = list.get(5);
73: assertTrue(object != null && object instanceof Account);
74: object = list.get(3);
75: assertTrue(object != null && object instanceof Account);
76: assertTrue(list.size() == 6);
77: }
78:
79: }
|