1 32 33 package com.jeantessier.diff; 34 35 import java.io.*; 36 import java.util.*; 37 38 import junit.framework.*; 39 40 import com.jeantessier.classreader.*; 41 42 public class TestDifferencesFactory extends TestCase { 43 public static final String OLD_CLASSPATH = "tests" + File.separator + "JarJarDiff" + File.separator + "old"; 44 public static final String NEW_CLASSPATH = "tests" + File.separator + "JarJarDiff" + File.separator + "new"; 45 46 private JarDifferences jarDifferences; 47 48 protected void setUp() throws Exception { 49 ClassfileLoader oldJar = new AggregatingClassfileLoader(); 50 oldJar.load(Collections.singleton(OLD_CLASSPATH)); 51 52 ClassfileLoader newJar = new AggregatingClassfileLoader(); 53 newJar.load(Collections.singleton(NEW_CLASSPATH)); 54 55 Validator oldValidator = new ListBasedValidator(new BufferedReader(new FileReader(OLD_CLASSPATH + ".txt"))); 56 Validator newValidator = new ListBasedValidator(new BufferedReader(new FileReader(NEW_CLASSPATH + ".txt"))); 57 58 DifferencesFactory factory = new DifferencesFactory(oldValidator, newValidator); 59 jarDifferences = (JarDifferences) factory.createJarDifferences("test", "old", oldJar, "new", newJar); 60 } 61 62 public void testEmpty() throws IOException { 63 Validator validator = new ListBasedValidator(new BufferedReader(new StringReader(""))); 64 DifferencesFactory factory = new DifferencesFactory(validator, validator); 65 JarDifferences emptyDifferences = (JarDifferences) factory.createJarDifferences("test", "old", new AggregatingClassfileLoader(), "new", new AggregatingClassfileLoader()); 66 67 assertEquals("name", "test", emptyDifferences.getName()); 68 assertEquals("old version", "old", emptyDifferences.getOldVersion()); 69 assertEquals("new version", "new", emptyDifferences.getNewVersion()); 70 71 assertTrue("IsEmpty()", emptyDifferences.isEmpty()); 72 73 assertTrue("!IsEmpty()", !jarDifferences.isEmpty()); 74 assertEquals("NbPackageDifferences: " + jarDifferences.getPackageDifferences(), 5, jarDifferences.getPackageDifferences().size()); 75 } 76 77 public void testDocumentedPackage() { 78 String name = "DocumentedPackage"; 79 DocumentableDifferences documentableDifferences = (DocumentableDifferences) find(name, jarDifferences.getPackageDifferences()); 80 PackageDifferences differences = (PackageDifferences) documentableDifferences.getComponent(); 81 assertNotNull(name, differences); 82 83 assertTrue(name + ".NewDocumentation()", documentableDifferences.isNewDocumentation()); 84 assertTrue(name + ".Remove Documentation()", !documentableDifferences.isRemovedDocumentation()); 85 assertTrue(name + ".IsEmpty()", !documentableDifferences.isEmpty()); 86 87 assertEquals(name, differences.getName()); 88 assertEquals(name + ".ClassDifferences: " + differences.getClassDifferences(), 1, differences.getClassDifferences().size()); 89 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 90 assertTrue(name + ".IsModified()", differences.isModified()); 91 assertTrue(name + ".IsNew()", !differences.isNew()); 92 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 93 } 94 95 public void testModifiedPackage() { 96 String name = "ModifiedPackage"; 97 PackageDifferences differences = (PackageDifferences) find(name, jarDifferences.getPackageDifferences()); 98 assertNotNull(name, differences); 99 100 assertEquals(name, differences.getName()); 101 assertEquals(name + ".ClassDifferences: " + differences.getClassDifferences(), 14, differences.getClassDifferences().size()); 102 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 103 assertTrue(name + ".IsModified()", differences.isModified()); 104 assertTrue(name + ".IsNew()", !differences.isNew()); 105 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 106 } 107 108 public void testNewPackage() { 109 String name = "NewPackage"; 110 PackageDifferences differences = (PackageDifferences) find(name, jarDifferences.getPackageDifferences()); 111 assertNotNull(name, differences); 112 113 assertEquals(name, differences.getName()); 114 assertEquals(name + ".ClassDifferences: " + differences.getClassDifferences(), 0, differences.getClassDifferences().size()); 115 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 116 assertTrue(name + ".IsModified()", !differences.isModified()); 117 assertTrue(name + ".IsNew()", differences.isNew()); 118 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 119 } 120 121 public void testRemovedPackage() { 122 String name = "RemovedPackage"; 123 PackageDifferences differences = (PackageDifferences) find(name, jarDifferences.getPackageDifferences()); 124 assertNotNull(name, differences); 125 126 assertEquals(name, differences.getName()); 127 assertEquals(name + ".ClassDifferences: " + differences.getClassDifferences(), 0, differences.getClassDifferences().size()); 128 assertTrue(name + ".IsRemoved()", differences.isRemoved()); 129 assertTrue(name + ".IsModified()", !differences.isModified()); 130 assertTrue(name + ".IsNew()", !differences.isNew()); 131 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 132 } 133 134 public void testUndocumentedPackage() { 135 String name = "UndocumentedPackage"; 136 DocumentableDifferences documentableDifferences = (DocumentableDifferences) find(name, jarDifferences.getPackageDifferences()); 137 PackageDifferences differences = (PackageDifferences) documentableDifferences.getComponent(); 138 assertNotNull(name, differences); 139 140 assertTrue(name + ".NewDocumentation()", !documentableDifferences.isNewDocumentation()); 141 assertTrue(name + ".Remove Documentation()", documentableDifferences.isRemovedDocumentation()); 142 assertTrue(name + ".IsEmpty()", !documentableDifferences.isEmpty()); 143 144 assertEquals(name, differences.getName()); 145 assertEquals(name + ".ClassDifferences: " + differences.getClassDifferences(), 1, differences.getClassDifferences().size()); 146 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 147 assertTrue(name + ".IsModified()", differences.isModified()); 148 assertTrue(name + ".IsNew()", !differences.isNew()); 149 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 150 } 151 152 public void testDeprecatedClass() { 153 String packageName = "ModifiedPackage"; 154 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 155 156 String name = packageName + ".DeprecatedClass"; 157 DeprecatableDifferences deprecatableDifferences = (DeprecatableDifferences) find(name, packageDifferences.getClassDifferences()); 158 ClassDifferences differences = (ClassDifferences) deprecatableDifferences.getComponent(); 159 assertNotNull(name, differences); 160 161 assertTrue(name + ".NewDeprecation()", deprecatableDifferences.isNewDeprecation()); 162 assertTrue(name + ".RemovedDeprecation()", !deprecatableDifferences.isRemovedDeprecation()); 163 assertTrue(name + ".IsEmpty()", !deprecatableDifferences.isEmpty()); 164 165 assertEquals(name, differences.getName()); 166 assertEquals(name + ".FeatureDifferences", 0, differences.getFeatureDifferences().size()); 167 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 168 assertTrue(name + ".IsModified()", !differences.isModified()); 169 assertTrue(name + ".IsNew()", !differences.isNew()); 170 assertTrue(name + ".IsEmpty()", differences.isEmpty()); 171 } 172 173 public void testUndocumentedPackagePublishedClass() { 174 String packageName = "UndocumentedPackage"; 175 PackageDifferences packageDifferences = (PackageDifferences) ((DecoratorDifferences) find(packageName, jarDifferences.getPackageDifferences())).getLeafComponent(); 176 177 String name = packageName + ".PublishedClass"; 178 DocumentableDifferences documentableDifferences = (DocumentableDifferences) find(name, packageDifferences.getClassDifferences()); 179 ClassDifferences differences = (ClassDifferences) documentableDifferences.getComponent(); 180 assertNotNull(name, differences); 181 182 assertTrue(name + ".NewDocumentation()", !documentableDifferences.isNewDocumentation()); 183 assertTrue(name + ".Remove Documentation()", documentableDifferences.isRemovedDocumentation()); 184 assertTrue(name + ".IsEmpty()", !documentableDifferences.isEmpty()); 185 186 assertEquals(name, differences.getName()); 187 assertEquals(name + ".FeatureDifferences", 0, differences.getFeatureDifferences().size()); 188 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 189 assertTrue(name + ".IsModified()", !differences.isModified()); 190 assertTrue(name + ".IsNew()", !differences.isNew()); 191 assertTrue(name + ".IsEmpty()", differences.isEmpty()); 192 } 193 194 public void testDocumentedClass() { 195 String packageName = "ModifiedPackage"; 196 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 197 198 String name = packageName + ".DocumentedClass"; 199 DocumentableDifferences documentableDifferences = (DocumentableDifferences) find(name, packageDifferences.getClassDifferences()); 200 ClassDifferences differences = (ClassDifferences) documentableDifferences.getComponent(); 201 assertNotNull(name, differences); 202 203 assertTrue(name + ".NewDocumentation()", documentableDifferences.isNewDocumentation()); 204 assertTrue(name + ".Remove Documentation()", !documentableDifferences.isRemovedDocumentation()); 205 assertTrue(name + ".IsEmpty()", !documentableDifferences.isEmpty()); 206 207 assertEquals(name, differences.getName()); 208 assertEquals(name + ".FeatureDifferences", 0, differences.getFeatureDifferences().size()); 209 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 210 assertTrue(name + ".IsModified()", !differences.isModified()); 211 assertTrue(name + ".IsNew()", !differences.isNew()); 212 assertTrue(name + ".IsEmpty()", differences.isEmpty()); 213 } 214 215 public void testModifiedClass() { 216 String packageName = "ModifiedPackage"; 217 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 218 219 String name = packageName + ".ModifiedClass"; 220 ClassDifferences differences = (ClassDifferences) find(name, packageDifferences.getClassDifferences()); 221 assertNotNull(name, differences); 222 223 assertEquals(name, differences.getName()); 224 assertEquals(name + ".FeatureDifferences", 21, differences.getFeatureDifferences().size()); 225 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 226 assertTrue(name + ".IsModified()", differences.isModified()); 227 assertTrue(name + ".IsNew()", !differences.isNew()); 228 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 229 } 230 231 public void testModifiedInterface() { 232 String packageName = "ModifiedPackage"; 233 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 234 235 String name = packageName + ".ModifiedInterface"; 236 ClassDifferences differences = (ClassDifferences) find(name, packageDifferences.getClassDifferences()); 237 assertNotNull(name, differences); 238 239 assertEquals(name, differences.getName()); 240 assertEquals(name + ".FeatureDifferences", 14, differences.getFeatureDifferences().size()); 241 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 242 assertTrue(name + ".IsModified()", differences.isModified()); 243 assertTrue(name + ".IsNew()", !differences.isNew()); 244 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 245 } 246 247 public void testNewClass() { 248 String packageName = "ModifiedPackage"; 249 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 250 251 String name = packageName + ".NewClass"; 252 ClassDifferences differences = (ClassDifferences) find(name, packageDifferences.getClassDifferences()); 253 assertNotNull(name, differences); 254 255 assertEquals(name, differences.getName()); 256 assertEquals(name + ".FeatureDifferences", 0, differences.getFeatureDifferences().size()); 257 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 258 assertTrue(name + ".IsModified()", !differences.isModified()); 259 assertTrue(name + ".IsNew()", differences.isNew()); 260 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 261 } 262 263 public void testNewInterface() { 264 String packageName = "ModifiedPackage"; 265 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 266 267 String name = packageName + ".NewInterface"; 268 ClassDifferences differences = (ClassDifferences) find(name, packageDifferences.getClassDifferences()); 269 assertNotNull(name, differences); 270 271 assertEquals(name, differences.getName()); 272 assertEquals(name + ".FeatureDifferences", 0, differences.getFeatureDifferences().size()); 273 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 274 assertTrue(name + ".IsModified()", !differences.isModified()); 275 assertTrue(name + ".IsNew()", differences.isNew()); 276 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 277 } 278 279 public void testRemovedClass() { 280 String packageName = "ModifiedPackage"; 281 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 282 283 String name = packageName + ".RemovedClass"; 284 ClassDifferences differences = (ClassDifferences) find(name, packageDifferences.getClassDifferences()); 285 assertNotNull(name, differences); 286 287 assertEquals(name, differences.getName()); 288 assertEquals(name + ".FeatureDifferences", 0, differences.getFeatureDifferences().size()); 289 assertTrue(name + ".IsRemoved()", differences.isRemoved()); 290 assertTrue(name + ".IsModified()", !differences.isModified()); 291 assertTrue(name + ".IsNew()", !differences.isNew()); 292 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 293 } 294 295 public void testRemovedInterface() { 296 String packageName = "ModifiedPackage"; 297 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 298 299 String name = packageName + ".RemovedInterface"; 300 ClassDifferences differences = (ClassDifferences) find(name, packageDifferences.getClassDifferences()); 301 assertNotNull(name, differences); 302 303 assertEquals(name, differences.getName()); 304 assertEquals(name + ".FeatureDifferences", 0, differences.getFeatureDifferences().size()); 305 assertTrue(name + ".IsRemoved()", differences.isRemoved()); 306 assertTrue(name + ".IsModified()", !differences.isModified()); 307 assertTrue(name + ".IsNew()", !differences.isNew()); 308 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 309 } 310 311 public void testUndeprecatedClass() { 312 String packageName = "ModifiedPackage"; 313 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 314 315 String name = packageName + ".UndeprecatedClass"; 316 DeprecatableDifferences deprecatableDifferences = (DeprecatableDifferences) find(name, packageDifferences.getClassDifferences()); 317 ClassDifferences differences = (ClassDifferences) deprecatableDifferences.getComponent(); 318 assertNotNull(name, differences); 319 320 assertTrue(name + ".NewDeprecation()", !deprecatableDifferences.isNewDeprecation()); 321 assertTrue(name + ".RemovedDeprecation()", deprecatableDifferences.isRemovedDeprecation()); 322 assertTrue(name + ".IsEmpty()", !deprecatableDifferences.isEmpty()); 323 324 assertEquals(name, differences.getName()); 325 assertEquals(name + ".FeatureDifferences", 0, differences.getFeatureDifferences().size()); 326 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 327 assertTrue(name + ".IsModified()", !differences.isModified()); 328 assertTrue(name + ".IsNew()", !differences.isNew()); 329 assertTrue(name + ".IsEmpty()", differences.isEmpty()); 330 } 331 332 public void testUndocumentedClass() { 333 String packageName = "ModifiedPackage"; 334 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 335 336 String name = packageName + ".UndocumentedClass"; 337 DocumentableDifferences documentableDifferences = (DocumentableDifferences) find(name, packageDifferences.getClassDifferences()); 338 ClassDifferences differences = (ClassDifferences) documentableDifferences.getComponent(); 339 assertNotNull(name, differences); 340 341 assertTrue(name + ".NewDocumentation()", !documentableDifferences.isNewDocumentation()); 342 assertTrue(name + ".Remove Documentation()", documentableDifferences.isRemovedDocumentation()); 343 assertTrue(name + ".IsEmpty()", !documentableDifferences.isEmpty()); 344 345 assertEquals(name, differences.getName()); 346 assertEquals(name + ".FeatureDifferences", 0, differences.getFeatureDifferences().size()); 347 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 348 assertTrue(name + ".IsModified()", !differences.isModified()); 349 assertTrue(name + ".IsNew()", !differences.isNew()); 350 assertTrue(name + ".IsEmpty()", differences.isEmpty()); 351 } 352 353 public void testDocumentedPackagePublishedClass() { 354 String packageName = "DocumentedPackage"; 355 PackageDifferences packageDifferences = (PackageDifferences) ((DecoratorDifferences) find(packageName, jarDifferences.getPackageDifferences())).getLeafComponent(); 356 357 String name = packageName + ".PublishedClass"; 358 DocumentableDifferences documentableDifferences = (DocumentableDifferences) find(name, packageDifferences.getClassDifferences()); 359 ClassDifferences differences = (ClassDifferences) documentableDifferences.getComponent(); 360 assertNotNull(name, differences); 361 362 assertTrue(name + ".NewDocumentation()", documentableDifferences.isNewDocumentation()); 363 assertTrue(name + ".Remove Documentation()", !documentableDifferences.isRemovedDocumentation()); 364 assertTrue(name + ".IsEmpty()", !documentableDifferences.isEmpty()); 365 366 assertEquals(name, differences.getName()); 367 assertEquals(name + ".FeatureDifferences", 0, differences.getFeatureDifferences().size()); 368 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 369 assertTrue(name + ".IsModified()", !differences.isModified()); 370 assertTrue(name + ".IsNew()", !differences.isNew()); 371 assertTrue(name + ".IsEmpty()", differences.isEmpty()); 372 } 373 374 public void testModifiedClassModifiedField() { 375 String packageName = "ModifiedPackage"; 376 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 377 378 String className = packageName + ".ModifiedClass"; 379 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 380 381 String name = className + ".modifiedField"; 382 FieldDifferences differences = (FieldDifferences) find(name, classDifferences.getFeatureDifferences()); 383 assertNotNull(name, differences); 384 385 assertEquals(name, differences.getName()); 386 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 387 assertTrue(name + ".IsModified()", differences.isModified()); 388 assertTrue(name + ".IsNew()", !differences.isNew()); 389 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 390 } 391 392 public void testModifiedClassNewField() { 393 String packageName = "ModifiedPackage"; 394 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 395 396 String className = packageName + ".ModifiedClass"; 397 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 398 399 String name = className + ".newField"; 400 FieldDifferences differences = (FieldDifferences) find(name, classDifferences.getFeatureDifferences()); 401 assertNotNull(name, differences); 402 403 assertEquals(name, differences.getName()); 404 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 405 assertTrue(name + ".IsModified()", !differences.isModified()); 406 assertTrue(name + ".IsNew()", differences.isNew()); 407 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 408 } 409 410 public void testModifiedClassRemovedField() { 411 String packageName = "ModifiedPackage"; 412 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 413 414 String className = packageName + ".ModifiedClass"; 415 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 416 417 String name = className + ".removedField"; 418 FieldDifferences differences = (FieldDifferences) find(name, classDifferences.getFeatureDifferences()); 419 assertNotNull(name, differences); 420 421 assertEquals(name, differences.getName()); 422 assertTrue(name + ".IsRemoved()", differences.isRemoved()); 423 assertTrue(name + ".IsModified()", !differences.isModified()); 424 assertTrue(name + ".IsNew()", !differences.isNew()); 425 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 426 } 427 428 public void testModifiedClassModifiedConstructor() { 429 String packageName = "ModifiedPackage"; 430 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 431 432 String className = packageName + ".ModifiedClass"; 433 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 434 435 String name = className + ".ModifiedClass(int, int, int)"; 436 ConstructorDifferences differences = (ConstructorDifferences) find(name, classDifferences.getFeatureDifferences()); 437 assertNotNull(name + " not in " + classDifferences.getFeatureDifferences(), differences); 438 439 assertEquals(name, differences.getName()); 440 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 441 assertTrue(name + ".IsModified()", differences.isModified()); 442 assertTrue(name + ".IsNew()", !differences.isNew()); 443 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 444 } 445 446 public void testModifiedClassNewConstructor() { 447 String packageName = "ModifiedPackage"; 448 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 449 450 String className = packageName + ".ModifiedClass"; 451 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 452 453 String name = className + ".ModifiedClass(int, int, int, int, int, int)"; 454 ConstructorDifferences differences = (ConstructorDifferences) find(name, classDifferences.getFeatureDifferences()); 455 assertNotNull(name + " not in " + classDifferences.getFeatureDifferences(), differences); 456 457 assertEquals(name, differences.getName()); 458 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 459 assertTrue(name + ".IsModified()", !differences.isModified()); 460 assertTrue(name + ".IsNew()", differences.isNew()); 461 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 462 } 463 464 public void testModifiedClassRemovedConstructor() { 465 String packageName = "ModifiedPackage"; 466 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 467 468 String className = packageName + ".ModifiedClass"; 469 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 470 471 String name = className + ".ModifiedClass()"; 472 ConstructorDifferences differences = (ConstructorDifferences) find(name, classDifferences.getFeatureDifferences()); 473 assertNotNull(name + " not in " + classDifferences.getFeatureDifferences(), differences); 474 475 assertEquals(name, differences.getName()); 476 assertTrue(name + ".IsRemoved()", differences.isRemoved()); 477 assertTrue(name + ".IsModified()", !differences.isModified()); 478 assertTrue(name + ".IsNew()", !differences.isNew()); 479 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 480 } 481 482 public void testModifiedClassModifiedMethod() { 483 String packageName = "ModifiedPackage"; 484 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 485 486 String className = packageName + ".ModifiedClass"; 487 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 488 489 String name = className + ".modifiedMethod()"; 490 MethodDifferences differences = (MethodDifferences) find(name, classDifferences.getFeatureDifferences()); 491 assertNotNull(name, differences); 492 493 assertEquals(name, differences.getName()); 494 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 495 assertTrue(name + ".IsModified()", differences.isModified()); 496 assertTrue(name + ".IsNew()", !differences.isNew()); 497 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 498 } 499 500 public void testModifiedClassNewMethod() { 501 String packageName = "ModifiedPackage"; 502 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 503 504 String className = packageName + ".ModifiedClass"; 505 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 506 507 String name = className + ".newMethod()"; 508 MethodDifferences differences = (MethodDifferences) find(name, classDifferences.getFeatureDifferences()); 509 assertNotNull(name, differences); 510 511 assertEquals(name, differences.getName()); 512 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 513 assertTrue(name + ".IsModified()", !differences.isModified()); 514 assertTrue(name + ".IsNew()", differences.isNew()); 515 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 516 } 517 518 public void testModifiedClassRemovedMethod() { 519 String packageName = "ModifiedPackage"; 520 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 521 522 String className = packageName + ".ModifiedClass"; 523 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 524 525 String name = className + ".removedMethod()"; 526 MethodDifferences differences = (MethodDifferences) find(name, classDifferences.getFeatureDifferences()); 527 assertNotNull(name, differences); 528 529 assertEquals(name, differences.getName()); 530 assertTrue(name + ".IsRemoved()", differences.isRemoved()); 531 assertTrue(name + ".IsModified()", !differences.isModified()); 532 assertTrue(name + ".IsNew()", !differences.isNew()); 533 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 534 } 535 536 public void testModifiedInterfaceModifiedField() { 537 String packageName = "ModifiedPackage"; 538 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 539 540 String className = packageName + ".ModifiedInterface"; 541 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 542 543 String name = className + ".modifiedField"; 544 FieldDifferences differences = (FieldDifferences) find(name, classDifferences.getFeatureDifferences()); 545 assertNotNull(name, differences); 546 547 assertEquals(name, differences.getName()); 548 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 549 assertTrue(name + ".IsModified()", differences.isModified()); 550 assertTrue(name + ".IsNew()", !differences.isNew()); 551 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 552 } 553 554 public void testModifiedInterfaceNewField() { 555 String packageName = "ModifiedPackage"; 556 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 557 558 String className = packageName + ".ModifiedInterface"; 559 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 560 561 String name = className + ".newField"; 562 FieldDifferences differences = (FieldDifferences) find(name, classDifferences.getFeatureDifferences()); 563 assertNotNull(name, differences); 564 565 assertEquals(name, differences.getName()); 566 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 567 assertTrue(name + ".IsModified()", !differences.isModified()); 568 assertTrue(name + ".IsNew()", differences.isNew()); 569 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 570 } 571 572 public void testModifiedInterfaceRemovedField() { 573 String packageName = "ModifiedPackage"; 574 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 575 576 String className = packageName + ".ModifiedInterface"; 577 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 578 579 String name = className + ".removedField"; 580 FieldDifferences differences = (FieldDifferences) find(name, classDifferences.getFeatureDifferences()); 581 assertNotNull(name, differences); 582 583 assertEquals(name, differences.getName()); 584 assertTrue(name + ".IsRemoved()", differences.isRemoved()); 585 assertTrue(name + ".IsModified()", !differences.isModified()); 586 assertTrue(name + ".IsNew()", !differences.isNew()); 587 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 588 } 589 590 public void testModifiedInterfaceModifiedMethod() { 591 String packageName = "ModifiedPackage"; 592 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 593 594 String className = packageName + ".ModifiedInterface"; 595 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 596 597 String name = className + ".modifiedMethod()"; 598 FeatureDifferences differences = (FeatureDifferences) find(name, classDifferences.getFeatureDifferences()); 599 assertNotNull(name, differences); 600 601 assertEquals(name, differences.getName()); 602 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 603 assertTrue(name + ".IsModified()", differences.isModified()); 604 assertTrue(name + ".IsNew()", !differences.isNew()); 605 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 606 } 607 608 public void testModifiedInterfaceNewMethod() { 609 String packageName = "ModifiedPackage"; 610 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 611 612 String className = packageName + ".ModifiedInterface"; 613 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 614 615 String name = className + ".newMethod()"; 616 FeatureDifferences differences = (FeatureDifferences) find(name, classDifferences.getFeatureDifferences()); 617 assertNotNull(name, differences); 618 619 assertEquals(name, differences.getName()); 620 assertTrue(name + ".IsRemoved()", !differences.isRemoved()); 621 assertTrue(name + ".IsModified()", !differences.isModified()); 622 assertTrue(name + ".IsNew()", differences.isNew()); 623 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 624 } 625 626 public void testModifiedInterfaceRemovedMethod() { 627 String packageName = "ModifiedPackage"; 628 PackageDifferences packageDifferences = (PackageDifferences) find(packageName, jarDifferences.getPackageDifferences()); 629 630 String className = packageName + ".ModifiedInterface"; 631 ClassDifferences classDifferences = (ClassDifferences) find(className, packageDifferences.getClassDifferences()); 632 633 String name = className + ".removedMethod()"; 634 FeatureDifferences differences = (FeatureDifferences) find(name, classDifferences.getFeatureDifferences()); 635 assertNotNull(name, differences); 636 637 assertEquals(name, differences.getName()); 638 assertTrue(name + ".IsRemoved()", differences.isRemoved()); 639 assertTrue(name + ".IsModified()", !differences.isModified()); 640 assertTrue(name + ".IsNew()", !differences.isNew()); 641 assertTrue(name + ".IsEmpty()", !differences.isEmpty()); 642 } 643 644 private Differences find(String name, Collection differences) { 645 Differences result = null; 646 647 Iterator i = differences.iterator(); 648 while (result == null && i.hasNext()) { 649 Differences candidate = (Differences) i.next(); 650 if (name.equals(candidate.getName())) { 651 result = candidate; 652 } 653 } 654 655 return result; 656 } 657 } 658 | Popular Tags |