1 19 20 package org.apache.tools.ant.module.run; 21 22 import java.awt.EventQueue ; 23 import java.io.PrintStream ; 24 import javax.swing.JEditorPane ; 25 import org.netbeans.junit.NbTestCase; 26 import org.openide.cookies.SaveCookie; 27 import org.openide.filesystems.FileObject; 28 import org.openide.filesystems.FileUtil; 29 import org.openide.loaders.DataObject; 30 import org.openide.text.CloneableEditor; 31 import org.openide.windows.OutputListener; 32 import org.openide.windows.TopComponent; 33 34 38 public class HyperlinkTest extends NbTestCase { 39 40 public HyperlinkTest(String n) { 41 super(n); 42 } 43 44 private FileObject f1; 45 private OutputListener h11; 46 private OutputListener h12; 47 48 @Override 49 protected void setUp() throws Exception { 50 super.setUp(); 51 clearWorkDir(); 52 FileObject root = FileUtil.toFileObject(getWorkDir()); 53 f1 = root.createData("f1"); 54 PrintStream ps = new PrintStream (f1.getOutputStream()); 55 ps.println("#comment 1"); 56 ps.println("bug #1"); 57 ps.println("#COMMENT 2"); 58 ps.println("bug #2"); 59 ps.println("#CoMmEnT 3"); 60 ps.flush(); 61 ps.close(); 62 h11 = new Hyperlink(f1.getURL(), "f1 #1", 2, 5, -1, -1); 63 h12 = new Hyperlink(f1.getURL(), "f1 #2", 4, 5, -1, -1); 64 System.setProperty("org.openide.windows.DummyWindowManager.VISIBLE", "false"); 65 } 66 67 @Override 68 protected void tearDown() throws Exception { 69 super.tearDown(); 70 Hyperlink.detachAllAnnotations(); 71 } 72 73 public void testMovingHyperlinkWithoutSave() throws Exception { 74 doTestMovingHyperlink(false); 75 } 76 77 public void testMovingHyperlinkWithSave() throws Exception { doTestMovingHyperlink(true); 79 } 80 81 private void doTestMovingHyperlink(boolean save) throws Exception { 82 click(h11); 83 JEditorPane ep1 = ((CloneableEditor) TopComponent.getRegistry().getActivated()).getEditorPane(); 84 assertEquals("#1\n", ep1.getDocument().getText(ep1.getCaretPosition(), 3)); 85 ep1.getDocument().insertString(ep1.getCaretPosition() + 3, "fixstuff\n", null); 86 if (save) { 87 DataObject.find(f1).getCookie(SaveCookie.class).save(); 88 } 89 click(h11); 90 assertEquals("#1\n", ep1.getDocument().getText(ep1.getCaretPosition(), 3)); 91 ep1.getDocument().insertString(ep1.getCaretPosition() + 3, "fixstuff\n", null); 92 click(h12); 93 assertEquals("#2\n", ep1.getDocument().getText(ep1.getCaretPosition(), 3)); 94 click(h11); 95 assertEquals("#1\n", ep1.getDocument().getText(ep1.getCaretPosition(), 3)); 96 } 97 98 private void click(OutputListener hyperlink) throws Exception { 99 hyperlink.outputLineAction(null); 100 EventQueue.invokeAndWait(new Runnable () {public void run() {}}); 102 } 103 104 } 105 | Popular Tags |