KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > solo > tests > StringListTest


1 /**
2  * $Id: StringListTest.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2003,2005 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2 of the License, or (at your option) any later
9  * version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.solo.tests;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 import junit.framework.TestSuite;
35 import org.apache.tools.ant.BuildException;
36
37 import com.idaremedia.antx.ut.HTC;
38 import com.idaremedia.antx.ut.HTCUtils;
39
40 import com.idaremedia.antx.helpers.InnerString;
41 import com.idaremedia.antx.ownhelpers.LocalTk;
42 import com.idaremedia.antx.solo.StringList;
43
44 /**
45  * Class test for {@linkplain com.idaremedia.antx.solo.StringList StringList}.
46  *
47  * @since JWare/AntX 0.3
48  * @author ssmc, &copy;2003,2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
49  * @version 0.5
50  * @.safety single
51  * @.group impl,test
52  **/

53
54 public final class StringListTest extends HTC
55 {
56     /** <i>PET</i> Test Category. **/
57     public static final String JavaDoc TEST_CATEGORY="CLASS";
58
59
60     /**
61      * Create new StringListTest testcase.
62      **/

63     public StringListTest(String JavaDoc methodName)
64     {
65         super("StringList::",methodName);
66     }
67
68
69     /**
70      * Create full test suite for StringList.
71      **/

72     public static TestSuite suite()
73     {
74         return new TestSuite(StringListTest.class);
75     }
76
77
78     /**
79      * Create baseline test suite for StringList (same as full).
80      **/

81     public static TestSuite baseline()
82     {
83         return suite();
84     }
85
86
87     /**
88      * Make this test (standalone) self-running.
89      **/

90     public static void main(String JavaDoc[] argv)
91     {
92         HTCUtils.quickCheck(suite());
93     }
94
95 // ---------------------------------------------------------------------------------------------------------
96
// --------------------------------------- [ Misc Factory Methods ] ----------------------------------------
97
// ---------------------------------------------------------------------------------------------------------
98

99     final static String JavaDoc PFX="CALL(";
100     final static String JavaDoc SFX=")";
101
102     protected void setUp() throws Exception JavaDoc
103     {
104         configureProjectFromResource("lists.xml");
105     }
106
107     private void addABCStrings(StringList out)
108     {
109         InnerString i= new InnerString();
110         i.setValue("a");
111         out.addConfiguredString(i);
112         i.setValue("b");
113         out.addConfiguredString(i);
114         i.setValue("c");
115         out.addConfiguredString(i);
116         assertFalse(out.isEmpty());
117     }
118
119     private void verifyABCStrings(StringList out, Iterator JavaDoc itr, String JavaDoc who)
120     {
121         assertNotNil(itr);
122         ArrayList JavaDoc sl= new ArrayList JavaDoc();
123         while (itr.hasNext()) {
124             sl.add(itr.next());
125             try {itr.remove();} catch(UnsupportedOperationException JavaDoc igx) {}
126         }
127         assertEqual(sl.size(),3);
128         assertEqual(sl.get(0),"a",who+".item@1");
129         assertEqual(sl.get(1),"b",who+".item@2");
130         assertEqual(sl.get(2),"c",who+".item@3");
131         assertEqual(out.toString(),"a,b,c");//NB:ensure itr didn't zap
132
}
133
134     private void verifyABCStrings(StringList out, String JavaDoc who)
135     {
136         verifyABCStrings(out,out.readonlyIterator(),who);
137         verifyABCStrings(out,out.readonlyStringIterator(),who);
138     }
139
140     private void verifyABCStrings(StringList out, Iterator JavaDoc itr,
141                                   String JavaDoc pfx, String JavaDoc sfx,String JavaDoc who)
142     {
143         assertNotNil(itr);
144         ArrayList JavaDoc sl= new ArrayList JavaDoc();
145         while (itr.hasNext()) {
146             sl.add(itr.next());
147             try {itr.remove();} catch(UnsupportedOperationException JavaDoc igx) {}
148         }
149         assertEqual(sl.size(),3);
150         assertEqual(sl.get(0),pfx+"a"+sfx,who+".item@1");
151         assertEqual(sl.get(1),pfx+"b"+sfx,who+".item@2");
152         assertEqual(sl.get(2),pfx+"c"+sfx,who+".item@3");
153         String JavaDoc X= pfx+"a"+sfx+","+pfx+"b"+sfx+","+pfx+"c"+sfx;
154         assertEqual(out.toString(),X);//NB:ensure itr didn't zap
155
}
156
157     private void verifyABCStrings(StringList out, String JavaDoc pfx, String JavaDoc sfx,String JavaDoc who)
158     {
159         verifyABCStrings(out,out.readonlyIterator(),pfx,sfx,who);
160         verifyABCStrings(out,out.readonlyStringIterator(),pfx,sfx,who);
161     }
162
163 // ---------------------------------------------------------------------------------------------------------
164
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
165
// ---------------------------------------------------------------------------------------------------------
166

167     public void checkBaseline()
168     {
169         //--Ensures setUp() works and can find our xml file!
170
}
171
172     public void testBaseline()
173     {
174         checkBaseline();
175     }
176
177     /** @since JWare/AntX 0.3 **/
178     public void testEmptyStringListOK_AntX03()
179     {
180         runTarget("testEmptyStringListOK_AntX03");
181     }
182
183     /** @since JWare/AntX 0.3 **/
184     public void testConstructor_AntX03()
185     {
186         StringList out = new StringList("a,b,c");
187         verifyABCStrings(out,"ctor(orig)");
188         StringList copy = (StringList)out.clone();
189         verifyABCStrings(copy,"ctor(copy)");
190     }
191
192     /** @since JWare/AntX 0.3 **/
193     public void testAddingStrings_AntX03()
194     {
195         StringList out = new StringList();
196         assertTrue(out.isEmpty());
197         addABCStrings(out);
198         verifyABCStrings(out,"add(orig)");
199         StringList copy = (StringList)out.clone();
200         verifyABCStrings(copy,"add(copy)");
201     }
202
203     /** @since JWare/AntX 0.3 **/
204     public void testPrefixSuffix_AntX03()
205     {
206         StringList out = new StringList();
207         out.setPrefix(PFX);
208         out.setSuffix(SFX);
209         addABCStrings(out);
210         verifyABCStrings(out,PFX,SFX,"pfxsfx(orig.a)");
211         StringList copy = (StringList)out.clone();
212         verifyABCStrings(copy,PFX,SFX,"pfxsfx(copy.a)");
213         copy.setPrefix("BLABLABLA");
214         verifyABCStrings(out,PFX,SFX,"pfxsfx(orig.b)");
215         verifyABCStrings(copy,"BLABLABLA",SFX,"pfxsfx(copy.b)");
216     }
217
218     /** @since JWare/AntX 0.3 **/
219     public void testStringListDelim_AntX03()
220     {
221         runTarget("testStringListDelim_AntX03");
222     }
223
224
225     /** @since JWare/AntX 0.3 **/
226     public void testStringListReferences_AntX03()
227     {
228         runTarget("testStringListReferences_AntX03");
229
230         //Try some stuff here but the JUnit+Ant ClassLoader mess
231
// prevents any meaningful tests w/ references(ssmc)
232
Object JavaDoc o = getProject().getReference("abcstrings");
233         assertNotNil(o);
234         StringList out = new StringList();
235         out.setRefid(LocalTk.referenceFor("abcstrings",getProject()));
236         assertTrue(out.isReference());
237         try { out.setPrefix("phffht"); }
238         catch(BuildException bx) {/*burp*/}
239         try { out.setSuffix("phffht"); }
240         catch(BuildException bx) {/*burp*/}
241     }
242
243
244     /* @since JWare/AntX 0.4 **/
245     public void testStringListFromFiles_AntX04()
246     {
247         runTarget("testStringListFromFiles_AntX04");
248     }
249     
250     
251     /* @since JWare/AntX 0.5 */
252     public void testIncludeOtherStringList_AntX05()
253     {
254         runTarget("testIncludeOtherStringList_AntX05");
255     }
256 }
257
258
259 /* end-of-StringListTest.java */
260
Popular Tags