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: public class TestDeprecatableDifferences extends TestCase {
043: private DifferencesFactory factory;
044: private ClassfileLoader oldLoader;
045: private ClassfileLoader newLoader;
046:
047: protected void setUp() throws Exception {
048: factory = new DifferencesFactory();
049:
050: oldLoader = new AggregatingClassfileLoader();
051: oldLoader.load(Collections.singleton("tests" + File.separator
052: + "JarJarDiff" + File.separator + "old"));
053:
054: newLoader = new AggregatingClassfileLoader();
055: newLoader.load(Collections.singleton("tests" + File.separator
056: + "JarJarDiff" + File.separator + "new"));
057: }
058:
059: public void testNotDeprecatedNotDeprecatedDifferent() {
060: String name = "ModifiedPackage.ModifiedClass";
061: Classfile oldClassfile = oldLoader.getClassfile(name);
062: assertNotNull(oldClassfile);
063: Classfile newClassfile = newLoader.getClassfile(name);
064: assertNotNull(newClassfile);
065: Differences componentDifferences = factory
066: .createClassDifferences(name, oldClassfile,
067: newClassfile);
068:
069: DeprecatableDifferences deprecatedDifferences = new DeprecatableDifferences(
070: componentDifferences, oldClassfile, newClassfile);
071: assertTrue("deprecated NewDeprecation()",
072: !deprecatedDifferences.isNewDeprecation());
073: assertTrue("deprecated RemovedDeprecation()",
074: !deprecatedDifferences.isRemovedDeprecation());
075: }
076:
077: public void testNotDeprecatedNotDeprecatedSame() {
078: String name = "ModifiedPackage.ModifiedClass";
079: Classfile oldClassfile = newLoader.getClassfile(name);
080: assertNotNull(oldClassfile);
081: Classfile newClassfile = newLoader.getClassfile(name);
082: assertNotNull(newClassfile);
083: Differences componentDifferences = new ClassDifferences(name,
084: oldClassfile, newClassfile);
085:
086: DeprecatableDifferences deprecatedDifferences = new DeprecatableDifferences(
087: componentDifferences, oldClassfile, newClassfile);
088: assertTrue("deprecated NewDeprecation()",
089: !deprecatedDifferences.isNewDeprecation());
090: assertTrue("deprecated RemovedDeprecation()",
091: !deprecatedDifferences.isRemovedDeprecation());
092: }
093:
094: public void testDeprecatedNotDeprecated() {
095: String name = "ModifiedPackage.UndeprecatedClass";
096: Classfile oldClassfile = oldLoader.getClassfile(name);
097: assertNotNull(oldClassfile);
098: Classfile newClassfile = newLoader.getClassfile(name);
099: assertNotNull(newClassfile);
100: Differences componentDifferences = new ClassDifferences(name,
101: oldClassfile, newClassfile);
102:
103: DeprecatableDifferences deprecatedDifferences = new DeprecatableDifferences(
104: componentDifferences, oldClassfile, newClassfile);
105: assertTrue("deprecated NewDeprecation()",
106: !deprecatedDifferences.isNewDeprecation());
107: assertTrue("deprecated RemovedDeprecation()",
108: deprecatedDifferences.isRemovedDeprecation());
109: }
110:
111: public void testNotDeprecatedDeprecated() {
112: String name = "ModifiedPackage.DeprecatedClass";
113: Classfile oldClassfile = oldLoader.getClassfile(name);
114: assertNotNull(oldClassfile);
115: Classfile newClassfile = newLoader.getClassfile(name);
116: assertNotNull(newClassfile);
117: Differences componentDifferences = new ClassDifferences(name,
118: oldClassfile, newClassfile);
119:
120: DeprecatableDifferences deprecatedDifferences = new DeprecatableDifferences(
121: componentDifferences, oldClassfile, newClassfile);
122: assertTrue("deprecated NewDeprecation()", deprecatedDifferences
123: .isNewDeprecation());
124: assertTrue("deprecated RemovedDeprecation()",
125: !deprecatedDifferences.isRemovedDeprecation());
126: }
127:
128: public void testDeprecatedDeprecated() {
129: String name = "ModifiedPackage.DeprecatedClass";
130: Classfile oldClassfile = newLoader.getClassfile(name);
131: assertNotNull(oldClassfile);
132: Classfile newClassfile = newLoader.getClassfile(name);
133: assertNotNull(newClassfile);
134: Differences componentDifferences = new ClassDifferences(name,
135: oldClassfile, newClassfile);
136:
137: DeprecatableDifferences deprecatedDifferences = new DeprecatableDifferences(
138: componentDifferences, oldClassfile, newClassfile);
139: assertTrue("deprecated NewDeprecation()",
140: !deprecatedDifferences.isNewDeprecation());
141: assertTrue("deprecated RemovedDeprecation()",
142: !deprecatedDifferences.isRemovedDeprecation());
143: }
144: }
|