1 19 20 package org.netbeans.test.java.generating.javadoc; 21 22 import java.io.BufferedWriter ; 23 import java.io.File ; 24 import java.io.FileWriter ; 25 import java.io.IOException ; 26 import java.io.PrintWriter ; 27 import junit.textui.TestRunner; 28 import org.netbeans.api.java.classpath.ClassPath; 29 import org.netbeans.api.java.source.JavaSource; 30 import org.netbeans.junit.NbTestCase; 31 import org.netbeans.junit.NbTestSuite; 32 import org.netbeans.test.java.Common; 33 import org.netbeans.test.java.LogTestCase; 34 import org.netbeans.test.java.Utilities; 35 import org.openide.cookies.EditorCookie; 36 import org.openide.cookies.SaveCookie; 37 import org.openide.filesystems.FileObject; 38 import org.openide.filesystems.FileUtil; 39 import org.openide.loaders.DataObject; 40 import org.openide.loaders.DataObjectNotFoundException; 41 42 43 46 47 public class JavaDoc extends LogTestCase { 48 49 private static final String TEST_FILE = "TestFile"; 50 51 private static final String packageName = "org.netbeans.test.java.generating.javadoc"; 52 53 private DataObject DO; 54 55 private FileObject fo; 56 57 58 File tempFile; 59 60 61 public JavaDoc(String name) { 62 super(name); 63 } 64 65 public static NbTestSuite suite() { 66 NbTestSuite suite = new NbTestSuite("org.netbeans.test.java.generating.javadoc.JavaDoc"); 67 suite.addTest(new JavaDoc("testClass")); 68 suite.addTest(new JavaDoc("testMethod")); 69 suite.addTest(new JavaDoc("testField")); 70 suite.addTest(new JavaDoc("testConstructor")); 72 return suite; 73 } 74 75 76 public static void main(java.lang.String [] args) { 77 TestRunner.run(suite()); 78 } 79 80 public void setUp() { 81 super.setUp(); 82 FileObject artefact=null; 83 try { 84 artefact=FileUtil.toFileObject(classPathWorkDir); 85 fo = artefact.getFileObject((packageName + "." + TEST_FILE).replace(".","/")); 86 DO = DataObject.find(fo); 87 } catch (Exception ex) { 88 ex.printStackTrace(log); 89 assertTrue(ex.toString(), false); 90 } 91 } 92 93 public void tearDown() { 94 assertTrue(writeResult(DO)); 95 try { 96 if (DO.getCookie(SaveCookie.class) != null) { 97 ((SaveCookie) DO.getCookie(SaveCookie.class)).save(); 98 } 99 } catch (Exception e){ 100 assertTrue(e.toString(), false); 101 } 102 super.tearDown(); 103 104 105 } 107 108 public void testClass() throws IOException { 109 JavaSource js = JavaSource.forFileObject(fo); 110 Common.addClassComment(js,"Class comment"); 111 } 112 133 protected boolean writeResult(DataObject DO) { 134 String result=""; 135 try { 136 EditorCookie ec=(EditorCookie)(DO.getCookie(EditorCookie.class)); 137 javax.swing.text.StyledDocument doc=ec.openDocument(); 138 result=doc.getText(0, doc.getLength()); 139 result=Common.unify(result); 140 } catch (Exception e){ 141 e.printStackTrace(log); 142 return false; 143 } 144 ref(result); 145 return true; 146 } 147 } 148 | Popular Tags |