KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > data > TestPArrayList


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: TestPArrayList.java,v 1.2 2004/02/01 05:16:33 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton.data;
21
22 import java.util.*;
23
24 import junit.framework.*;
25
26 //import org.enhydra.barracuda.plankton.data.Collections;
27
import org.apache.log4j.*;
28 import org.enhydra.barracuda.testbed.*;
29
30
31 /**
32  * Test case for any PList
33  */

34 public class TestPArrayList extends PListTestCases {
35     //common vars (customize for every test class)
36
static {
37         testClass = TestPArrayList.class.getName();
38         logger = Logger.getLogger("test."+testClass);
39     }
40     
41     //-------------------- Basics --------------------------------
42
/**
43      * Public Constructor
44      */

45     public TestPArrayList(String JavaDoc name) {
46         super(name);
47     }
48     
49     /**
50      * Every test class should have a main method so it can be run
51      * directly (when debugging tests you often will not want to run
52      * the whole suite)
53      *
54      * @param args defined in test.util.TestUtil
55      */

56     public static void main(String JavaDoc args[]) {
57         //check for standard runtime parameters
58
TestUtil.parseParams(args);
59
60         //launch the test
61
if (TestUtil.BATCH_MODE) junit.textui.TestRunner.main(new String JavaDoc[] {testClass});
62         else junit.swingui.TestRunner.main(new String JavaDoc[] {testClass});
63     }
64
65     
66     //-------------------- Actual Tests --------------------------
67
//Note: all the methods herein should follow the testXXXX naming convention
68
//Also keep in mind that local vars set in one test method are NOT retained
69
//when the next method is invoked because JUnit makes a separate instance of
70
//the test class for each testXXXX method!!!
71

72     //NOTE: most of the individual tests are actually inherited
73
//from the parent class
74

75     /**
76      * Verify the clone (we have to test this here instead
77      * the clone method is not part of the List interface...we need
78      * a concrete implementation in order to be able to reference it)
79      */

80     public void testClone() {
81         if (logger.isInfoEnabled()) logger.info("testing clone()");
82
83         //test an empty list
84
PArrayList plist1 = (PArrayList) this.getPListInstance();
85         PArrayList plist2 = (PArrayList) plist1.clone();
86         assertTrue("Cloned obj==source obj at 1", plist1!=plist2);
87         assertEquals("Clone check 1a failed", plist1, plist2);
88         assertEquals("Clone check 1b failed", plist2, plist1);
89
90         //test a list with some items
91
plist1 = (PArrayList) this.getPListInstance();
92         plist1.add("foo1");
93         plist1.add("foo2");
94         plist1.add("foo3");
95         plist1.add(new Integer JavaDoc(99));
96         plist1.add(null);
97         plist2 = (PArrayList) plist1.clone();
98         assertTrue("Cloned obj==source obj at 2", plist1!=plist2);
99         assertEquals("Clone check 2a failed", plist1, plist2);
100         assertEquals("Clone check 2b failed", plist2, plist1);
101         
102         //test a list with some PData items
103
plist1 = (PArrayList) this.getPListInstance();
104         plist1.add("foo1");
105         PList plTmp = this.getPListInstance();
106         plTmp.add("blah 1");
107         plTmp.add("blah 2");
108         plist1.add(plTmp);
109         plist2 = (PArrayList) plist1.clone();
110         assertTrue("Cloned obj==source obj at 3", plist1!=plist2);
111         assertEquals("Clone check 3a failed", plist1, plist2);
112         assertEquals("Clone check 3b failed", plist2, plist1);
113     }
114
115     //-------------------- Abstract methods ----------------------
116
public StateMap getStateMap() {
117         return getPListInstance();
118     }
119
120     public PData getPDataInstance() {
121         return getPListInstance();
122     }
123
124     public PList getPListInstance() {
125         return new PArrayList();
126     }
127
128     public PMap getPMapInstance() {
129         return new PHashMap();
130     }
131 }
132
Popular Tags