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 junit.framework.*;
039:
040: import com.jeantessier.classreader.*;
041:
042: /**
043: *
044: */
045: public class TestDifferencesFactoryForCompatibleClassWithIncompatibleMethod
046: extends TestCase {
047: public static final String OLD_PUBLISHED_CLASSPATH = "tests"
048: + File.separator + "JarJarDiff" + File.separator
049: + "oldpublished";
050: public static final String NEW_PUBLISHED_CLASSPATH = "tests"
051: + File.separator + "JarJarDiff" + File.separator
052: + "newpublished";
053:
054: private PackageMapper oldPublishedPackages;
055: private PackageMapper newPublishedPackages;
056:
057: private ClassfileLoader oldPublishedJar;
058: private ClassfileLoader newPublishedJar;
059:
060: private DifferencesFactory factory;
061:
062: public PackageMapper getOldPublishedPackages() {
063: return oldPublishedPackages;
064: }
065:
066: public PackageMapper getNewPublishedPackages() {
067: return newPublishedPackages;
068: }
069:
070: public ClassfileLoader getOldPublishedJar() {
071: return oldPublishedJar;
072: }
073:
074: public ClassfileLoader getNewPublishedJar() {
075: return newPublishedJar;
076: }
077:
078: protected void setUp() throws Exception {
079: super .setUp();
080:
081: oldPublishedPackages = new PackageMapper();
082: newPublishedPackages = new PackageMapper();
083:
084: oldPublishedJar = new AggregatingClassfileLoader();
085: oldPublishedJar.addLoadListener(oldPublishedPackages);
086: oldPublishedJar.load(Collections
087: .singleton(OLD_PUBLISHED_CLASSPATH));
088:
089: newPublishedJar = new AggregatingClassfileLoader();
090: newPublishedJar.addLoadListener(newPublishedPackages);
091: newPublishedJar.load(Collections
092: .singleton(NEW_PUBLISHED_CLASSPATH));
093:
094: factory = new DifferencesFactory(
095: new IncompatibleDifferenceStrategy(
096: new NoDifferenceStrategy()));
097: }
098:
099: public void testCompatibleClassWithIncompatibleMethod() {
100: String className = "ModifiedPackage.CompatibleClass";
101: Classfile oldClass = getOldPublishedJar().getClassfile(
102: className);
103: Classfile newClass = getNewPublishedJar().getClassfile(
104: className);
105:
106: ClassDifferences classDifferences = (ClassDifferences) factory
107: .createClassDifferences(className, oldClass, newClass);
108: assertFalse(classDifferences.isDeclarationModified());
109: assertTrue(classDifferences.isModified());
110:
111: MethodDifferences methodDifferences = null;
112: Iterator i = classDifferences.getFeatureDifferences()
113: .iterator();
114: while (i.hasNext()) {
115: Differences differences = (Differences) i.next();
116: if (differences.getName().equals(
117: className + ".incompatibleMethod()")) {
118: methodDifferences = (MethodDifferences) differences;
119: }
120: }
121:
122: assertTrue(methodDifferences.isModified());
123: }
124: }
|