KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > pmti > v1 > itf > parser > IParserCollatorUTestI


1 /*
2  * @(#)IParserCollatorUTestI.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.pmti.v1.itf.parser;
28
29 import net.sourceforge.groboutils.pmti.v1.itf.*;
30 import net.sourceforge.groboutils.pmti.v1.itf.impl.*;
31
32 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
33 import org.easymock.EasyMock;
34 import org.easymock.MockControl;
35 import net.sourceforge.groboutils.junit.v1.iftc.*;
36 import junit.framework.Test;
37 import junit.framework.TestCase;
38 import junit.framework.TestSuite;
39
40
41 /**
42  * Tests the IParserCollator interface.
43  *
44  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
45  * @since July 14, 2002
46  * @version $Date: 2003/02/10 22:52:09 $
47  */

48 public class IParserCollatorUTestI extends InterfaceTestCase
49 {
50     //-------------------------------------------------------------------------
51
// Standard JUnit Class-specific declarations
52

53     private static final Class JavaDoc THIS_CLASS = IParserCollatorUTestI.class;
54     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
55     
56     public IParserCollatorUTestI( String JavaDoc name, ImplFactory f )
57     {
58         super( name, IParserCollator.class, f );
59     }
60
61     
62     public IParserCollator createIParserCollator()
63     {
64         return (IParserCollator)createImplObject();
65     }
66
67
68     //-------------------------------------------------------------------------
69
// Tests
70

71     public void testAddParser1()
72     {
73         IParserCollator pc = createIParserCollator();
74         pc.addParser( null );
75     }
76     
77     
78     public static class MyParser implements IParser
79     {
80         public ITestIssueRecord[] records;
81         public MyParser()
82         {
83             this.records = new ITestIssueRecord[0];
84         }
85         public MyParser( ITestIssueRecord[] r )
86         {
87             this.records = r;
88         }
89         
90         public ITestIssueRecord[] parse()
91         {
92             return this.records;
93         }
94     }
95
96     
97     public void testAddParser2()
98     {
99         IParserCollator pc = createIParserCollator();
100         pc.addParser( new MyParser() );
101         pc.addParser( new MyParser() );
102     }
103
104     
105     public void testAddParser3()
106     {
107         IParserCollator pc = createIParserCollator();
108         pc.addParser( new MyParser() );
109         pc.getRecords();
110         try
111         {
112             pc.addParser( new MyParser() );
113             fail( "Did not throw IllegalStateException." );
114         }
115         catch (IllegalStateException JavaDoc ise)
116         {
117             // check exception??
118
}
119     }
120     
121     
122     public void testGetRecords1()
123     {
124         IParserCollator pc = createIParserCollator();
125         ITestIssueRecordSet set = pc.getRecords();
126         assertNotNull(
127             "Returned null set.",
128             set );
129         ITestIssueRecord[] records = set.getTestIssueRecords();
130         assertNotNull(
131             "Returned null record array.",
132             records );
133         assertEquals(
134             "Returned a non-empty record set.",
135             0,
136             records.length );
137     }
138     
139     
140     public void testGetRecords2()
141     {
142         IParserCollator pc = createIParserCollator();
143         pc.addParser( new MyParser() );
144         pc.addParser( new MyParser() );
145         ITestIssueRecordSet set = pc.getRecords();
146         assertNotNull(
147             "Returned null set.",
148             set );
149         ITestIssueRecord[] records = set.getTestIssueRecords();
150         assertNotNull(
151             "Returned null record array.",
152             records );
153         assertEquals(
154             "Returned a non-empty record set.",
155             0,
156             records.length );
157     }
158     
159     
160     public void testGetRecords3()
161     {
162         IParserCollator pc = createIParserCollator();
163         ITestIssueRecord[] real = {
164                 createRecord1(),
165             };
166         pc.addParser( new MyParser( real ) );
167         ITestIssueRecordSet set = pc.getRecords();
168         assertNotNull(
169             "Returned null set.",
170             set );
171         assertContainsOnly( set, real );
172     }
173     
174     
175     public void testGetRecords4()
176     {
177         IParserCollator pc = createIParserCollator();
178         ITestIssueRecord[] real = {
179                 createRecord1(),
180                 createRecord2(),
181                 createRecord2(),
182                 createRecord2(),
183                 createRecord3(),
184             };
185         pc.addParser( new MyParser( real ) );
186         pc.addParser( new MyParser() );
187         ITestIssueRecordSet set = pc.getRecords();
188         assertNotNull(
189             "Returned null set.",
190             set );
191         assertContainsOnly( set, real );
192     }
193     
194     
195     //-------------------------------------------------------------------------
196
// Helpers
197

198     
199     
200     /**
201      * NOTE: changes <tt>records</tt>
202      */

203     protected void assertContainsOnly( ITestIssueRecordSet set,
204             ITestIssueRecord[] records )
205     {
206         int foundCount = 0;
207         ITestIssueRecord[] actualRecords = set.getTestIssueRecords();
208         assertNotNull(
209             "test issue record set contains null record array.",
210             actualRecords );
211         for (int arIndex = 0; arIndex < actualRecords.length; ++arIndex)
212         {
213             assertNotNull(
214                 "Returned a null test issue record in set.",
215                 actualRecords[ arIndex ] );
216             boolean foundRecord = false;
217             for (int rIndex = 0; rIndex < records.length; ++rIndex)
218             {
219                 if (records[ rIndex ] != null
220                     && actualRecords[ arIndex ] == records[ rIndex ])
221                 {
222                     foundRecord = true;
223                     ++foundCount;
224                     records[ rIndex ] = null;
225                     break;
226                 }
227             }
228             assertTrue(
229                 "Found record "+actualRecords[ arIndex ]+
230                 " in result set that was not passed into the collate method.",
231                 foundRecord );
232         }
233         
234         assertEquals(
235             "Did not find all the input records to the collate method in its "+
236             "results.",
237             records.length,
238             foundCount );
239             
240     }
241     
242     
243     protected ITestIssueRecord createRecord1()
244     {
245         IIssueRecord ir = new DefaultIssueRecord( "", null );
246         DefaultTestRecord tr = new DefaultTestRecord();
247         ITestIssueRecord tir = new DefaultTestIssueRecord( ir, tr, "text 1" );
248         return tir;
249     }
250     
251     
252     protected ITestIssueRecord createRecord2()
253     {
254         IIssueRecord ir = new DefaultIssueRecord( "", null );
255         DefaultTestRecord tr = new DefaultTestRecord();
256         tr.setTestSuite( "suite" );
257         
258         ITestIssueRecord tir = new DefaultTestIssueRecord( ir, tr, "text 2" );
259         return tir;
260     }
261     
262     
263     protected ITestIssueRecord createRecord3()
264     {
265         IIssueRecord ir = new DefaultIssueRecord( "", null );
266         DefaultTestRecord tr = new DefaultTestRecord();
267         tr.setTestSuite( "suite" );
268         tr.setTestName( "name" );
269         
270         ITestIssueRecord tir = new DefaultTestIssueRecord( ir, tr, "text 3" );
271         return tir;
272     }
273     
274     //-------------------------------------------------------------------------
275
// Standard JUnit declarations
276

277     
278     public static InterfaceTestSuite suite()
279     {
280         InterfaceTestSuite suite = new InterfaceTestSuite( THIS_CLASS );
281         
282         return suite;
283     }
284     
285     public static void main( String JavaDoc[] args )
286     {
287         String JavaDoc[] name = { THIS_CLASS.getName() };
288         
289         // junit.textui.TestRunner.main( name );
290
// junit.swingui.TestRunner.main( name );
291

292         junit.textui.TestRunner.main( name );
293     }
294     
295     
296     /**
297      *
298      * @exception Exception thrown under any exceptional condition.
299      */

300     protected void setUp() throws Exception JavaDoc
301     {
302         super.setUp();
303         
304         // set ourself up
305
}
306     
307     
308     /**
309      *
310      * @exception Exception thrown under any exceptional condition.
311      */

312     protected void tearDown() throws Exception JavaDoc
313     {
314         // tear ourself down
315

316         
317         super.tearDown();
318     }
319 }
320
321
Popular Tags