1 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 46 public class ITestIssueRecordCollatorUTestI extends InterfaceTestCase 47 { 48 51 private static final Class THIS_CLASS = ITestIssueRecordCollatorUTestI.class; 52 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 53 54 public ITestIssueRecordCollatorUTestI( String 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 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 171 172 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 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 [] args ) 264 { 265 String [] name = { THIS_CLASS.getName() }; 266 267 270 junit.textui.TestRunner.main( name ); 271 } 272 273 274 278 protected void setUp() throws Exception 279 { 280 super.setUp(); 281 282 } 284 285 286 290 protected void tearDown() throws Exception 291 { 292 294 295 super.tearDown(); 296 } 297 } 298 299 | Popular Tags |