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 TestDifferencesFactoryWithAPIAndCodeDifferenceStrategy
040: extends TestDifferencesFactoryBase {
041: private DifferencesFactory factory;
042:
043: protected void setUp() throws Exception {
044: super .setUp();
045:
046: factory = new DifferencesFactory(new APIDifferenceStrategy(
047: new CodeDifferenceStrategy()));
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: assertTrue(fieldDifferences.isConstantValueDifference());
095: assertEquals("public static final int modifiedValueField",
096: fieldDifferences.getOldDeclaration());
097: assertEquals("public static final int modifiedValueField",
098: fieldDifferences.getNewDeclaration());
099: }
100:
101: public void testConstructorDifference() {
102: String className = "ModifiedPackage.ModifiedClass";
103: Classfile oldClass = getOldJar().getClassfile(className);
104: Classfile newClass = getNewJar().getClassfile(className);
105:
106: ClassDifferences classDifferences = (ClassDifferences) factory
107: .createClassDifferences(className, oldClass, newClass);
108:
109: ConstructorDifferences constructorDifferences = null;
110: Iterator i = classDifferences.getFeatureDifferences()
111: .iterator();
112: while (i.hasNext()) {
113: Differences differences = (Differences) i.next();
114: if (differences.getName().equals(
115: className + ".ModifiedClass(int, int, int)")) {
116: constructorDifferences = (ConstructorDifferences) differences;
117: }
118: }
119:
120: assertFalse(constructorDifferences.isCodeDifference());
121: }
122:
123: public void testConstructorCodeDifference() {
124: String className = "ModifiedPackage.ModifiedClass";
125: Classfile oldClass = getOldJar().getClassfile(className);
126: Classfile newClass = getNewJar().getClassfile(className);
127:
128: ClassDifferences classDifferences = (ClassDifferences) factory
129: .createClassDifferences(className, oldClass, newClass);
130:
131: ConstructorDifferences constructorDifferences = null;
132: Iterator i = classDifferences.getFeatureDifferences()
133: .iterator();
134: while (i.hasNext()) {
135: Differences differences = (Differences) i.next();
136: if (differences.getName().equals(
137: className + ".ModifiedClass(float)")) {
138: constructorDifferences = (ConstructorDifferences) differences;
139: }
140: }
141:
142: assertTrue(constructorDifferences.isCodeDifference());
143: }
144:
145: public void testMethodDifference() {
146: String className = "ModifiedPackage.ModifiedClass";
147: Classfile oldClass = getOldJar().getClassfile(className);
148: Classfile newClass = getNewJar().getClassfile(className);
149:
150: ClassDifferences classDifferences = (ClassDifferences) factory
151: .createClassDifferences(className, oldClass, newClass);
152:
153: MethodDifferences methodDifferences = null;
154: Iterator i = classDifferences.getFeatureDifferences()
155: .iterator();
156: while (i.hasNext()) {
157: Differences differences = (Differences) i.next();
158: if (differences.getName().equals(
159: className + ".modifiedMethod()")) {
160: methodDifferences = (MethodDifferences) differences;
161: }
162: }
163:
164: assertTrue(methodDifferences.isCodeDifference());
165: }
166:
167: public void testMethodCodeDifference() {
168: String className = "ModifiedPackage.ModifiedClass";
169: Classfile oldClass = getOldJar().getClassfile(className);
170: Classfile newClass = getNewJar().getClassfile(className);
171:
172: ClassDifferences classDifferences = (ClassDifferences) factory
173: .createClassDifferences(className, oldClass, newClass);
174:
175: MethodDifferences methodDifferences = null;
176: Iterator i = classDifferences.getFeatureDifferences()
177: .iterator();
178: while (i.hasNext()) {
179: Differences differences = (Differences) i.next();
180: if (differences.getName().equals(
181: className + ".modifiedCodeMethod()")) {
182: methodDifferences = (MethodDifferences) differences;
183: }
184: }
185:
186: assertTrue(methodDifferences.isCodeDifference());
187: }
188: }
|