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 TestDifferencesFactoryWithIncompatibleDifferenceStrategy
040: extends TestDifferencesFactoryBase {
041: private DifferencesFactory factory;
042:
043: protected void setUp() throws Exception {
044: super .setUp();
045:
046: factory = new DifferencesFactory(
047: new IncompatibleDifferenceStrategy(
048: new NoDifferenceStrategy()));
049: }
050:
051: public void testFieldDeclarationDifference() {
052: String className = "ModifiedPackage.ModifiedInterface";
053: Classfile oldClass = getOldJar().getClassfile(className);
054: Classfile newClass = getNewJar().getClassfile(className);
055:
056: ClassDifferences classDifferences = (ClassDifferences) factory
057: .createClassDifferences(className, oldClass, newClass);
058:
059: FieldDifferences fieldDifferences = null;
060: Iterator i = classDifferences.getFeatureDifferences()
061: .iterator();
062: while (i.hasNext()) {
063: Differences differences = (Differences) i.next();
064: if (differences.getName().equals(
065: className + ".modifiedField")) {
066: fieldDifferences = (FieldDifferences) differences;
067: }
068: }
069:
070: assertEquals("public static final int modifiedField",
071: fieldDifferences.getOldDeclaration());
072: assertEquals("public static final float modifiedField",
073: fieldDifferences.getNewDeclaration());
074: }
075:
076: public void testFieldConstantValueDifference() {
077: String className = "ModifiedPackage.ModifiedInterface";
078: Classfile oldClass = getOldJar().getClassfile(className);
079: Classfile newClass = getNewJar().getClassfile(className);
080:
081: ClassDifferences classDifferences = (ClassDifferences) factory
082: .createClassDifferences(className, oldClass, newClass);
083:
084: FieldDifferences fieldDifferences = null;
085: Iterator i = classDifferences.getFeatureDifferences()
086: .iterator();
087: while (i.hasNext()) {
088: Differences differences = (Differences) i.next();
089: if (differences.getName().equals(
090: className + ".modifiedValueField")) {
091: fieldDifferences = (FieldDifferences) differences;
092: }
093: }
094:
095: assertNull(fieldDifferences);
096: }
097:
098: public void testConstructorDifference() {
099: String className = "ModifiedPackage.ModifiedClass";
100: Classfile oldClass = getOldJar().getClassfile(className);
101: Classfile newClass = getNewJar().getClassfile(className);
102:
103: ClassDifferences classDifferences = (ClassDifferences) factory
104: .createClassDifferences(className, oldClass, newClass);
105:
106: ConstructorDifferences constructorDifferences = null;
107: Iterator i = classDifferences.getFeatureDifferences()
108: .iterator();
109: while (i.hasNext()) {
110: Differences differences = (Differences) i.next();
111: if (differences.getName().equals(
112: className + ".ModifiedClass(int, int, int)")) {
113: constructorDifferences = (ConstructorDifferences) differences;
114: }
115: }
116:
117: assertFalse(constructorDifferences.isCodeDifference());
118: }
119:
120: public void testConstructorCodeDifference() {
121: String className = "ModifiedPackage.ModifiedClass";
122: Classfile oldClass = getOldJar().getClassfile(className);
123: Classfile newClass = getNewJar().getClassfile(className);
124:
125: ClassDifferences classDifferences = (ClassDifferences) factory
126: .createClassDifferences(className, oldClass, newClass);
127:
128: ConstructorDifferences constructorDifferences = null;
129: Iterator i = classDifferences.getFeatureDifferences()
130: .iterator();
131: while (i.hasNext()) {
132: Differences differences = (Differences) i.next();
133: if (differences.getName().equals(
134: className + ".ModifiedClass(float)")) {
135: constructorDifferences = (ConstructorDifferences) differences;
136: }
137: }
138:
139: assertNull(constructorDifferences);
140: }
141:
142: public void testMethodDifference() {
143: String className = "ModifiedPackage.ModifiedClass";
144: Classfile oldClass = getOldJar().getClassfile(className);
145: Classfile newClass = getNewJar().getClassfile(className);
146:
147: ClassDifferences classDifferences = (ClassDifferences) factory
148: .createClassDifferences(className, oldClass, newClass);
149:
150: MethodDifferences methodDifferences = null;
151: Iterator i = classDifferences.getFeatureDifferences()
152: .iterator();
153: while (i.hasNext()) {
154: Differences differences = (Differences) i.next();
155: if (differences.getName().equals(
156: className + ".modifiedMethod()")) {
157: methodDifferences = (MethodDifferences) differences;
158: }
159: }
160:
161: assertNotNull(methodDifferences);
162: assertTrue(methodDifferences.isModified());
163: assertFalse(methodDifferences.isCodeDifference());
164: }
165:
166: public void testMethodCodeDifference() {
167: String className = "ModifiedPackage.ModifiedClass";
168: Classfile oldClass = getOldJar().getClassfile(className);
169: Classfile newClass = getNewJar().getClassfile(className);
170:
171: ClassDifferences classDifferences = (ClassDifferences) factory
172: .createClassDifferences(className, oldClass, newClass);
173:
174: MethodDifferences methodDifferences = null;
175: Iterator i = classDifferences.getFeatureDifferences()
176: .iterator();
177: while (i.hasNext()) {
178: Differences differences = (Differences) i.next();
179: if (differences.getName().equals(
180: className + ".modifiedCodeMethod()")) {
181: methodDifferences = (MethodDifferences) differences;
182: }
183: }
184:
185: assertNull(methodDifferences);
186: }
187: }
|