KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > pmti > v1 > itf > ITestIssueRecordCollatorUTestI


1 /*
2  * @(#)ITestIssueRecordCollatorUTestI.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;
28
29 import net.sourceforge.groboutils.pmti.v1.itf.impl.*;
30 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
31 import org.easymock.EasyMock;
32 import org.easymock.MockControl;
33 import net.sourceforge.groboutils.junit.v1.iftc.*;
34 import junit.framework.Test;
35 import junit.framework.TestCase;
36 import junit.framework.TestSuite;
37
38
39 /**
40  * Tests the ITestIssueRecordCollator interface.
41  *
42  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
43  * @since July 14, 2002
44  * @version $Date: 2003/02/10 22:52:05 $
45  */

46 public class ITestIssueRecordCollatorUTestI extends InterfaceTestCase
47 {
48     //-------------------------------------------------------------------------
49
// Standard JUnit Class-specific declarations
50

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

69     
70     
71     
72     public void testCollate1()
73     {
74         ITestIssueRecordCollator tirc = createITestIssueRecordCollator();
75         ITestIssueRecordSet sets[] = tirc.collate( null );
76         assertNotNull(
77             "result is null.",
78             sets );
79         assertEquals(
80             "has non-empty result.",
81             0,
82             sets.length );
83     }
84     
85     
86     public void testCollate2()
87     {
88         ITestIssueRecordCollator tirc = createITestIssueRecordCollator();
89         ITestIssueRecord[] records = new ITestIssueRecord[0];
90         ITestIssueRecordSet sets[] = tirc.collate( records );
91         assertNotNull(
92             "result is null.",
93             sets );
94         assertEquals(
95             "has non-empty result.",
96             0,
97             sets.length );
98     }
99     
100     
101     public void testCollate3()
102     {
103         ITestIssueRecordCollator tirc = createITestIssueRecordCollator();
104         ITestIssueRecord[] records = {
105                 createRecord1(),
106             };
107         ITestIssueRecordSet sets[] = tirc.collate( records );
108         assertNotNull(
109             "result is null.",
110             sets );
111         assertEquals(
112             "Can only have one set.",
113             1,
114             sets.length );
115         ITestIssueRecord retRecords[] = sets[0].getTestIssueRecords();
116         assertNotNull(
117             "Must not have null record array returned.",
118             retRecords );
119         assertEquals(
120             "Must only have one record.",
121             1,
122             retRecords.length );
123         assertEquals(
124             "Did not return the input record.",
125             records[0],
126             retRecords[0] );
127         assertContainsOnly( sets, records );
128     }
129     
130     
131     public void testCollate4()
132     {
133         ITestIssueRecordCollator tirc = createITestIssueRecordCollator();
134         ITestIssueRecord[] records = {
135                 createRecord1(),
136                 createRecord1(),
137             };
138         ITestIssueRecordSet sets[] = tirc.collate( records );
139         assertNotNull(
140             "result is null.",
141             sets );
142         assertContainsOnly( sets, records );
143     }
144     
145     
146     public void testCollate5()
147     {
148         ITestIssueRecordCollator tirc = createITestIssueRecordCollator();
149         ITestIssueRecord[] records = {
150                 createRecord1(),
151                 createRecord1(),
152                 createRecord2(),
153                 createRecord3(),
154                 createRecord3(),
155                 createRecord3(),
156             };
157         ITestIssueRecordSet sets[] = tirc.collate( records );
158         assertNotNull(
159             "result is null.",
160             sets );
161         assertContainsOnly( sets, records );
162     }
163     
164     
165     
166
167
168     //-------------------------------------------------------------------------
169
// Helpers
170

171     
172     /**
173      * NOTE: changes <tt>records</tt>
174      */

175     protected void assertContainsOnly( ITestIssueRecordSet sets[],
176             ITestIssueRecord[] records )
177     {
178         int foundCount = 0;
179         for (int i = 0; i < sets.length; ++i)
180         {
181             ITestIssueRecordSet set = sets[i];
182             ITestIssueRecord[] actualRecords = set.getTestIssueRecords();
183             assertNotNull(
184                 "test issue record set "+i+" contains null record array.",
185                 actualRecords );
186             for (int arIndex = 0; arIndex < actualRecords.length; ++arIndex)
187             {
188                 assertNotNull(
189                     "Returned a null test issue record in set "+i+".",
190                     actualRecords[ arIndex ] );
191                 boolean foundRecord = false;
192                 for (int rIndex = 0; rIndex < records.length; ++rIndex)
193                 {
194                     if (records[ rIndex ] != null
195                         && actualRecords[ arIndex ] == records[ rIndex ])
196                     {
197                         foundRecord = true;
198                         ++foundCount;
199                         records[ rIndex ] = null;
200                         break;
201                     }
202                 }
203                 assertTrue(
204                     "Found record "+actualRecords[ arIndex ]+
205                     " in result set "+i+
206                     " that was not passed into the collate method.",
207                     foundRecord );
208             }
209         }
210         
211         assertEquals(
212             "Did not find all the input records to the collate method in its "+
213             "results.",
214             records.length,
215             foundCount );
216             
217     }
218     
219     
220     protected ITestIssueRecord createRecord1()
221     {
222         IIssueRecord ir = new DefaultIssueRecord( "", null );
223         DefaultTestRecord tr = new DefaultTestRecord();
224         ITestIssueRecord tir = new DefaultTestIssueRecord( ir, tr, "text 1" );
225         return tir;
226     }
227     
228     
229     protected ITestIssueRecord createRecord2()
230     {
231         IIssueRecord ir = new DefaultIssueRecord( "", null );
232         DefaultTestRecord tr = new DefaultTestRecord();
233         tr.setTestSuite( "suite" );
234         
235         ITestIssueRecord tir = new DefaultTestIssueRecord( ir, tr, "text 2" );
236         return tir;
237     }
238     
239     
240     protected ITestIssueRecord createRecord3()
241     {
242         IIssueRecord ir = new DefaultIssueRecord( "", null );
243         DefaultTestRecord tr = new DefaultTestRecord();
244         tr.setTestSuite( "suite" );
245         tr.setTestName( "name" );
246         
247         ITestIssueRecord tir = new DefaultTestIssueRecord( ir, tr, "text 3" );
248         return tir;
249     }
250     
251     
252     //-------------------------------------------------------------------------
253
// Standard JUnit declarations
254

255     
256     public static InterfaceTestSuite suite()
257     {
258         InterfaceTestSuite suite = new InterfaceTestSuite( THIS_CLASS );
259         
260         return suite;
261     }
262     
263     public static void main( String JavaDoc[] args )
264     {
265         String JavaDoc[] name = { THIS_CLASS.getName() };
266         
267         // junit.textui.TestRunner.main( name );
268
// junit.swingui.TestRunner.main( name );
269

270         junit.textui.TestRunner.main( name );
271     }
272     
273     
274     /**
275      *
276      * @exception Exception thrown under any exceptional condition.
277      */

278     protected void setUp() throws Exception JavaDoc
279     {
280         super.setUp();
281         
282         // set ourself up
283
}
284     
285     
286     /**
287      *
288      * @exception Exception thrown under any exceptional condition.
289      */

290     protected void tearDown() throws Exception JavaDoc
291     {
292         // tear ourself down
293

294         
295         super.tearDown();
296     }
297 }
298
299
Popular Tags