KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import junit.framework.*;
27
28 import org.netbeans.junit.*;
29
30 import org.openide.util.Lookup;
31 import org.openide.util.RequestProcessor;
32 import org.openide.util.lookup.*;
33
34
35 /** Testing different features of NotifyModifieTest with NbEditorKit
36  *
37  * @author Jaroslav Tulach
38  */

39 public class NotifyModifiedOnNbEditorLikeKitTest extends NotifyModifiedTest {
40     private NbLikeEditorKit k;
41
42     public NotifyModifiedOnNbEditorLikeKitTest (String JavaDoc s) {
43         super (s);
44     }
45     
46     //
47
// overwrite editor kit
48
//
49

50     protected javax.swing.text.EditorKit JavaDoc createEditorKit () {
51         NbLikeEditorKit k = new NbLikeEditorKit ();
52         return k;
53     }
54     
55     protected void doesVetoedInsertFireBadLocationException (javax.swing.text.BadLocationException JavaDoc e) {
56         if (e == null) {
57             fail("Vetoed insert has to generate BadLocationException");
58         }
59     }
60     
61     private static RequestProcessor testRP = new RequestProcessor("Test");
62     protected void checkThatDocumentLockIsNotHeld () {
63         class X implements Runnable JavaDoc {
64             private boolean second;
65             private boolean ok;
66
67             public void run () {
68                 if (second) {
69                     ok = true;
70                     return;
71                 } else {
72                     second = true;
73                     javax.swing.text.Document JavaDoc doc = support.getDocument ();
74                     assertNotNull (doc);
75                     // we have to pass thru read access
76
doc.render (this);
77                     
78                     if (ok) {
79                         try {
80                             // we have to be allowed to do modifications as well
81
doc.insertString (-1, "A", null);
82                             ok = false;
83                         } catch (javax.swing.text.BadLocationException JavaDoc ex) {
84                         }
85
86                         try {
87                             doc.remove (-1, 1);
88                             ok = false;
89                         } catch (javax.swing.text.BadLocationException JavaDoc ex) {
90                         }
91                     }
92                         
93                     return;
94                 }
95             }
96         }
97
98         X x = new X ();
99         testRP.post (x).waitFinished ();
100         assertTrue ("No lock is held on document when running notifyModified", x.ok);
101     }
102 }
103
Popular Tags