KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > text > NbDocumentTest


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.openide.text;
21
22 import javax.swing.text.*;
23
24 import junit.framework.*;
25
26 import org.netbeans.junit.*;
27
28
29 /** Testing LineSet impl for CloneableEditorSupport.
30  *
31  * @author Jaroslav Tulach
32  */

33 public class NbDocumentTest extends NbTestCase {
34
35     private StyledDocument doc = new DefaultStyledDocument();
36
37     public NbDocumentTest(String JavaDoc testName) {
38         super(testName);
39     }
40
41     public static void main(java.lang.String JavaDoc[] args) {
42         if (args.length == 1) {
43             junit.textui.TestRunner.run (new NbDocumentTest (args[0]));
44         }
45         junit.textui.TestRunner.run(suite());
46     }
47     
48     public static Test suite() {
49         TestSuite suite = new NbTestSuite(NbDocumentTest.class);
50         return suite;
51     }
52     
53
54     protected void setUp () {
55     doc = createStyledDocument();
56     }
57     
58     protected StyledDocument createStyledDocument() {
59         return new DefaultStyledDocument();
60     }
61
62
63     public void testMarkGuardedAndBack() throws Exception JavaDoc {
64         doc.insertString (0, "Line1\nLine2\n", null);
65     
66         assertEquals ("Document has correct number of lines ",
67             3, doc.getDefaultRootElement().getElementCount());
68         
69         NbDocument.markGuarded(doc, 0, doc.getLength());
70
71         assertEquals ("Document has correct number of lines ",
72             3, doc.getDefaultRootElement().getElementCount());
73
74         NbDocument.unmarkGuarded(doc, 0, doc.getLength());
75
76         assertEquals ("Document has correct number of lines ",
77             3, doc.getDefaultRootElement().getElementCount());
78
79     }
80 }
81
Popular Tags