1 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 48 public class IParserCollatorUTestI extends InterfaceTestCase 49 { 50 53 private static final Class THIS_CLASS = IParserCollatorUTestI.class; 54 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 55 56 public IParserCollatorUTestI( String 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 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 ise) 116 { 117 } 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 198 199 200 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 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 [] args ) 286 { 287 String [] name = { THIS_CLASS.getName() }; 288 289 292 junit.textui.TestRunner.main( name ); 293 } 294 295 296 300 protected void setUp() throws Exception 301 { 302 super.setUp(); 303 304 } 306 307 308 312 protected void tearDown() throws Exception 313 { 314 316 317 super.tearDown(); 318 } 319 } 320 321 | Popular Tags |