KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > diff > DiffViewAbstract


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;
21
22 import java.io.*;
23
24 import org.netbeans.junit.*;
25 import org.netbeans.api.diff.DiffView;
26 import org.netbeans.api.diff.Difference;
27 import org.netbeans.api.diff.StreamSource;
28
29 /**
30  *
31  * @author Martin Entlicher
32  */

33 public abstract class DiffViewAbstract extends NbTestCase {
34     /** the DiffView to work on */
35     private DiffView dv;
36
37     public DiffViewAbstract(String JavaDoc name) {
38         super(name);
39     }
40
41     protected abstract DiffView createDiffView(StreamSource ss1, StreamSource ss2) throws IOException;
42     
43     protected void setUp() throws Exception JavaDoc {
44         dv = createDiffView(new Impl("name1", "title1", "text/plain", "content1\nsame\ndifferent1"), new Impl("name2", "title2", "text/plain", "content2\nsame\ndifferent2"));
45     }
46     
47     public void testCanDiffConsistent() throws Exception JavaDoc {
48         if (dv.canSetCurrentDifference()) {
49             dv.setCurrentDifference(0);
50         } else {
51             try {
52                 dv.setCurrentDifference(0);
53                 fail("Should throw UnsupportedOperationException");
54             } catch (UnsupportedOperationException JavaDoc uoex) {
55                 // OK
56
}
57         }
58     }
59     
60     public void testCurrentDifference() throws Exception JavaDoc {
61         if (dv.canSetCurrentDifference()) {
62             int dc = dv.getDifferenceCount();
63             assertEquals("Just one difference", 2, dc);
64             dv.setCurrentDifference(1);
65             assertEquals("Test current difference", 1, dv.getCurrentDifference());
66             try {
67                 dv.setCurrentDifference(10);
68                 fail("Should report an exception.");
69             } catch (IllegalArgumentException JavaDoc ioex) {
70                 // OK
71
}
72         }
73     }
74     
75     /**
76      * Private implementation to be returned by the static methods.
77      */

78     private static class Impl extends StreamSource {
79
80         private String JavaDoc name;
81         private String JavaDoc title;
82         private String JavaDoc MIMEType;
83         private Reader r;
84         private String JavaDoc buffer;
85         private Writer w;
86
87         Impl(String JavaDoc name, String JavaDoc title, String JavaDoc MIMEType, String JavaDoc str) {
88             this.name = name;
89             this.title = title;
90             this.MIMEType = MIMEType;
91             this.w = null;
92             buffer = str;
93         }
94
95         public String JavaDoc getName() {
96             return name;
97         }
98
99         public String JavaDoc getTitle() {
100             return title;
101         }
102
103         public String JavaDoc getMIMEType() {
104             return MIMEType;
105         }
106
107         public Reader createReader() throws IOException {
108             return new StringReader(buffer);
109         }
110
111         public Writer createWriter(Difference[] conflicts) throws IOException {
112             return null;
113         }
114     }
115     
116 }
117
Popular Tags