1 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 33 public class NbDocumentTest extends NbTestCase { 34 35 private StyledDocument doc = new DefaultStyledDocument(); 36 37 public NbDocumentTest(String testName) { 38 super(testName); 39 } 40 41 public static void main(java.lang.String [] 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 { 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 |