KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > diff > builtin > visualizer > TextDiffVisualizerTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.diff.builtin.visualizer;
21
22 import java.io.*;
23 import junit.framework.*;
24 import java.awt.Component JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.Reader JavaDoc;
28 import java.io.BufferedReader JavaDoc;
29 import java.io.ByteArrayInputStream JavaDoc;
30 import java.io.Serializable JavaDoc;
31 import org.netbeans.modules.diff.builtin.provider.*;
32 import org.netbeans.modules.diff.builtin.provider.BuiltInDiffProvider;
33 import org.openide.windows.CloneableOpenSupport;
34 import org.openide.util.NbBundle;
35 import org.netbeans.api.diff.Difference;
36 import org.netbeans.spi.diff.DiffVisualizer;
37 import org.netbeans.modules.diff.builtin.DiffPresenter;
38
39 /**
40  *
41  * @author Petr Kuzel
42  */

43 public class TextDiffVisualizerTest extends TestCase {
44     
45     public TextDiffVisualizerTest(String JavaDoc testName) {
46         super(testName);
47     }
48
49     public static Test suite() {
50         TestSuite suite = new TestSuite(TextDiffVisualizerTest.class);
51         
52         return suite;
53     }
54
55     public void testDifferenceToContextDiffText() throws Exception JavaDoc {
56         testDifferenceToContextDiffText("WordLibrar");
57         testDifferenceToContextDiffText("start-add");
58         testDifferenceToContextDiffText("start-ch");
59         testDifferenceToContextDiffText("start-rm");
60         testDifferenceToContextDiffText("end-add");
61         testDifferenceToContextDiffText("end-ch");
62         testDifferenceToContextDiffText("end-rm");
63     }
64
65     public void testDifferenceToContextDiffText(String JavaDoc tcase) throws Exception JavaDoc {
66         System.out.println("differenceToContextDiffText(" + tcase + ")");
67         
68         Reader JavaDoc r1 = new InputStreamReader(getClass().getResourceAsStream("data/" + tcase + "0.txt"), "utf8");
69         Reader JavaDoc r2 = new InputStreamReader(getClass().getResourceAsStream("data/" + tcase + "1.txt"), "utf8");
70         Difference[] diffs = new BuiltInDiffProvider().computeDiff(r1, r2);
71         
72         r1 = new InputStreamReader(getClass().getResourceAsStream("data/" + tcase + "0.txt"), "utf8");
73         r2 = new InputStreamReader(getClass().getResourceAsStream("data/" + tcase + "1.txt"), "utf8");
74         TextDiffVisualizer.TextDiffInfo diffInfo = new TextDiffVisualizer.TextDiffInfo("name1", "name2", "tit1", "tit2", r1, r2, diffs);
75         diffInfo.setContextMode(true, 3);
76         
77         LineNumberReader expResult = new LineNumberReader(new InputStreamReader(getClass().getResourceAsStream("data/" + tcase + ".diff"), "utf8"));
78         InputStream JavaDoc result = TextDiffVisualizer.differenceToContextDiffText(diffInfo);
79         
80         LineNumberReader actResult = new LineNumberReader(new InputStreamReader(result, "utf8"));
81         
82         // kill headers
83
expResult.readLine();
84         expResult.readLine();
85         
86         actResult.readLine();
87         actResult.readLine();
88                 
89         while (true) {
90             String JavaDoc expLine = expResult.readLine();
91             String JavaDoc actLine = actResult.readLine();
92             if (expLine == null && actLine == null) {
93                 break;
94             }
95             System.out.println("" + actLine);
96             assertEquals(expLine, actLine);
97         }
98     }
99     
100 }
101
Popular Tags