KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestPHashMap.java,v 1.3 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.*;
27
import org.apache.log4j.*;
28 import org.enhydra.barracuda.testbed.*;
29
30
31 /**
32  * Test case for PHashMap
33  */

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

45     public TestPHashMap(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 Map 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         PHashMap pmap1 = null;
83         PHashMap pmap2 = null;
84
85         //test an empty list
86
pmap1 = (PHashMap) this.getPMapInstance();
87         pmap2 = (PHashMap) pmap1.clone();
88         assertTrue("Cloned obj==source obj at 1", pmap1!=pmap2);
89         assertEquals("Clone check 1a failed", pmap1, pmap2);
90         assertEquals("Clone check 1b failed", pmap2, pmap1);
91
92         //test a list with some items
93
pmap1 = (PHashMap) this.getPMapInstance();
94         pmap1.put("key1", "foo1");
95         pmap1.put("key2", "foo2");
96         pmap1.put("key3", "foo3");
97         pmap1.put("key4", new Integer JavaDoc(99));
98         pmap1.put("key5", null);
99         pmap2 = (PHashMap) pmap1.clone();
100         assertTrue("Cloned obj==source obj at 2", pmap1!=pmap2);
101         assertEquals("Clone check 2a failed", pmap1, pmap2);
102         assertEquals("Clone check 2b failed", pmap2, pmap1);
103         
104         //test a list with some PData items
105
pmap1 = (PHashMap) this.getPMapInstance();
106         pmap1.put("key1", "foo1");
107         PMap pmTmp = this.getPMapInstance();
108         pmTmp.put("key2a", "blah 1");
109         pmTmp.put("key2b", "blah 2");
110         pmap1.put("key2", pmTmp);
111         pmap2 = (PHashMap) pmap1.clone();
112         assertTrue("Cloned obj==source obj at 3", pmap1!=pmap2);
113         assertEquals("Clone check 3a failed", pmap1, pmap2);
114         assertEquals("Clone check 3b failed", pmap2, pmap1);
115     }
116
117
118     //-------------------- Abstract methods ----------------------
119
public StateMap getStateMap() {
120         return getPMapInstance();
121     }
122
123     public PData getPDataInstance() {
124         return getPMapInstance();
125     }
126
127     public PList getPListInstance() {
128         return new PArrayList();
129     }
130
131     public PMap getPMapInstance() {
132         return new PHashMap();
133     }
134 }
135
Popular Tags