KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > diff > TestDeprecatableDifferences


1 /*
2  * Copyright (c) 2001-2005, 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.io.*;
36 import java.util.*;
37
38 import junit.framework.*;
39
40 import com.jeantessier.classreader.*;
41
42 public class TestDeprecatableDifferences extends TestCase {
43     private DifferencesFactory factory;
44     private ClassfileLoader oldLoader;
45     private ClassfileLoader newLoader;
46
47     protected void setUp() throws Exception JavaDoc {
48         Validator validator = new ListBasedValidator(new BufferedReader(new StringReader("")));
49         factory = new DifferencesFactory(validator, validator);
50         
51         oldLoader = new AggregatingClassfileLoader();
52         oldLoader.load(Collections.singleton("tests" + File.separator + "JarJarDiff" + File.separator + "old"));
53
54         newLoader = new AggregatingClassfileLoader();
55         newLoader.load(Collections.singleton("tests" + File.separator + "JarJarDiff" + File.separator + "new"));
56     }
57
58     public void testNotDeprecatedNotDeprecatedDifferent() {
59         String JavaDoc name = "ModifiedPackage.ModifiedClass";
60         Classfile oldClassfile = oldLoader.getClassfile(name);
61         assertNotNull(oldClassfile);
62         Classfile newClassfile = newLoader.getClassfile(name);
63         assertNotNull(newClassfile);
64         Differences componentDifferences = factory.createClassDifferences(name, oldClassfile, newClassfile);
65         assertTrue("component IsEmpty()", !componentDifferences.isEmpty());
66
67         DeprecatableDifferences deprecatedDifferences = new DeprecatableDifferences(componentDifferences, oldClassfile, newClassfile);
68         
69         assertTrue("deprecated NewDeprecation()", !deprecatedDifferences.isNewDeprecation());
70         assertTrue("deprecated RemovedDeprecation()", !deprecatedDifferences.isRemovedDeprecation());
71         assertTrue("deprecated IsEmpty()", !deprecatedDifferences.isEmpty());
72     }
73
74     public void testNotDeprecatedNotDeprecatedSame() {
75         String JavaDoc name = "ModifiedPackage.ModifiedClass";
76         Classfile oldClassfile = newLoader.getClassfile(name);
77         assertNotNull(oldClassfile);
78         Classfile newClassfile = newLoader.getClassfile(name);
79         assertNotNull(newClassfile);
80         Differences componentDifferences = new ClassDifferences(name, oldClassfile, newClassfile);
81         assertTrue("component IsEmpty()", componentDifferences.isEmpty());
82
83         DeprecatableDifferences deprecatedDifferences = new DeprecatableDifferences(componentDifferences, oldClassfile, newClassfile);
84         
85         assertTrue("deprecated NewDeprecation()", !deprecatedDifferences.isNewDeprecation());
86         assertTrue("deprecated RemovedDeprecation()", !deprecatedDifferences.isRemovedDeprecation());
87         assertTrue("deprecated IsEmpty()", deprecatedDifferences.isEmpty());
88     }
89
90     public void testDeprecatedNotDeprecated() {
91         String JavaDoc name = "ModifiedPackage.UndeprecatedClass";
92         Classfile oldClassfile = oldLoader.getClassfile(name);
93         assertNotNull(oldClassfile);
94         Classfile newClassfile = newLoader.getClassfile(name);
95         assertNotNull(newClassfile);
96         Differences componentDifferences = new ClassDifferences(name, oldClassfile, newClassfile);
97         assertTrue("component not empty", componentDifferences.isEmpty());
98
99         DeprecatableDifferences deprecatedDifferences = new DeprecatableDifferences(componentDifferences, oldClassfile, newClassfile);
100         
101         assertTrue("deprecated NewDeprecation()", !deprecatedDifferences.isNewDeprecation());
102         assertTrue("deprecated RemovedDeprecation()", deprecatedDifferences.isRemovedDeprecation());
103         assertTrue("deprecated IsEmpty()", !deprecatedDifferences.isEmpty());
104     }
105
106     public void testNotDeprecatedDeprecated() {
107         String JavaDoc name = "ModifiedPackage.DeprecatedClass";
108         Classfile oldClassfile = oldLoader.getClassfile(name);
109         assertNotNull(oldClassfile);
110         Classfile newClassfile = newLoader.getClassfile(name);
111         assertNotNull(newClassfile);
112         Differences componentDifferences = new ClassDifferences(name, oldClassfile, newClassfile);
113         assertTrue("component not empty", componentDifferences.isEmpty());
114
115         DeprecatableDifferences deprecatedDifferences = new DeprecatableDifferences(componentDifferences, oldClassfile, newClassfile);
116         
117         assertTrue("deprecated NewDeprecation()", deprecatedDifferences.isNewDeprecation());
118         assertTrue("deprecated RemovedDeprecation()", !deprecatedDifferences.isRemovedDeprecation());
119         assertTrue("deprecated IsEmpty()", !deprecatedDifferences.isEmpty());
120     }
121
122     public void testDeprecatedDeprecated() {
123         String JavaDoc name = "ModifiedPackage.DeprecatedClass";
124         Classfile oldClassfile = newLoader.getClassfile(name);
125         assertNotNull(oldClassfile);
126         Classfile newClassfile = newLoader.getClassfile(name);
127         assertNotNull(newClassfile);
128         Differences componentDifferences = new ClassDifferences(name, oldClassfile, newClassfile);
129         assertTrue("component not empty", componentDifferences.isEmpty());
130
131         DeprecatableDifferences deprecatedDifferences = new DeprecatableDifferences(componentDifferences, oldClassfile, newClassfile);
132         
133         assertTrue("deprecated NewDeprecation()", !deprecatedDifferences.isNewDeprecation());
134         assertTrue("deprecated RemovedDeprecation()", !deprecatedDifferences.isRemovedDeprecation());
135         assertTrue("deprecated IsEmpty()", deprecatedDifferences.isEmpty());
136     }
137 }
138
Popular Tags