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