KickJava   Java API By Example, From Geeks To Geeks.

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


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
37 import org.xml.sax.*;
38 import org.xml.sax.helpers.*;
39
40 import org.apache.oro.text.perl.*;
41
42 import junit.framework.*;
43
44 public class TestListDiffPrinter extends TestCase implements ErrorHandler {
45     private static final String JavaDoc READER_CLASSNAME = "org.apache.xerces.parsers.SAXParser";
46
47     private static final String JavaDoc SPECIFIC_ENCODING = "iso-latin-1";
48     private static final String JavaDoc SPECIFIC_DTD_PREFIX = "./etc";
49
50     private ListDiffPrinter printer;
51     private XMLReader reader;
52
53     private Perl5Util perl;
54
55     protected void setUp() throws Exception JavaDoc {
56         reader = XMLReaderFactory.createXMLReader(READER_CLASSNAME);
57         reader.setFeature("http://xml.org/sax/features/validation", true);
58         reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", true);
59         reader.setErrorHandler(this);
60
61         perl = new Perl5Util();
62     }
63
64     public void testDefaultDTDPrefix() {
65         printer = new ListDiffPrinter();
66
67         String JavaDoc xmlDocument = printer.toString();
68         assertTrue(xmlDocument + "Missing DTD", perl.match("/DOCTYPE \\S+ SYSTEM \"(.*)\"/", xmlDocument));
69         assertTrue("DTD \"" + perl.group(1) + "\" does not have prefix \"" + ListDiffPrinter.DEFAULT_DTD_PREFIX + "\"", perl.group(1).startsWith(ListDiffPrinter.DEFAULT_DTD_PREFIX));
70         
71         try {
72             reader.parse(new InputSource(new StringReader(xmlDocument)));
73         } catch (SAXException ex) {
74             fail("Could not parse XML Document: " + ex.getMessage() + "\n" + xmlDocument);
75         } catch (IOException ex) {
76             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
77         }
78     }
79     
80     public void testSpecificDTDPrefix() {
81         printer = new ListDiffPrinter(ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
82
83         String JavaDoc xmlDocument = printer.toString();
84         assertTrue(xmlDocument + "Missing DTD", perl.match("/DOCTYPE \\S+ SYSTEM \"(.*)\"/", xmlDocument));
85         assertTrue("DTD \"" + perl.group(1) + "\" does not have prefix \"./etc\"", perl.group(1).startsWith(SPECIFIC_DTD_PREFIX));
86         
87         try {
88             reader.parse(new InputSource(new StringReader(xmlDocument)));
89         } catch (SAXException ex) {
90             fail("Could not parse XML Document: " + ex.getMessage() + "\n" + xmlDocument);
91         } catch (IOException ex) {
92             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
93         }
94     }
95
96     public void testDefaultEncoding() {
97         printer = new ListDiffPrinter();
98
99         String JavaDoc xmlDocument = printer.toString();
100         assertTrue(xmlDocument + "Missing encoding", perl.match("/encoding=\"([^\"]*)\"/", xmlDocument));
101         assertEquals("Encoding", ListDiffPrinter.DEFAULT_ENCODING, perl.group(1));
102         
103         try {
104             reader.parse(new InputSource(new StringReader(xmlDocument)));
105         } catch (SAXException ex) {
106             fail("Could not parse XML Document: " + ex.getMessage() + "\n" + xmlDocument);
107         } catch (IOException ex) {
108             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
109         }
110     }
111
112     public void testSpecificEncoding() {
113         printer = new ListDiffPrinter(SPECIFIC_ENCODING, ListDiffPrinter.DEFAULT_DTD_PREFIX);
114
115         String JavaDoc xmlDocument = printer.toString();
116         assertTrue(xmlDocument + "Missing encoding", perl.match("/encoding=\"([^\"]*)\"/", xmlDocument));
117         assertEquals("Encoding", SPECIFIC_ENCODING, perl.group(1));
118         
119         try {
120             reader.parse(new InputSource(new StringReader(xmlDocument)));
121         } catch (SAXException ex) {
122             fail("Could not parse XML Document: " + ex.getMessage() + "\n" + xmlDocument);
123         } catch (IOException ex) {
124             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
125         }
126     }
127
128     public void testDefault() {
129         ListDiffPrinter printer = new ListDiffPrinter(ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
130
131         printer.remove("java.lang.Object");
132         printer.remove("java.lang.Object.Object()");
133         printer.remove("java.lang.String");
134         printer.remove("java.util");
135         printer.remove("java.util.Collection.add(java.lang.Object)");
136         printer.remove("java.util.Collection.addAll(java.util.Collection)");
137
138         printer.add("java.lang.Thread");
139         printer.add("java.lang.Thread.Thread()");
140         printer.add("java.lang.System");
141         printer.add("java.io");
142         printer.add("java.io.PrintStream.println(java.lang.Object)");
143         printer.add("java.io.PrintWriter.println(java.lang.Object)");
144
145         String JavaDoc xmlDocument = printer.toString();
146         
147         try {
148             reader.parse(new InputSource(new StringReader(xmlDocument)));
149         } catch (SAXException ex) {
150             fail("Could not parse XML Document: " + ex.getMessage() + "\n" + xmlDocument);
151         } catch (IOException ex) {
152             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
153         }
154
155         assertTrue("java.lang.Object not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Object</line>") != -1);
156         assertTrue("java.lang.Object.Object() not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Object.Object()</line>") != -1);
157         assertTrue("java.lang.String not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.String</line>") != -1);
158         assertTrue("java.util not in " + xmlDocument, xmlDocument.indexOf("<line>java.util</line>") != -1);
159         assertTrue("java.util.Collection.add(java.lang.Object) not in " + xmlDocument, xmlDocument.indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
160         assertTrue("java.util.Collection.addAll(java.util.Collection) not in " + xmlDocument, xmlDocument.indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
161
162         assertTrue("java.lang.Thread not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Thread</line>") != -1);
163         assertTrue("java.lang.Thread.Thread() not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Thread.Thread()</line>") != -1);
164         assertTrue("java.lang.System not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.System</line>") != -1);
165         assertTrue("java.io not in " + xmlDocument, xmlDocument.indexOf("<line>java.io</line>") != -1);
166         assertTrue("java.io.PrintStream.println(java.lang.Object) not in " + xmlDocument, xmlDocument.indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
167         assertTrue("java.io.PrintWriter.println(java.lang.Object) not in " + xmlDocument, xmlDocument.indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
168     }
169
170     public void testFullList() {
171         ListDiffPrinter printer = new ListDiffPrinter(false, ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
172
173         printer.remove("java.lang.Object");
174         printer.remove("java.lang.Object.Object()");
175         printer.remove("java.lang.String");
176         printer.remove("java.util");
177         printer.remove("java.util.Collection.add(java.lang.Object)");
178         printer.remove("java.util.Collection.addAll(java.util.Collection)");
179
180         printer.add("java.lang.Thread");
181         printer.add("java.lang.Thread.Thread()");
182         printer.add("java.lang.System");
183         printer.add("java.io");
184         printer.add("java.io.PrintStream.println(java.lang.Object)");
185         printer.add("java.io.PrintWriter.println(java.lang.Object)");
186
187         String JavaDoc xmlDocument = printer.toString();
188         
189         try {
190             reader.parse(new InputSource(new StringReader(xmlDocument)));
191         } catch (SAXException ex) {
192             fail("Could not parse XML Document: " + ex.getMessage() + "\n" + xmlDocument);
193         } catch (IOException ex) {
194             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
195         }
196
197         assertTrue("java.lang.Object not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Object</line>") != -1);
198         assertTrue("java.lang.Object.Object() not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Object.Object()</line>") != -1);
199         assertTrue("java.lang.String not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.String</line>") != -1);
200         assertTrue("java.util not in " + xmlDocument, xmlDocument.indexOf("<line>java.util</line>") != -1);
201         assertTrue("java.util.Collection.add(java.lang.Object) not in " + xmlDocument, xmlDocument.indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
202         assertTrue("java.util.Collection.addAll(java.util.Collection) not in " + xmlDocument, xmlDocument.indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
203
204         assertTrue("java.lang.Thread not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Thread</line>") != -1);
205         assertTrue("java.lang.Thread.Thread() not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Thread.Thread()</line>") != -1);
206         assertTrue("java.lang.System not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.System</line>") != -1);
207         assertTrue("java.io not in " + xmlDocument, xmlDocument.indexOf("<line>java.io</line>") != -1);
208         assertTrue("java.io.PrintStream.println(java.lang.Object) not in " + xmlDocument, xmlDocument.indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
209         assertTrue("java.io.PrintWriter.println(java.lang.Object) not in " + xmlDocument, xmlDocument.indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
210     }
211
212     public void testCompressedList() {
213         ListDiffPrinter printer = new ListDiffPrinter(true, ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
214
215         printer.remove("java.lang.Object [C]");
216         printer.remove("java.lang.Object.Object() [F]");
217         printer.remove("java.lang.String [C]");
218         printer.remove("java.util [P]");
219         printer.remove("java.util.Collection.add(java.lang.Object) [F]");
220         printer.remove("java.util.Collection.addAll(java.util.Collection) [F]");
221
222         printer.add("java.lang.Thread [C]");
223         printer.add("java.lang.Thread.Thread() [F]");
224         printer.add("java.lang.System [C]");
225         printer.add("java.io [P]");
226         printer.add("java.io.PrintStream.println(java.lang.Object) [F]");
227         printer.add("java.io.PrintWriter.println(java.lang.Object) [F]");
228
229         String JavaDoc xmlDocument = printer.toString();
230         
231         try {
232             reader.parse(new InputSource(new StringReader(xmlDocument)));
233         } catch (SAXException ex) {
234             fail("Could not parse XML Document: " + ex.getMessage() + "\n" + xmlDocument);
235         } catch (IOException ex) {
236             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
237         }
238
239         assertTrue("java.lang.Object not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Object</line>") != -1);
240         assertTrue("java.lang.Object.Object() in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Object.Object()</line>") == -1);
241         assertTrue("java.lang.String not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.String</line>") != -1);
242         assertTrue("java.util not in " + xmlDocument, xmlDocument.indexOf("<line>java.util</line>") != -1);
243         assertTrue("java.util.Collection.add(java.lang.Object) in " + xmlDocument, xmlDocument.indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") == -1);
244         assertTrue("java.util.Collection.addAll(java.util.Collection) in " + xmlDocument, xmlDocument.indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") == -1);
245
246         assertTrue("java.lang.Thread not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Thread</line>") != -1);
247         assertTrue("java.lang.Thread.Thread() in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Thread.Thread()</line>") == -1);
248         assertTrue("java.lang.System not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.System</line>") != -1);
249         assertTrue("java.io not in " + xmlDocument, xmlDocument.indexOf("<line>java.io</line>") != -1);
250         assertTrue("java.io.PrintStream.println(java.lang.Object) not in " + xmlDocument, xmlDocument.indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") == -1);
251         assertTrue("java.io.PrintWriter.println(java.lang.Object) in " + xmlDocument, xmlDocument.indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") == -1);
252     }
253
254     public void testCompressedListWithoutSuffixes() {
255         ListDiffPrinter printer = new ListDiffPrinter(true, ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
256
257         printer.remove("java.lang.Object");
258         printer.remove("java.lang.Object.Object()");
259         printer.remove("java.lang.String");
260         printer.remove("java.util");
261         printer.remove("java.util.Collection.add(java.lang.Object)");
262         printer.remove("java.util.Collection.addAll(java.util.Collection)");
263
264         printer.add("java.lang.Thread");
265         printer.add("java.lang.Thread.Thread()");
266         printer.add("java.lang.System");
267         printer.add("java.io");
268         printer.add("java.io.PrintStream.println(java.lang.Object)");
269         printer.add("java.io.PrintWriter.println(java.lang.Object)");
270
271         String JavaDoc xmlDocument = printer.toString();
272         
273         try {
274             reader.parse(new InputSource(new StringReader(xmlDocument)));
275         } catch (SAXException ex) {
276             fail("Could not parse XML Document: " + ex.getMessage() + "\n" + xmlDocument);
277         } catch (IOException ex) {
278             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
279         }
280
281         assertTrue("java.lang.Object not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Object</line>") != -1);
282         assertTrue("java.lang.Object.Object() not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Object.Object()</line>") != -1);
283         assertTrue("java.lang.String not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.String</line>") != -1);
284         assertTrue("java.util not in " + xmlDocument, xmlDocument.indexOf("<line>java.util</line>") != -1);
285         assertTrue("java.util.Collection.add(java.lang.Object) not in " + xmlDocument, xmlDocument.indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
286         assertTrue("java.util.Collection.addAll(java.util.Collection) not in " + xmlDocument, xmlDocument.indexOf("<line>java.util.Collection.add(java.lang.Object)</line>") != -1);
287
288         assertTrue("java.lang.Thread not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Thread</line>") != -1);
289         assertTrue("java.lang.Thread.Thread() not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.Thread.Thread()</line>") != -1);
290         assertTrue("java.lang.System not in " + xmlDocument, xmlDocument.indexOf("<line>java.lang.System</line>") != -1);
291         assertTrue("java.io not in " + xmlDocument, xmlDocument.indexOf("<line>java.io</line>") != -1);
292         assertTrue("java.io.PrintStream.println(java.lang.Object) not in " + xmlDocument, xmlDocument.indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
293         assertTrue("java.io.PrintWriter.println(java.lang.Object) not in " + xmlDocument, xmlDocument.indexOf("<line>java.io.PrintStream.println(java.lang.Object)</line>") != -1);
294     }
295
296     public void testLegitimateSuffixes() {
297         ListDiffPrinter printer = new ListDiffPrinter(true, ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
298
299         printer.remove("removed [P]"); // not compressed
300
printer.remove("removed.Removed [C]"); // compressed
301
printer.remove("removed.Removed.Removed() [F]"); // compressed
302
printer.remove("removed.Removed.removed [F]"); // compressed
303
printer.remove("removed.OtherRemoved.OtherRemoved() [F]"); // compressed
304
printer.remove("removed.OtherRemoved.other_removed [F]"); // compressed
305
printer.remove("removedpackage [P]"); // not compressed
306
printer.remove("removed.package.internal [P]"); // not compressed
307
printer.remove("other.removed.Removed [C]"); // not compressed
308
printer.remove("other.removed.Removed.Removed() [F]"); // compressed
309
printer.remove("other.removed.OtherRemoved.OtherRemoved() [F]"); // not compressed
310

311         printer.add("add [P]"); // not compressed
312
printer.add("add.Add [C]"); // compressed
313
printer.add("add.Add.Add() [F]"); // compressed
314
printer.add("add.Add.add [F]"); // compressed
315
printer.add("add.OtherAdd.OtherAdd() [F]"); // compressed
316
printer.add("add.OtherAdd.add [F]"); // compressed
317
printer.add("addpackage [P]"); // not compressed
318
printer.add("add.package.internal [P]"); // not compressed
319
printer.add("other.add.Add [C]"); // not compressed
320
printer.add("other.add.Add.Add() [F]"); // compressed
321
printer.add("other.add.OtherAdd.OtherAdd() [F]"); // not compressed
322

323         String JavaDoc xmlDocument = printer.toString();
324         
325         try {
326             reader.parse(new InputSource(new StringReader(xmlDocument)));
327         } catch (SAXException ex) {
328             fail("Could not parse XML Document: " + ex.getMessage() + "\n" + xmlDocument);
329         } catch (IOException ex) {
330             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
331         }
332
333         assertTrue("removed not in " + xmlDocument, xmlDocument.indexOf("<line>removed</line>") != -1);
334         assertTrue("removed.Removed in " + xmlDocument, xmlDocument.indexOf("<line>removed.Removed</line>") == -1);
335         assertTrue("removed.Removed.Removed() in " + xmlDocument, xmlDocument.indexOf("<line>removed.Removed.Removed()</line>") == -1);
336         assertTrue("removed.Removed.removed in " + xmlDocument, xmlDocument.indexOf("<line>removed.Removed.removed</line>") == -1);
337         assertTrue("removed.OtherRemoved.OtherRemoved() in " + xmlDocument, xmlDocument.indexOf("<line>removed.OtherRemoved.OtherRemoved()</line>") == -1);
338         assertTrue("removed.OtherRemoved.other_removed in " + xmlDocument, xmlDocument.indexOf("<line>removed.OtherRemoved.other_removed</line>") == -1);
339         assertTrue("removedpackage not in " + xmlDocument, xmlDocument.indexOf("<line>removedpackage</line>") != -1);
340         assertTrue("removed.package.internal not in " + xmlDocument, xmlDocument.indexOf("<line>removed.package.internal</line>") != -1);
341         assertTrue("other.removed.Removed not in " + xmlDocument, xmlDocument.indexOf("<line>other.removed.Removed</line>") != -1);
342         assertTrue("other.removed.Removed.Removed() in " + xmlDocument, xmlDocument.indexOf("<line>other.removed.Removed.Removed()</line>") == -1);
343         assertTrue("other.removed.OtherRemoved.OtherRemoved() not in " + xmlDocument, xmlDocument.indexOf("<line>other.removed.OtherRemoved.OtherRemoved()</line>") != -1);
344
345         assertTrue("add not in " + xmlDocument, xmlDocument.indexOf("<line>add</line>") != -1);
346         assertTrue("add.Add in " + xmlDocument, xmlDocument.indexOf("<line>add.Add</line>") == -1);
347         assertTrue("add.Add.Add() in " + xmlDocument, xmlDocument.indexOf("<line>add.Add.Add()</line>") == -1);
348         assertTrue("add.Add.add in " + xmlDocument, xmlDocument.indexOf("<line>add.Add.add</line>") == -1);
349         assertTrue("add.OtherAdd.OtherAdd() in " + xmlDocument, xmlDocument.indexOf("<line>add.OtherAdd.OtherAdd()</line>") == -1);
350         assertTrue("add.OtherAdd.other_add in " + xmlDocument, xmlDocument.indexOf("<line>add.OtherAdd.other_add</line>") == -1);
351         assertTrue("addpackage not in " + xmlDocument, xmlDocument.indexOf("<line>addpackage</line>") != -1);
352         assertTrue("add.package.internal not in " + xmlDocument, xmlDocument.indexOf("<line>add.package.internal</line>") != -1);
353         assertTrue("other.add.Add not in " + xmlDocument, xmlDocument.indexOf("<line>other.add.Add</line>") != -1);
354         assertTrue("other.add.Add.Add() in " + xmlDocument, xmlDocument.indexOf("<line>other.add.Add.Add()</line>") == -1);
355         assertTrue("other.add.OtherAdd.OtherAdd() not in " + xmlDocument, xmlDocument.indexOf("<line>other.add.OtherAdd.OtherAdd()</line>") != -1);
356     }
357
358     public void testNoSuffixes() {
359         ListDiffPrinter printer = new ListDiffPrinter(true, ListDiffPrinter.DEFAULT_ENCODING, SPECIFIC_DTD_PREFIX);
360
361         printer.remove("removed"); // not compressed
362
printer.remove("removed.Removed"); // not compressed
363
printer.remove("removed.Removed.Removed()"); // not compressed
364
printer.remove("removed.Removed.removed"); // not compressed
365
printer.remove("removed.OtherRemoved.OtherRemoved()"); // not compressed
366
printer.remove("removed.OtherRemoved.other_removed"); // not compressed
367
printer.remove("removedpackage"); // not compressed
368
printer.remove("removed.package.internal"); // not compressed
369
printer.remove("other.removed.Removed"); // not compressed
370
printer.remove("other.removed.Removed.Removed()"); // not compressed
371
printer.remove("other.removed.OtherRemoved.OtherRemoved()"); // not compressed
372

373         printer.add("add"); // not compressed
374
printer.add("add.Add"); // not compressed
375
printer.add("add.Add.Add()"); // not compressed
376
printer.add("add.Add.add"); // not compressed
377
printer.add("add.OtherAdd.OtherAdd()"); // not compressed
378
printer.add("add.OtherAdd.other_add"); // not compressed
379
printer.add("addpackage"); // not compressed
380
printer.add("add.package.internal"); // not compressed
381
printer.add("other.add.Add"); // not compressed
382
printer.add("other.add.Add.Add()"); // not compressed
383
printer.add("other.add.OtherAdd.OtherAdd()"); // not compressed
384

385         String JavaDoc xmlDocument = printer.toString();
386         
387         try {
388             reader.parse(new InputSource(new StringReader(xmlDocument)));
389         } catch (SAXException ex) {
390             fail("Could not parse XML Document: " + ex.getMessage() + "\n" + xmlDocument);
391         } catch (IOException ex) {
392             fail("Could not read XML Document: " + ex.getMessage() + "\n" + xmlDocument);
393         }
394
395         assertTrue("removed not in " + xmlDocument, xmlDocument.indexOf("<line>removed</line>") != -1);
396         assertTrue("removed.Removed in " + xmlDocument, xmlDocument.indexOf("<line>removed.Removed</line>") != -1);
397         assertTrue("removed.Removed.Removed() in " + xmlDocument, xmlDocument.indexOf("<line>removed.Removed.Removed()</line>") != -1);
398         assertTrue("removed.Removed.removed in " + xmlDocument, xmlDocument.indexOf("<line>removed.Removed.removed</line>") != -1);
399         assertTrue("removed.OtherRemoved.OtherRemoved() in " + xmlDocument, xmlDocument.indexOf("<line>removed.OtherRemoved.OtherRemoved()</line>") != -1);
400         assertTrue("removed.OtherRemoved.other_removed in " + xmlDocument, xmlDocument.indexOf("<line>removed.OtherRemoved.other_removed</line>") != -1);
401         assertTrue("removedpackage not in " + xmlDocument, xmlDocument.indexOf("<line>removedpackage</line>") != -1);
402         assertTrue("removed.package.internal not in " + xmlDocument, xmlDocument.indexOf("<line>removed.package.internal</line>") != -1);
403         assertTrue("other.removed.Removed not in " + xmlDocument, xmlDocument.indexOf("<line>other.removed.Removed</line>") != -1);
404         assertTrue("other.removed.Removed.Removed() in " + xmlDocument, xmlDocument.indexOf("<line>other.removed.Removed.Removed()</line>") != -1);
405         assertTrue("other.removed.OtherRemoved.OtherRemoved() not in " + xmlDocument, xmlDocument.indexOf("<line>other.removed.OtherRemoved.OtherRemoved()</line>") != -1);
406
407         assertTrue("add not in " + xmlDocument, xmlDocument.indexOf("<line>add</line>") != -1);
408         assertTrue("add.Add in " + xmlDocument, xmlDocument.indexOf("<line>add.Add</line>") != -1);
409         assertTrue("add.Add.Add() in " + xmlDocument, xmlDocument.indexOf("<line>add.Add.Add()</line>") != -1);
410         assertTrue("add.Add.add in " + xmlDocument, xmlDocument.indexOf("<line>add.Add.add</line>") != -1);
411         assertTrue("add.OtherAdd.OtherAdd() in " + xmlDocument, xmlDocument.indexOf("<line>add.OtherAdd.OtherAdd()</line>") != -1);
412         assertTrue("add.OtherAdd.other_add in " + xmlDocument, xmlDocument.indexOf("<line>add.OtherAdd.other_add</line>") != -1);
413         assertTrue("addpackage not in " + xmlDocument, xmlDocument.indexOf("<line>addpackage</line>") != -1);
414         assertTrue("add.package.internal not in " + xmlDocument, xmlDocument.indexOf("<line>add.package.internal</line>") != -1);
415         assertTrue("other.add.Add not in " + xmlDocument, xmlDocument.indexOf("<line>other.add.Add</line>") != -1);
416         assertTrue("other.add.Add.Add() in " + xmlDocument, xmlDocument.indexOf("<line>other.add.Add.Add()</line>") != -1);
417         assertTrue("other.add.OtherAdd.OtherAdd() not in " + xmlDocument, xmlDocument.indexOf("<line>other.add.OtherAdd.OtherAdd()</line>") != -1);
418     }
419
420     public void error(SAXParseException ex) {
421         // Ignore
422
}
423
424     public void fatalError(SAXParseException ex) {
425         // Ignore
426
}
427
428     public void warning(SAXParseException ex) {
429         // Ignore
430
}
431 }
432
Popular Tags