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.io.*;
036: import java.util.*;
037:
038: import com.jeantessier.classreader.*;
039:
040: public class TestListBasedDifferenceStrategy extends
041: TestDifferencesFactoryBase {
042: private MockDifferenceStrategy mockStrategy;
043:
044: protected void setUp() throws Exception {
045: super .setUp();
046:
047: mockStrategy = new MockDifferenceStrategy(
048: new CodeDifferenceStrategy());
049: }
050:
051: public void testNullFile() throws IOException {
052: try {
053: new ListBasedDifferenceStrategy(mockStrategy,
054: (BufferedReader) null);
055: fail("Created validator with null");
056: } catch (NullPointerException ex) {
057: // Expected
058: }
059: }
060:
061: public void testMissingFile1() {
062: try {
063: new ListBasedDifferenceStrategy(mockStrategy,
064: "no such file");
065: fail("Created validator with missing file");
066: } catch (IOException ex) {
067: // Expected
068: }
069: }
070:
071: public void testMissingFile2() {
072: File file = new File("no such file");
073: assertFalse("File exists", file.exists());
074:
075: try {
076: new ListBasedDifferenceStrategy(mockStrategy, file);
077: fail("Created validator with missing file");
078: } catch (IOException ex) {
079: // Expected
080: }
081: }
082:
083: public void testIsPackageDifferentNotInList() throws IOException {
084: Map oldPackage = new HashMap();
085: oldPackage.put("ModifiedPackage.ModifiedClass", getOldJar()
086: .getClassfile("ModifiedPackage.ModifiedClass"));
087: Map newPackage = new HashMap();
088: newPackage.put("ModifiedPackage.ModifiedClass", getNewJar()
089: .getClassfile("ModifiedPackage.ModifiedClass"));
090:
091: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
092: mockStrategy, new BufferedReader(new StringReader("")));
093: strategy.isPackageDifferent(oldPackage, newPackage);
094:
095: assertEquals("package", 0, mockStrategy
096: .getPackageDifferentCount());
097: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
098: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
099: assertEquals("constant", 0, mockStrategy
100: .getConstantValueDifferentCount());
101: assertEquals("method", 0, mockStrategy
102: .getMethodDifferentCount());
103: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
104: }
105:
106: public void testIsClassDifferentNotInList() throws IOException {
107: Classfile oldClass = getOldJar().getClassfile(
108: "ModifiedPackage.ModifiedClass");
109: Classfile newClass = getNewJar().getClassfile(
110: "ModifiedPackage.ModifiedClass");
111:
112: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
113: mockStrategy, new BufferedReader(new StringReader("")));
114: strategy.isClassDifferent(oldClass, newClass);
115:
116: assertEquals("package", 0, mockStrategy
117: .getPackageDifferentCount());
118: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
119: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
120: assertEquals("constant", 0, mockStrategy
121: .getConstantValueDifferentCount());
122: assertEquals("method", 0, mockStrategy
123: .getMethodDifferentCount());
124: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
125: }
126:
127: public void testIsFieldDifferentNotInList() throws IOException {
128: Field_info oldField = getOldJar().getClassfile(
129: "ModifiedPackage.ModifiedClass").getField(
130: "modifiedField");
131: Field_info newField = getNewJar().getClassfile(
132: "ModifiedPackage.ModifiedClass").getField(
133: "modifiedField");
134:
135: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
136: mockStrategy, new BufferedReader(new StringReader("")));
137: strategy.isFieldDifferent(oldField, newField);
138:
139: assertEquals("package", 0, mockStrategy
140: .getPackageDifferentCount());
141: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
142: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
143: assertEquals("constant", 0, mockStrategy
144: .getConstantValueDifferentCount());
145: assertEquals("method", 0, mockStrategy
146: .getMethodDifferentCount());
147: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
148: }
149:
150: public void testIsMethodDifferentNotInList() throws IOException {
151: Method_info oldMethod = getOldJar().getClassfile(
152: "ModifiedPackage.ModifiedClass").getMethod(
153: "modifiedMethod()");
154: Method_info newMethod = getNewJar().getClassfile(
155: "ModifiedPackage.ModifiedClass").getMethod(
156: "modifiedMethod()");
157:
158: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
159: mockStrategy, new BufferedReader(new StringReader("")));
160: strategy.isMethodDifferent(oldMethod, newMethod);
161:
162: assertEquals("package", 0, mockStrategy
163: .getPackageDifferentCount());
164: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
165: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
166: assertEquals("constant", 0, mockStrategy
167: .getConstantValueDifferentCount());
168: assertEquals("method", 0, mockStrategy
169: .getMethodDifferentCount());
170: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
171: }
172:
173: public void testIsCodeMethodDifferentNotInList() throws IOException {
174: Method_info oldMethod = getOldJar().getClassfile(
175: "ModifiedPackage.ModifiedClass").getMethod(
176: "modifiedCodeMethod()");
177: Method_info newMethod = getNewJar().getClassfile(
178: "ModifiedPackage.ModifiedClass").getMethod(
179: "modifiedCodeMethod()");
180:
181: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
182: mockStrategy, new BufferedReader(new StringReader("")));
183: strategy.isMethodDifferent(oldMethod, newMethod);
184:
185: assertEquals("package", 0, mockStrategy
186: .getPackageDifferentCount());
187: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
188: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
189: assertEquals("constant", 0, mockStrategy
190: .getConstantValueDifferentCount());
191: assertEquals("method", 0, mockStrategy
192: .getMethodDifferentCount());
193: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
194: }
195:
196: public void testIsCodeDifferentNotInList() throws IOException {
197: Code_attribute oldCode = getOldJar().getClassfile(
198: "ModifiedPackage.ModifiedClass").getMethod(
199: "modifiedCodeMethod()").getCode();
200: Code_attribute newCode = getNewJar().getClassfile(
201: "ModifiedPackage.ModifiedClass").getMethod(
202: "modifiedCodeMethod()").getCode();
203:
204: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
205: mockStrategy, new BufferedReader(new StringReader("")));
206: strategy.isCodeDifferent(oldCode, newCode);
207:
208: assertEquals("package", 0, mockStrategy
209: .getPackageDifferentCount());
210: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
211: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
212: assertEquals("constant", 0, mockStrategy
213: .getConstantValueDifferentCount());
214: assertEquals("method", 0, mockStrategy
215: .getMethodDifferentCount());
216: assertEquals("code", 1, mockStrategy.getCodeDifferentCount());
217: }
218:
219: public void testIsPackageDifferentInList() throws IOException {
220: Map oldPackage = new HashMap();
221: oldPackage.put("ModifiedPackage.ModifiedClass", getOldJar()
222: .getClassfile("ModifiedPackage.ModifiedClass"));
223: Map newPackage = new HashMap();
224: newPackage.put("ModifiedPackage.ModifiedClass", getNewJar()
225: .getClassfile("ModifiedPackage.ModifiedClass"));
226:
227: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
228: mockStrategy, new BufferedReader(new StringReader(
229: "ModifiedPackage")));
230: strategy.isPackageDifferent(oldPackage, newPackage);
231:
232: assertEquals("package", 1, mockStrategy
233: .getPackageDifferentCount());
234: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
235: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
236: assertEquals("constant", 0, mockStrategy
237: .getConstantValueDifferentCount());
238: assertEquals("method", 0, mockStrategy
239: .getMethodDifferentCount());
240: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
241: }
242:
243: public void testIsClassDifferentInList() throws IOException {
244: Classfile oldClass = getOldJar().getClassfile(
245: "ModifiedPackage.ModifiedClass");
246: Classfile newClass = getNewJar().getClassfile(
247: "ModifiedPackage.ModifiedClass");
248:
249: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
250: mockStrategy, new BufferedReader(new StringReader(
251: "ModifiedPackage.ModifiedClass")));
252: strategy.isClassDifferent(oldClass, newClass);
253:
254: assertEquals("package", 0, mockStrategy
255: .getPackageDifferentCount());
256: assertEquals("class", 1, mockStrategy.getClassDifferentCount());
257: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
258: assertEquals("constant", 0, mockStrategy
259: .getConstantValueDifferentCount());
260: assertEquals("method", 0, mockStrategy
261: .getMethodDifferentCount());
262: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
263: }
264:
265: public void testIsFieldDifferentInList() throws IOException {
266: Field_info oldField = getOldJar().getClassfile(
267: "ModifiedPackage.ModifiedClass").getField(
268: "modifiedField");
269: Field_info newField = getNewJar().getClassfile(
270: "ModifiedPackage.ModifiedClass").getField(
271: "modifiedField");
272:
273: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
274: mockStrategy, new BufferedReader(new StringReader(
275: "ModifiedPackage.ModifiedClass.modifiedField")));
276: strategy.isFieldDifferent(oldField, newField);
277:
278: assertEquals("package", 0, mockStrategy
279: .getPackageDifferentCount());
280: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
281: assertEquals("field", 1, mockStrategy.getFieldDifferentCount());
282: assertEquals("constant", 0, mockStrategy
283: .getConstantValueDifferentCount());
284: assertEquals("method", 0, mockStrategy
285: .getMethodDifferentCount());
286: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
287: }
288:
289: public void testIsMethodDifferentInList() throws IOException {
290: Method_info oldMethod = getOldJar().getClassfile(
291: "ModifiedPackage.ModifiedClass").getMethod(
292: "modifiedMethod()");
293: Method_info newMethod = getNewJar().getClassfile(
294: "ModifiedPackage.ModifiedClass").getMethod(
295: "modifiedMethod()");
296:
297: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
298: mockStrategy,
299: new BufferedReader(
300: new StringReader(
301: "ModifiedPackage.ModifiedClass.modifiedMethod()")));
302: strategy.isMethodDifferent(oldMethod, newMethod);
303:
304: assertEquals("package", 0, mockStrategy
305: .getPackageDifferentCount());
306: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
307: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
308: assertEquals("constant", 0, mockStrategy
309: .getConstantValueDifferentCount());
310: assertEquals("method", 1, mockStrategy
311: .getMethodDifferentCount());
312: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
313: }
314:
315: public void testIsCodeMethodDifferentInList() throws IOException {
316: Method_info oldMethod = getOldJar().getClassfile(
317: "ModifiedPackage.ModifiedClass").getMethod(
318: "modifiedCodeMethod()");
319: Method_info newMethod = getNewJar().getClassfile(
320: "ModifiedPackage.ModifiedClass").getMethod(
321: "modifiedCodeMethod()");
322:
323: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
324: mockStrategy,
325: new BufferedReader(
326: new StringReader(
327: "ModifiedPackage.ModifiedClass.modifiedCodeMethod()")));
328: strategy.isMethodDifferent(oldMethod, newMethod);
329:
330: assertEquals("package", 0, mockStrategy
331: .getPackageDifferentCount());
332: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
333: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
334: assertEquals("constant", 0, mockStrategy
335: .getConstantValueDifferentCount());
336: assertEquals("method", 1, mockStrategy
337: .getMethodDifferentCount());
338: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
339: }
340:
341: public void testIsCodeDifferentInList() throws IOException {
342: Code_attribute oldCode = getOldJar().getClassfile(
343: "ModifiedPackage.ModifiedClass").getMethod(
344: "modifiedCodeMethod()").getCode();
345: Code_attribute newCode = getNewJar().getClassfile(
346: "ModifiedPackage.ModifiedClass").getMethod(
347: "modifiedCodeMethod()").getCode();
348:
349: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
350: mockStrategy,
351: new BufferedReader(
352: new StringReader(
353: "ModifiedPackage.ModifiedClass.modifiedCodeMethod()")));
354: strategy.isCodeDifferent(oldCode, newCode);
355:
356: assertEquals("package", 0, mockStrategy
357: .getPackageDifferentCount());
358: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
359: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
360: assertEquals("constant", 0, mockStrategy
361: .getConstantValueDifferentCount());
362: assertEquals("method", 0, mockStrategy
363: .getMethodDifferentCount());
364: assertEquals("code", 1, mockStrategy.getCodeDifferentCount());
365: }
366:
367: public void testIsPackageDifferentInListWithSuffix()
368: throws IOException {
369: Map oldPackage = new HashMap();
370: oldPackage.put("ModifiedPackage.ModifiedClass", getOldJar()
371: .getClassfile("ModifiedPackage.ModifiedClass"));
372: Map newPackage = new HashMap();
373: newPackage.put("ModifiedPackage.ModifiedClass", getNewJar()
374: .getClassfile("ModifiedPackage.ModifiedClass"));
375:
376: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
377: mockStrategy, new BufferedReader(new StringReader(
378: "ModifiedPackage [P]")));
379: strategy.isPackageDifferent(oldPackage, newPackage);
380:
381: assertEquals("package", 1, mockStrategy
382: .getPackageDifferentCount());
383: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
384: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
385: assertEquals("constant", 0, mockStrategy
386: .getConstantValueDifferentCount());
387: assertEquals("method", 0, mockStrategy
388: .getMethodDifferentCount());
389: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
390: }
391:
392: public void testIsClassDifferentInListWithSuffix()
393: throws IOException {
394: Classfile oldClass = getOldJar().getClassfile(
395: "ModifiedPackage.ModifiedClass");
396: Classfile newClass = getNewJar().getClassfile(
397: "ModifiedPackage.ModifiedClass");
398:
399: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
400: mockStrategy, new BufferedReader(new StringReader(
401: "ModifiedPackage.ModifiedClass [C]")));
402: strategy.isClassDifferent(oldClass, newClass);
403:
404: assertEquals("package", 0, mockStrategy
405: .getPackageDifferentCount());
406: assertEquals("class", 1, mockStrategy.getClassDifferentCount());
407: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
408: assertEquals("constant", 0, mockStrategy
409: .getConstantValueDifferentCount());
410: assertEquals("method", 0, mockStrategy
411: .getMethodDifferentCount());
412: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
413: }
414:
415: public void testIsFieldDifferentInListWithSuffix()
416: throws IOException {
417: Field_info oldField = getOldJar().getClassfile(
418: "ModifiedPackage.ModifiedClass").getField(
419: "modifiedField");
420: Field_info newField = getNewJar().getClassfile(
421: "ModifiedPackage.ModifiedClass").getField(
422: "modifiedField");
423:
424: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
425: mockStrategy,
426: new BufferedReader(
427: new StringReader(
428: "ModifiedPackage.ModifiedClass.modifiedField [F]")));
429: strategy.isFieldDifferent(oldField, newField);
430:
431: assertEquals("package", 0, mockStrategy
432: .getPackageDifferentCount());
433: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
434: assertEquals("field", 1, mockStrategy.getFieldDifferentCount());
435: assertEquals("constant", 0, mockStrategy
436: .getConstantValueDifferentCount());
437: assertEquals("method", 0, mockStrategy
438: .getMethodDifferentCount());
439: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
440: }
441:
442: public void testIsMethodDifferentInListWithSuffix()
443: throws IOException {
444: Method_info oldMethod = getOldJar().getClassfile(
445: "ModifiedPackage.ModifiedClass").getMethod(
446: "modifiedMethod()");
447: Method_info newMethod = getNewJar().getClassfile(
448: "ModifiedPackage.ModifiedClass").getMethod(
449: "modifiedMethod()");
450:
451: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
452: mockStrategy,
453: new BufferedReader(
454: new StringReader(
455: "ModifiedPackage.ModifiedClass.modifiedMethod() [F]")));
456: strategy.isMethodDifferent(oldMethod, newMethod);
457:
458: assertEquals("package", 0, mockStrategy
459: .getPackageDifferentCount());
460: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
461: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
462: assertEquals("constant", 0, mockStrategy
463: .getConstantValueDifferentCount());
464: assertEquals("method", 1, mockStrategy
465: .getMethodDifferentCount());
466: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
467: }
468:
469: public void testIsCodeMethodDifferentInListWithSuffix()
470: throws IOException {
471: Method_info oldMethod = getOldJar().getClassfile(
472: "ModifiedPackage.ModifiedClass").getMethod(
473: "modifiedCodeMethod()");
474: Method_info newMethod = getNewJar().getClassfile(
475: "ModifiedPackage.ModifiedClass").getMethod(
476: "modifiedCodeMethod()");
477:
478: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
479: mockStrategy,
480: new BufferedReader(
481: new StringReader(
482: "ModifiedPackage.ModifiedClass.modifiedCodeMethod() [F]")));
483: strategy.isMethodDifferent(oldMethod, newMethod);
484:
485: assertEquals("package", 0, mockStrategy
486: .getPackageDifferentCount());
487: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
488: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
489: assertEquals("constant", 0, mockStrategy
490: .getConstantValueDifferentCount());
491: assertEquals("method", 1, mockStrategy
492: .getMethodDifferentCount());
493: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
494: }
495:
496: public void testIsCodeDifferentInListWithSuffix()
497: throws IOException {
498: Code_attribute oldCode = getOldJar().getClassfile(
499: "ModifiedPackage.ModifiedClass").getMethod(
500: "modifiedCodeMethod()").getCode();
501: Code_attribute newCode = getNewJar().getClassfile(
502: "ModifiedPackage.ModifiedClass").getMethod(
503: "modifiedCodeMethod()").getCode();
504:
505: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
506: mockStrategy,
507: new BufferedReader(
508: new StringReader(
509: "ModifiedPackage.ModifiedClass.modifiedCodeMethod() [F]")));
510: strategy.isCodeDifferent(oldCode, newCode);
511:
512: assertEquals("package", 0, mockStrategy
513: .getPackageDifferentCount());
514: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
515: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
516: assertEquals("constant", 0, mockStrategy
517: .getConstantValueDifferentCount());
518: assertEquals("method", 0, mockStrategy
519: .getMethodDifferentCount());
520: assertEquals("code", 1, mockStrategy.getCodeDifferentCount());
521: }
522:
523: public void testIsConstantValueDifferent() throws IOException {
524: ConstantValue_attribute oldConstantValue = getOldJar()
525: .getClassfile("ModifiedPackage.ModifiedInterface")
526: .getField("modifiedValueField").getConstantValue();
527: ConstantValue_attribute newConstantValue = getNewJar()
528: .getClassfile("ModifiedPackage.ModifiedInterface")
529: .getField("modifiedValueField").getConstantValue();
530:
531: DifferenceStrategy strategy = new ListBasedDifferenceStrategy(
532: mockStrategy, new BufferedReader(new StringReader("")));
533: strategy.isConstantValueDifferent(oldConstantValue,
534: newConstantValue);
535:
536: assertEquals("package", 0, mockStrategy
537: .getPackageDifferentCount());
538: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
539: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
540: assertEquals("constant", 1, mockStrategy
541: .getConstantValueDifferentCount());
542: assertEquals("method", 0, mockStrategy
543: .getMethodDifferentCount());
544: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
545: }
546:
547: public void testMerge() throws IOException {
548: Map oldPackage1 = new HashMap();
549: oldPackage1.put("ModifiedPackage.ModifiedClass", getOldJar()
550: .getClassfile("ModifiedPackage.ModifiedClass"));
551: Map newPackage1 = new HashMap();
552: newPackage1.put("ModifiedPackage.ModifiedClass", getNewJar()
553: .getClassfile("ModifiedPackage.ModifiedClass"));
554:
555: Map oldPackage2 = new HashMap();
556: oldPackage2.put("UnmodifiedPackage.UnmodifiedClass",
557: getOldJar().getClassfile(
558: "UnmodifiedPackage.UnmodifiedClass"));
559: Map newPackage2 = new HashMap();
560: newPackage2.put("UnmodifiedPackage.UnmodifiedClass",
561: getNewJar().getClassfile(
562: "UnmodifiedPackage.UnmodifiedClass"));
563:
564: ListBasedDifferenceStrategy strategy = new ListBasedDifferenceStrategy(
565: mockStrategy, new BufferedReader(new StringReader("")));
566:
567: strategy.isPackageDifferent(oldPackage1, newPackage1);
568: strategy.isPackageDifferent(oldPackage2, newPackage2);
569: assertEquals("package", 0, mockStrategy
570: .getPackageDifferentCount());
571: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
572: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
573: assertEquals("constant", 0, mockStrategy
574: .getConstantValueDifferentCount());
575: assertEquals("method", 0, mockStrategy
576: .getMethodDifferentCount());
577: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
578:
579: strategy.load(new BufferedReader(new StringReader(
580: "ModifiedPackage")));
581:
582: strategy.isPackageDifferent(oldPackage1, newPackage1);
583: strategy.isPackageDifferent(oldPackage2, newPackage2);
584: assertEquals("package", 1, mockStrategy
585: .getPackageDifferentCount());
586: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
587: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
588: assertEquals("constant", 0, mockStrategy
589: .getConstantValueDifferentCount());
590: assertEquals("method", 0, mockStrategy
591: .getMethodDifferentCount());
592: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
593:
594: strategy.load(new BufferedReader(new StringReader(
595: "UnmodifiedPackage")));
596:
597: strategy.isPackageDifferent(oldPackage1, newPackage1);
598: strategy.isPackageDifferent(oldPackage2, newPackage2);
599: assertEquals("package", 3, mockStrategy
600: .getPackageDifferentCount());
601: assertEquals("class", 0, mockStrategy.getClassDifferentCount());
602: assertEquals("field", 0, mockStrategy.getFieldDifferentCount());
603: assertEquals("constant", 0, mockStrategy
604: .getConstantValueDifferentCount());
605: assertEquals("method", 0, mockStrategy
606: .getMethodDifferentCount());
607: assertEquals("code", 0, mockStrategy.getCodeDifferentCount());
608: }
609: }
|