1 | /* |
2 | * Copyright (c) 2001-2009, Jean Tessier |
3 | * All rights reserved. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * |
9 | * * Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * |
12 | * * Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
15 | * |
16 | * * Neither the name of Jean Tessier nor the names of his contributors |
17 | * may be used to endorse or promote products derived from this software |
18 | * without specific prior written permission. |
19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR |
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | */ |
32 | |
33 | package com.jeantessier.diff; |
34 | |
35 | import java.util.*; |
36 | |
37 | import com.jeantessier.classreader.*; |
38 | |
39 | public class TestDifferencesFactoryWithIncompatibleDifferenceStrategy extends TestDifferencesFactoryBase { |
40 | private DifferencesFactory factory; |
41 | |
42 | protected void setUp() throws Exception { |
43 | super.setUp(); |
44 | |
45 | factory = new DifferencesFactory(new IncompatibleDifferenceStrategy(new NoDifferenceStrategy())); |
46 | } |
47 | |
48 | public void testFieldDeclarationDifference() { |
49 | String className = "ModifiedPackage.ModifiedInterface"; |
50 | Classfile oldClass = getOldJar().getClassfile(className); |
51 | Classfile newClass = getNewJar().getClassfile(className); |
52 | |
53 | ClassDifferences classDifferences = (ClassDifferences) factory.createClassDifferences(className, oldClass, newClass); |
54 | |
55 | FieldDifferences fieldDifferences = null; |
56 | Iterator i = classDifferences.getFeatureDifferences().iterator(); |
57 | while (i.hasNext()) { |
58 | Differences differences = (Differences) i.next(); |
59 | if (differences.getName().equals(className + ".modifiedField")) { |
60 | fieldDifferences = (FieldDifferences) differences; |
61 | } |
62 | } |
63 | |
64 | assertEquals("public static final int modifiedField", fieldDifferences.getOldDeclaration()); |
65 | assertEquals("public static final float modifiedField", fieldDifferences.getNewDeclaration()); |
66 | } |
67 | |
68 | public void testFieldConstantValueDifference() { |
69 | String className = "ModifiedPackage.ModifiedInterface"; |
70 | Classfile oldClass = getOldJar().getClassfile(className); |
71 | Classfile newClass = getNewJar().getClassfile(className); |
72 | |
73 | ClassDifferences classDifferences = (ClassDifferences) factory.createClassDifferences(className, oldClass, newClass); |
74 | |
75 | FieldDifferences fieldDifferences = null; |
76 | Iterator i = classDifferences.getFeatureDifferences().iterator(); |
77 | while (i.hasNext()) { |
78 | Differences differences = (Differences) i.next(); |
79 | if (differences.getName().equals(className + ".modifiedValueField")) { |
80 | fieldDifferences = (FieldDifferences) differences; |
81 | } |
82 | } |
83 | |
84 | assertNull(fieldDifferences); |
85 | } |
86 | |
87 | public void testConstructorDifference() { |
88 | String className = "ModifiedPackage.ModifiedClass"; |
89 | Classfile oldClass = getOldJar().getClassfile(className); |
90 | Classfile newClass = getNewJar().getClassfile(className); |
91 | |
92 | ClassDifferences classDifferences = (ClassDifferences) factory.createClassDifferences(className, oldClass, newClass); |
93 | |
94 | ConstructorDifferences constructorDifferences = null; |
95 | Iterator i = classDifferences.getFeatureDifferences().iterator(); |
96 | while (i.hasNext()) { |
97 | Differences differences = (Differences) i.next(); |
98 | if (differences.getName().equals(className + ".ModifiedClass(int, int, int)")) { |
99 | constructorDifferences = (ConstructorDifferences) differences; |
100 | } |
101 | } |
102 | |
103 | assertFalse(constructorDifferences.isCodeDifference()); |
104 | } |
105 | |
106 | public void testConstructorCodeDifference() { |
107 | String className = "ModifiedPackage.ModifiedClass"; |
108 | Classfile oldClass = getOldJar().getClassfile(className); |
109 | Classfile newClass = getNewJar().getClassfile(className); |
110 | |
111 | ClassDifferences classDifferences = (ClassDifferences) factory.createClassDifferences(className, oldClass, newClass); |
112 | |
113 | ConstructorDifferences constructorDifferences = null; |
114 | Iterator i = classDifferences.getFeatureDifferences().iterator(); |
115 | while (i.hasNext()) { |
116 | Differences differences = (Differences) i.next(); |
117 | if (differences.getName().equals(className + ".ModifiedClass(float)")) { |
118 | constructorDifferences = (ConstructorDifferences) differences; |
119 | } |
120 | } |
121 | |
122 | assertNull(constructorDifferences); |
123 | } |
124 | |
125 | public void testMethodDifference() { |
126 | String className = "ModifiedPackage.ModifiedClass"; |
127 | Classfile oldClass = getOldJar().getClassfile(className); |
128 | Classfile newClass = getNewJar().getClassfile(className); |
129 | |
130 | ClassDifferences classDifferences = (ClassDifferences) factory.createClassDifferences(className, oldClass, newClass); |
131 | |
132 | MethodDifferences methodDifferences = null; |
133 | Iterator i = classDifferences.getFeatureDifferences().iterator(); |
134 | while (i.hasNext()) { |
135 | Differences differences = (Differences) i.next(); |
136 | if (differences.getName().equals(className + ".modifiedMethod()")) { |
137 | methodDifferences = (MethodDifferences) differences; |
138 | } |
139 | } |
140 | |
141 | assertNotNull(methodDifferences); |
142 | assertTrue(methodDifferences.isModified()); |
143 | assertFalse(methodDifferences.isCodeDifference()); |
144 | } |
145 | |
146 | public void testMethodCodeDifference() { |
147 | String className = "ModifiedPackage.ModifiedClass"; |
148 | Classfile oldClass = getOldJar().getClassfile(className); |
149 | Classfile newClass = getNewJar().getClassfile(className); |
150 | |
151 | ClassDifferences classDifferences = (ClassDifferences) factory.createClassDifferences(className, oldClass, newClass); |
152 | |
153 | MethodDifferences methodDifferences = null; |
154 | Iterator i = classDifferences.getFeatureDifferences().iterator(); |
155 | while (i.hasNext()) { |
156 | Differences differences = (Differences) i.next(); |
157 | if (differences.getName().equals(className + ".modifiedCodeMethod()")) { |
158 | methodDifferences = (MethodDifferences) differences; |
159 | } |
160 | } |
161 | |
162 | assertNull(methodDifferences); |
163 | } |
164 | } |