001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.diff;
034:
035: import java.util.*;
036:
037: import com.jeantessier.classreader.*;
038:
039: public class TestAPIDifferenceStrategy extends
040: TestDifferencesFactoryBase {
041: private MockDifferenceStrategy mockStrategy;
042: private APIDifferenceStrategy strategy;
043:
044: protected void setUp() throws Exception {
045: super .setUp();
046:
047: mockStrategy = new MockDifferenceStrategy(
048: new NoDifferenceStrategy());
049: strategy = new APIDifferenceStrategy(mockStrategy);
050: }
051:
052: public void testUnmodifiedConstantValue() {
053: ConstantValue_attribute oldValue = getOldJar().getClassfile(
054: "UnmodifiedPackage.UnmodifiedInterface").getField(
055: "unmodifiedField").getConstantValue();
056: ConstantValue_attribute newValue = getNewJar().getClassfile(
057: "UnmodifiedPackage.UnmodifiedInterface").getField(
058: "unmodifiedField").getConstantValue();
059:
060: assertFalse(strategy.isConstantValueDifferent(oldValue,
061: newValue));
062:
063: assertEquals("package", 0, mockStrategy
064: .getPackageDifferentCount());
065: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
066: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
067: assertEquals("constant", 1, mockStrategy
068: .getConstantValueDifferentCount());
069: assertEquals("method", 0, mockStrategy
070: .getMethodDifferentCount());
071: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
072: }
073:
074: public void testRemovedConstantValue() {
075: ConstantValue_attribute oldValue = getOldJar().getClassfile(
076: "ModifiedPackage.ModifiedInterface").getField(
077: "removedField").getConstantValue();
078: ConstantValue_attribute newValue = null;
079:
080: assertFalse(strategy.isConstantValueDifferent(oldValue,
081: newValue));
082:
083: assertEquals("package", 0, mockStrategy
084: .getPackageDifferentCount());
085: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
086: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
087: assertEquals("constant", 1, mockStrategy
088: .getConstantValueDifferentCount());
089: assertEquals("method", 0, mockStrategy
090: .getMethodDifferentCount());
091: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
092: }
093:
094: public void testModifiedConstantValue() {
095: ConstantValue_attribute oldValue = getOldJar().getClassfile(
096: "ModifiedPackage.ModifiedInterface").getField(
097: "modifiedValueField").getConstantValue();
098: ConstantValue_attribute newValue = getNewJar().getClassfile(
099: "ModifiedPackage.ModifiedInterface").getField(
100: "modifiedValueField").getConstantValue();
101:
102: assertFalse(strategy.isConstantValueDifferent(oldValue,
103: newValue));
104:
105: assertEquals("package", 0, mockStrategy
106: .getPackageDifferentCount());
107: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
108: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
109: assertEquals("constant", 1, mockStrategy
110: .getConstantValueDifferentCount());
111: assertEquals("method", 0, mockStrategy
112: .getMethodDifferentCount());
113: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
114: }
115:
116: public void testNewConstantValue() {
117: ConstantValue_attribute oldValue = null;
118: ConstantValue_attribute newValue = getNewJar().getClassfile(
119: "ModifiedPackage.ModifiedInterface").getField(
120: "newField").getConstantValue();
121:
122: assertFalse(strategy.isConstantValueDifferent(oldValue,
123: newValue));
124:
125: assertEquals("package", 0, mockStrategy
126: .getPackageDifferentCount());
127: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
128: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
129: assertEquals("constant", 1, mockStrategy
130: .getConstantValueDifferentCount());
131: assertEquals("method", 0, mockStrategy
132: .getMethodDifferentCount());
133: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
134: }
135:
136: public void testUnmodifiedField() {
137: Field_info oldFeature = getOldJar().getClassfile(
138: "UnmodifiedPackage.UnmodifiedClass").getField(
139: "unmodifiedField");
140: Field_info newFeature = getNewJar().getClassfile(
141: "UnmodifiedPackage.UnmodifiedClass").getField(
142: "unmodifiedField");
143:
144: assertFalse(strategy.isFieldDifferent(oldFeature, newFeature));
145:
146: assertEquals("package", 0, mockStrategy
147: .getPackageDifferentCount());
148: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
149: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
150: assertEquals("constant", 1, mockStrategy
151: .getConstantValueDifferentCount());
152: assertEquals("method", 0, mockStrategy
153: .getMethodDifferentCount());
154: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
155: }
156:
157: public void testRemovedField() {
158: Field_info oldFeature = getOldJar().getClassfile(
159: "ModifiedPackage.ModifiedClass").getField(
160: "removedField");
161: Field_info newFeature = getNewJar().getClassfile(
162: "ModifiedPackage.ModifiedClass").getField(
163: "removedField");
164:
165: assertTrue(strategy.isFieldDifferent(oldFeature, newFeature));
166:
167: assertEquals("package", 0, mockStrategy
168: .getPackageDifferentCount());
169: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
170: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
171: assertEquals("constant", 0, mockStrategy
172: .getConstantValueDifferentCount());
173: assertEquals("method", 0, mockStrategy
174: .getMethodDifferentCount());
175: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
176: }
177:
178: public void testModifiedField() {
179: Field_info oldFeature = getOldJar().getClassfile(
180: "ModifiedPackage.ModifiedClass").getField(
181: "modifiedField");
182: Field_info newFeature = getNewJar().getClassfile(
183: "ModifiedPackage.ModifiedClass").getField(
184: "modifiedField");
185:
186: assertTrue(strategy.isFieldDifferent(oldFeature, newFeature));
187:
188: assertEquals("package", 0, mockStrategy
189: .getPackageDifferentCount());
190: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
191: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
192: assertEquals("constant", 0, mockStrategy
193: .getConstantValueDifferentCount());
194: assertEquals("method", 0, mockStrategy
195: .getMethodDifferentCount());
196: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
197: }
198:
199: public void testModifiedValueField() {
200: Field_info oldFeature = getOldJar().getClassfile(
201: "ModifiedPackage.ModifiedInterface").getField(
202: "modifiedValueField");
203: Field_info newFeature = getNewJar().getClassfile(
204: "ModifiedPackage.ModifiedInterface").getField(
205: "modifiedValueField");
206:
207: assertFalse(strategy.isFieldDifferent(oldFeature, newFeature));
208:
209: assertEquals("package", 0, mockStrategy
210: .getPackageDifferentCount());
211: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
212: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
213: assertEquals("constant", 1, mockStrategy
214: .getConstantValueDifferentCount());
215: assertEquals("method", 0, mockStrategy
216: .getMethodDifferentCount());
217: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
218: }
219:
220: public void testDeprecatedField() {
221: Field_info oldFeature = getOldJar().getClassfile(
222: "ModifiedPackage.ModifiedInterface").getField(
223: "deprecatedField");
224: Field_info newFeature = getNewJar().getClassfile(
225: "ModifiedPackage.ModifiedInterface").getField(
226: "deprecatedField");
227:
228: assertTrue(strategy.isFieldDifferent(oldFeature, newFeature));
229:
230: assertEquals("package", 0, mockStrategy
231: .getPackageDifferentCount());
232: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
233: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
234: assertEquals("constant", 0, mockStrategy
235: .getConstantValueDifferentCount());
236: assertEquals("method", 0, mockStrategy
237: .getMethodDifferentCount());
238: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
239: }
240:
241: public void testUndeprecatedField() {
242: Field_info oldFeature = getOldJar().getClassfile(
243: "ModifiedPackage.ModifiedInterface").getField(
244: "undeprecatedField");
245: Field_info newFeature = getNewJar().getClassfile(
246: "ModifiedPackage.ModifiedInterface").getField(
247: "undeprecatedField");
248:
249: assertTrue(strategy.isFieldDifferent(oldFeature, newFeature));
250:
251: assertEquals("package", 0, mockStrategy
252: .getPackageDifferentCount());
253: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
254: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
255: assertEquals("constant", 0, mockStrategy
256: .getConstantValueDifferentCount());
257: assertEquals("method", 0, mockStrategy
258: .getMethodDifferentCount());
259: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
260: }
261:
262: public void testNewField() {
263: Field_info oldFeature = getOldJar().getClassfile(
264: "ModifiedPackage.ModifiedClass").getField("newField");
265: Field_info newFeature = getNewJar().getClassfile(
266: "ModifiedPackage.ModifiedClass").getField("newField");
267:
268: assertTrue(strategy.isFieldDifferent(oldFeature, newFeature));
269:
270: assertEquals("package", 0, mockStrategy
271: .getPackageDifferentCount());
272: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
273: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
274: assertEquals("constant", 0, mockStrategy
275: .getConstantValueDifferentCount());
276: assertEquals("method", 0, mockStrategy
277: .getMethodDifferentCount());
278: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
279: }
280:
281: public void testUnmodifiedCode() {
282: Code_attribute oldCode = getOldJar().getClassfile(
283: "UnmodifiedPackage.UnmodifiedClass").getMethod(
284: "unmodifiedMethod()").getCode();
285: Code_attribute newCode = getNewJar().getClassfile(
286: "UnmodifiedPackage.UnmodifiedClass").getMethod(
287: "unmodifiedMethod()").getCode();
288:
289: assertFalse(strategy.isCodeDifferent(oldCode, newCode));
290:
291: assertEquals("package", 0, mockStrategy
292: .getPackageDifferentCount());
293: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
294: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
295: assertEquals("constant", 0, mockStrategy
296: .getConstantValueDifferentCount());
297: assertEquals("method", 0, mockStrategy
298: .getMethodDifferentCount());
299: assertEquals("code", 1, mockStrategy.getCodeDifferentCount());
300: }
301:
302: public void testModifiedCode() {
303: Code_attribute oldCode = getOldJar().getClassfile(
304: "ModifiedPackage.ModifiedClass").getMethod(
305: "modifiedCodeMethod()").getCode();
306: Code_attribute newCode = getNewJar().getClassfile(
307: "ModifiedPackage.ModifiedClass").getMethod(
308: "modifiedCodeMethod()").getCode();
309:
310: assertFalse(strategy.isCodeDifferent(oldCode, newCode));
311:
312: assertEquals("package", 0, mockStrategy
313: .getPackageDifferentCount());
314: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
315: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
316: assertEquals("constant", 0, mockStrategy
317: .getConstantValueDifferentCount());
318: assertEquals("method", 0, mockStrategy
319: .getMethodDifferentCount());
320: assertEquals("code", 1, mockStrategy.getCodeDifferentCount());
321: }
322:
323: public void testUnmodifiedConstructor() {
324: Method_info oldMethod = getOldJar().getClassfile(
325: "UnmodifiedPackage.UnmodifiedClass").getMethod(
326: "UnmodifiedClass()");
327: Method_info newMethod = getNewJar().getClassfile(
328: "UnmodifiedPackage.UnmodifiedClass").getMethod(
329: "UnmodifiedClass()");
330:
331: assertFalse(strategy.isMethodDifferent(oldMethod, newMethod));
332:
333: assertEquals("package", 0, mockStrategy
334: .getPackageDifferentCount());
335: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
336: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
337: assertEquals("constant", 0, mockStrategy
338: .getConstantValueDifferentCount());
339: assertEquals("method", 0, mockStrategy
340: .getMethodDifferentCount());
341: assertEquals("code", 1, mockStrategy.getCodeDifferentCount());
342: }
343:
344: public void testRemovedConstructor() {
345: Method_info oldMethod = getOldJar().getClassfile(
346: "ModifiedPackage.ModifiedClass").getMethod(
347: "ModifiedClass()");
348: Method_info newMethod = getNewJar().getClassfile(
349: "ModifiedPackage.ModifiedClass").getMethod(
350: "ModifiedClass()");
351:
352: assertTrue(strategy.isMethodDifferent(oldMethod, newMethod));
353:
354: assertEquals("package", 0, mockStrategy
355: .getPackageDifferentCount());
356: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
357: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
358: assertEquals("constant", 0, mockStrategy
359: .getConstantValueDifferentCount());
360: assertEquals("method", 0, mockStrategy
361: .getMethodDifferentCount());
362: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
363: }
364:
365: public void testModifiedConstructor() {
366: Method_info oldMethod = getOldJar().getClassfile(
367: "ModifiedPackage.ModifiedClass").getMethod(
368: "ModifiedClass(int, int, int)");
369: Method_info newMethod = getNewJar().getClassfile(
370: "ModifiedPackage.ModifiedClass").getMethod(
371: "ModifiedClass(int, int, int)");
372:
373: assertTrue(strategy.isMethodDifferent(oldMethod, newMethod));
374:
375: assertEquals("package", 0, mockStrategy
376: .getPackageDifferentCount());
377: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
378: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
379: assertEquals("constant", 0, mockStrategy
380: .getConstantValueDifferentCount());
381: assertEquals("method", 0, mockStrategy
382: .getMethodDifferentCount());
383: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
384: }
385:
386: public void testModifiedCodeConstructor() {
387: Method_info oldMethod = getOldJar().getClassfile(
388: "ModifiedPackage.ModifiedClass").getMethod(
389: "ModifiedClass(float)");
390: Method_info newMethod = getNewJar().getClassfile(
391: "ModifiedPackage.ModifiedClass").getMethod(
392: "ModifiedClass(float)");
393:
394: assertFalse(strategy.isMethodDifferent(oldMethod, newMethod));
395:
396: assertEquals("package", 0, mockStrategy
397: .getPackageDifferentCount());
398: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
399: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
400: assertEquals("constant", 0, mockStrategy
401: .getConstantValueDifferentCount());
402: assertEquals("method", 0, mockStrategy
403: .getMethodDifferentCount());
404: assertEquals("code", 1, mockStrategy.getCodeDifferentCount());
405: }
406:
407: public void testDeprecatedConstructor() {
408: Method_info oldMethod = getOldJar().getClassfile(
409: "ModifiedPackage.ModifiedClass").getMethod(
410: "ModifiedClass(int)");
411: Method_info newMethod = getNewJar().getClassfile(
412: "ModifiedPackage.ModifiedClass").getMethod(
413: "ModifiedClass(int)");
414:
415: assertTrue(strategy.isMethodDifferent(oldMethod, newMethod));
416:
417: assertEquals("package", 0, mockStrategy
418: .getPackageDifferentCount());
419: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
420: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
421: assertEquals("constant", 0, mockStrategy
422: .getConstantValueDifferentCount());
423: assertEquals("method", 0, mockStrategy
424: .getMethodDifferentCount());
425: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
426: }
427:
428: public void testUndeprecatedConstructor() {
429: Method_info oldMethod = getOldJar().getClassfile(
430: "ModifiedPackage.ModifiedClass").getMethod(
431: "ModifiedClass(int, int, int, int, int)");
432: Method_info newMethod = getNewJar().getClassfile(
433: "ModifiedPackage.ModifiedClass").getMethod(
434: "ModifiedClass(int, int, int, int, int)");
435:
436: assertTrue(strategy.isMethodDifferent(oldMethod, newMethod));
437:
438: assertEquals("package", 0, mockStrategy
439: .getPackageDifferentCount());
440: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
441: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
442: assertEquals("constant", 0, mockStrategy
443: .getConstantValueDifferentCount());
444: assertEquals("method", 0, mockStrategy
445: .getMethodDifferentCount());
446: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
447: }
448:
449: public void testNewConstructor() {
450: Method_info oldMethod = getOldJar().getClassfile(
451: "ModifiedPackage.ModifiedClass").getMethod(
452: "ModifiedClass(int, int, int, int, int, int)");
453: Method_info newMethod = getNewJar().getClassfile(
454: "ModifiedPackage.ModifiedClass").getMethod(
455: "ModifiedClass(int, int, int, int, int, int)");
456:
457: assertTrue(strategy.isMethodDifferent(oldMethod, newMethod));
458:
459: assertEquals("package", 0, mockStrategy
460: .getPackageDifferentCount());
461: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
462: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
463: assertEquals("constant", 0, mockStrategy
464: .getConstantValueDifferentCount());
465: assertEquals("method", 0, mockStrategy
466: .getMethodDifferentCount());
467: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
468: }
469:
470: public void testUnmodifiedMethod() {
471: Method_info oldMethod = getOldJar().getClassfile(
472: "UnmodifiedPackage.UnmodifiedClass").getMethod(
473: "unmodifiedMethod()");
474: Method_info newMethod = getNewJar().getClassfile(
475: "UnmodifiedPackage.UnmodifiedClass").getMethod(
476: "unmodifiedMethod()");
477:
478: assertFalse(strategy.isMethodDifferent(oldMethod, newMethod));
479:
480: assertEquals("package", 0, mockStrategy
481: .getPackageDifferentCount());
482: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
483: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
484: assertEquals("constant", 0, mockStrategy
485: .getConstantValueDifferentCount());
486: assertEquals("method", 0, mockStrategy
487: .getMethodDifferentCount());
488: assertEquals("code", 1, mockStrategy.getCodeDifferentCount());
489: }
490:
491: public void testRemovedMethod() {
492: Method_info oldMethod = getOldJar().getClassfile(
493: "ModifiedPackage.ModifiedClass").getMethod(
494: "removedMethod()");
495: Method_info newMethod = getNewJar().getClassfile(
496: "ModifiedPackage.ModifiedClass").getMethod(
497: "removedMethod()");
498:
499: assertTrue(strategy.isMethodDifferent(oldMethod, newMethod));
500:
501: assertEquals("package", 0, mockStrategy
502: .getPackageDifferentCount());
503: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
504: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
505: assertEquals("constant", 0, mockStrategy
506: .getConstantValueDifferentCount());
507: assertEquals("method", 0, mockStrategy
508: .getMethodDifferentCount());
509: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
510: }
511:
512: public void testModifiedMethod() {
513: Method_info oldMethod = getOldJar().getClassfile(
514: "ModifiedPackage.ModifiedClass").getMethod(
515: "modifiedMethod()");
516: Method_info newMethod = getNewJar().getClassfile(
517: "ModifiedPackage.ModifiedClass").getMethod(
518: "modifiedMethod()");
519:
520: assertTrue(strategy.isMethodDifferent(oldMethod, newMethod));
521:
522: assertEquals("package", 0, mockStrategy
523: .getPackageDifferentCount());
524: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
525: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
526: assertEquals("constant", 0, mockStrategy
527: .getConstantValueDifferentCount());
528: assertEquals("method", 0, mockStrategy
529: .getMethodDifferentCount());
530: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
531: }
532:
533: public void testModifiedCodeMethod() {
534: Method_info oldMethod = getOldJar().getClassfile(
535: "ModifiedPackage.ModifiedClass").getMethod(
536: "modifiedCodeMethod()");
537: Method_info newMethod = getNewJar().getClassfile(
538: "ModifiedPackage.ModifiedClass").getMethod(
539: "modifiedCodeMethod()");
540:
541: assertFalse(strategy.isMethodDifferent(oldMethod, newMethod));
542:
543: assertEquals("package", 0, mockStrategy
544: .getPackageDifferentCount());
545: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
546: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
547: assertEquals("constant", 0, mockStrategy
548: .getConstantValueDifferentCount());
549: assertEquals("method", 0, mockStrategy
550: .getMethodDifferentCount());
551: assertEquals("code", 1, mockStrategy.getCodeDifferentCount());
552: }
553:
554: public void testDeprecatedMethod() {
555: Method_info oldMethod = getOldJar().getClassfile(
556: "ModifiedPackage.ModifiedClass").getMethod(
557: "deprecatedMethod()");
558: Method_info newMethod = getNewJar().getClassfile(
559: "ModifiedPackage.ModifiedClass").getMethod(
560: "deprecatedMethod()");
561:
562: assertTrue(strategy.isMethodDifferent(oldMethod, newMethod));
563:
564: assertEquals("package", 0, mockStrategy
565: .getPackageDifferentCount());
566: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
567: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
568: assertEquals("constant", 0, mockStrategy
569: .getConstantValueDifferentCount());
570: assertEquals("method", 0, mockStrategy
571: .getMethodDifferentCount());
572: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
573: }
574:
575: public void testUndeprecatedMethod() {
576: Method_info oldMethod = getOldJar().getClassfile(
577: "ModifiedPackage.ModifiedClass").getMethod(
578: "undeprecatedMethod()");
579: Method_info newMethod = getNewJar().getClassfile(
580: "ModifiedPackage.ModifiedClass").getMethod(
581: "undeprecatedMethod()");
582:
583: assertTrue(strategy.isMethodDifferent(oldMethod, newMethod));
584:
585: assertEquals("package", 0, mockStrategy
586: .getPackageDifferentCount());
587: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
588: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
589: assertEquals("constant", 0, mockStrategy
590: .getConstantValueDifferentCount());
591: assertEquals("method", 0, mockStrategy
592: .getMethodDifferentCount());
593: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
594: }
595:
596: public void testNewMethod() {
597: Method_info oldMethod = getOldJar().getClassfile(
598: "ModifiedPackage.ModifiedClass").getMethod(
599: "newMethod()");
600: Method_info newMethod = getNewJar().getClassfile(
601: "ModifiedPackage.ModifiedClass").getMethod(
602: "newMethod()");
603:
604: assertTrue(strategy.isMethodDifferent(oldMethod, newMethod));
605:
606: assertEquals("package", 0, mockStrategy
607: .getPackageDifferentCount());
608: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
609: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
610: assertEquals("constant", 0, mockStrategy
611: .getConstantValueDifferentCount());
612: assertEquals("method", 0, mockStrategy
613: .getMethodDifferentCount());
614: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
615: }
616:
617: public void testUnmodifiedInterface() {
618: Classfile oldClass = getOldJar().getClassfile(
619: "UnmodifiedPackage.UnmodifiedInterface");
620: Classfile newClass = getNewJar().getClassfile(
621: "UnmodifiedPackage.UnmodifiedInterface");
622:
623: assertFalse(strategy.isClassDifferent(oldClass, newClass));
624:
625: assertEquals("package", 0, mockStrategy
626: .getPackageDifferentCount());
627: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
628: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
629: assertEquals("constant", 1, mockStrategy
630: .getConstantValueDifferentCount());
631: assertEquals("method", 0, mockStrategy
632: .getMethodDifferentCount());
633: assertEquals("code", 1, mockStrategy.getCodeDifferentCount());
634: }
635:
636: public void testRemovedInterface() {
637: Classfile oldClass = getOldJar().getClassfile(
638: "ModifiedPackage.RemovedInterface");
639: Classfile newClass = getNewJar().getClassfile(
640: "ModifiedPackage.RemovedInterface");
641:
642: assertTrue(strategy.isClassDifferent(oldClass, newClass));
643:
644: assertEquals("package", 0, mockStrategy
645: .getPackageDifferentCount());
646: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
647: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
648: assertEquals("constant", 0, mockStrategy
649: .getConstantValueDifferentCount());
650: assertEquals("method", 0, mockStrategy
651: .getMethodDifferentCount());
652: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
653: }
654:
655: public void testModifiedDeclarationInterface() {
656: Classfile oldClass = getOldJar().getClassfile(
657: "ModifiedPackage.ModifiedDeclarationInterface");
658: Classfile newClass = getNewJar().getClassfile(
659: "ModifiedPackage.ModifiedDeclarationInterface");
660:
661: assertTrue(strategy.isClassDifferent(oldClass, newClass));
662:
663: assertEquals("package", 0, mockStrategy
664: .getPackageDifferentCount());
665: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
666: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
667: assertEquals("constant", 0, mockStrategy
668: .getConstantValueDifferentCount());
669: assertEquals("method", 0, mockStrategy
670: .getMethodDifferentCount());
671: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
672: }
673:
674: public void testModifiedInterface() {
675: Classfile oldClass = getOldJar().getClassfile(
676: "ModifiedPackage.ModifiedInterface");
677: Classfile newClass = getNewJar().getClassfile(
678: "ModifiedPackage.ModifiedInterface");
679:
680: assertTrue(strategy.isClassDifferent(oldClass, newClass));
681:
682: assertEquals("package", 0, mockStrategy
683: .getPackageDifferentCount());
684: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
685: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
686: assertEquals("constant", 0, mockStrategy
687: .getConstantValueDifferentCount());
688: assertEquals("method", 0, mockStrategy
689: .getMethodDifferentCount());
690: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
691: }
692:
693: public void testNewInterface() {
694: Classfile oldClass = getOldJar().getClassfile(
695: "ModifiedPackage.NewInterface");
696: Classfile newClass = getNewJar().getClassfile(
697: "ModifiedPackage.NewInterface");
698:
699: assertTrue(strategy.isClassDifferent(oldClass, newClass));
700:
701: assertEquals("package", 0, mockStrategy
702: .getPackageDifferentCount());
703: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
704: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
705: assertEquals("constant", 0, mockStrategy
706: .getConstantValueDifferentCount());
707: assertEquals("method", 0, mockStrategy
708: .getMethodDifferentCount());
709: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
710: }
711:
712: public void testUnmodifiedClass() {
713: Classfile oldClass = getOldJar().getClassfile(
714: "UnmodifiedPackage.UnmodifiedClass");
715: Classfile newClass = getNewJar().getClassfile(
716: "UnmodifiedPackage.UnmodifiedClass");
717:
718: assertFalse(strategy.isClassDifferent(oldClass, newClass));
719:
720: assertEquals("package", 0, mockStrategy
721: .getPackageDifferentCount());
722: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
723: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
724: assertEquals("constant", 1, mockStrategy
725: .getConstantValueDifferentCount());
726: assertEquals("method", 0, mockStrategy
727: .getMethodDifferentCount());
728: assertEquals("code", 2, mockStrategy.getCodeDifferentCount());
729: }
730:
731: public void testRemovedClass() {
732: Classfile oldClass = getOldJar().getClassfile(
733: "ModifiedPackage.RemovedClass");
734: Classfile newClass = getNewJar().getClassfile(
735: "ModifiedPackage.RemovedClass");
736:
737: assertTrue(strategy.isClassDifferent(oldClass, newClass));
738:
739: assertEquals("package", 0, mockStrategy
740: .getPackageDifferentCount());
741: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
742: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
743: assertEquals("constant", 0, mockStrategy
744: .getConstantValueDifferentCount());
745: assertEquals("method", 0, mockStrategy
746: .getMethodDifferentCount());
747: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
748: }
749:
750: public void testModifiedDeclarationClass() {
751: Classfile oldClass = getOldJar().getClassfile(
752: "ModifiedPackage.ModifiedDeclarationClass");
753: Classfile newClass = getNewJar().getClassfile(
754: "ModifiedPackage.ModifiedDeclarationClass");
755:
756: assertTrue(strategy.isClassDifferent(oldClass, newClass));
757:
758: assertEquals("package", 0, mockStrategy
759: .getPackageDifferentCount());
760: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
761: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
762: assertEquals("constant", 0, mockStrategy
763: .getConstantValueDifferentCount());
764: assertEquals("method", 0, mockStrategy
765: .getMethodDifferentCount());
766: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
767: }
768:
769: public void testModifiedClass() {
770: Classfile oldClass = getOldJar().getClassfile(
771: "ModifiedPackage.ModifiedClass");
772: Classfile newClass = getNewJar().getClassfile(
773: "ModifiedPackage.ModifiedClass");
774:
775: assertTrue(strategy.isClassDifferent(oldClass, newClass));
776:
777: assertEquals("package", 0, mockStrategy
778: .getPackageDifferentCount());
779: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
780: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
781: assertEquals("constant", 0, mockStrategy
782: .getConstantValueDifferentCount());
783: assertEquals("method", 0, mockStrategy
784: .getMethodDifferentCount());
785: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
786: }
787:
788: public void testNewClass() {
789: Classfile oldClass = getOldJar().getClassfile(
790: "ModifiedPackage.NewClass");
791: Classfile newClass = getNewJar().getClassfile(
792: "ModifiedPackage.NewClass");
793:
794: assertTrue(strategy.isClassDifferent(oldClass, newClass));
795:
796: assertEquals("package", 0, mockStrategy
797: .getPackageDifferentCount());
798: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
799: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
800: assertEquals("constant", 0, mockStrategy
801: .getConstantValueDifferentCount());
802: assertEquals("method", 0, mockStrategy
803: .getMethodDifferentCount());
804: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
805: }
806:
807: public void testUnmodifiedPackage() {
808: Map oldPackage = new HashMap();
809: oldPackage.put("UnmodifiedPackage.UnmodifiedClass", getOldJar()
810: .getClassfile("UnmodifiedPackage.UnmodifiedClass"));
811: oldPackage.put("UnmodifiedPackage.UnmodifiedInterface",
812: getOldJar().getClassfile(
813: "UnmodifiedPackage.UnmodifiedInterface"));
814: Map newPackage = new HashMap();
815: newPackage.put("UnmodifiedPackage.UnmodifiedClass", getNewJar()
816: .getClassfile("UnmodifiedPackage.UnmodifiedClass"));
817: newPackage.put("UnmodifiedPackage.UnmodifiedInterface",
818: getNewJar().getClassfile(
819: "UnmodifiedPackage.UnmodifiedInterface"));
820:
821: assertFalse(strategy.isPackageDifferent(oldPackage, newPackage));
822:
823: assertEquals("package", 0, mockStrategy
824: .getPackageDifferentCount());
825: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
826: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
827: assertEquals("constant", 2, mockStrategy
828: .getConstantValueDifferentCount());
829: assertEquals("method", 0, mockStrategy
830: .getMethodDifferentCount());
831: assertEquals("code", 3, mockStrategy.getCodeDifferentCount());
832: }
833:
834: public void testRemovedPackage() {
835: Map oldPackage = new HashMap();
836: oldPackage.put("RemovedPackage.RemovedClass", getOldJar()
837: .getClassfile("RemovedPackage.RemovedClass"));
838: Map newPackage = new HashMap();
839:
840: assertTrue(strategy.isPackageDifferent(oldPackage, newPackage));
841:
842: assertEquals("package", 0, mockStrategy
843: .getPackageDifferentCount());
844: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
845: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
846: assertEquals("constant", 0, mockStrategy
847: .getConstantValueDifferentCount());
848: assertEquals("method", 0, mockStrategy
849: .getMethodDifferentCount());
850: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
851: }
852:
853: public void testModifiedPackage() {
854: Map oldPackage = new HashMap();
855: oldPackage.put("UnmodifiedPackage.UnmodifiedClass", getOldJar()
856: .getClassfile("UnmodifiedPackage.UnmodifiedClass"));
857: oldPackage.put("UnmodifiedPackage.UnmodifiedInterface",
858: getOldJar().getClassfile(
859: "UnmodifiedPackage.UnmodifiedInterface"));
860: Map newPackage = new HashMap();
861: newPackage.put("UnmodifiedPackage.UnmodifiedClass", getNewJar()
862: .getClassfile("UnmodifiedPackage.UnmodifiedClass"));
863:
864: assertTrue(strategy.isPackageDifferent(oldPackage, newPackage));
865:
866: assertEquals("package", 0, mockStrategy
867: .getPackageDifferentCount());
868: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
869: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
870: assertEquals("constant", 0, mockStrategy
871: .getConstantValueDifferentCount());
872: assertEquals("method", 0, mockStrategy
873: .getMethodDifferentCount());
874: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
875: }
876:
877: public void testModifiedCodePackage() {
878: Map oldPackage = new HashMap();
879: oldPackage.put("ModifiedPackage.ModifiedClass", getOldJar()
880: .getClassfile("ModifiedPackage.ModifiedClass"));
881: Map newPackage = new HashMap();
882: newPackage.put("ModifiedPackage.ModifiedClass", getNewJar()
883: .getClassfile("ModifiedPackage.ModifiedClass"));
884:
885: assertTrue(strategy.isPackageDifferent(oldPackage, newPackage));
886:
887: assertEquals("package", 0, mockStrategy
888: .getPackageDifferentCount());
889: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
890: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
891: assertEquals("constant", 0, mockStrategy
892: .getConstantValueDifferentCount());
893: assertEquals("method", 0, mockStrategy
894: .getMethodDifferentCount());
895: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
896: }
897:
898: public void testNewPackage() {
899: Map oldPackage = new HashMap();
900: Map newPackage = new HashMap();
901: newPackage.put("NewPackage.NewClass", getNewJar().getClassfile(
902: "NewPackage.NewClass"));
903:
904: assertTrue(strategy.isPackageDifferent(oldPackage, newPackage));
905:
906: assertEquals("package", 0, mockStrategy
907: .getPackageDifferentCount());
908: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
909: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
910: assertEquals("constant", 0, mockStrategy
911: .getConstantValueDifferentCount());
912: assertEquals("method", 0, mockStrategy
913: .getMethodDifferentCount());
914: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
915: }
916: }
|