1 19 20 package org.netbeans.modules.junit; 21 22 import org.openide.*; 23 import org.openide.options.SystemOption; 24 import org.openide.util.HelpCtx; 25 import org.openide.util.NbBundle; 26 import java.io.*; 27 28 import junit.framework.*; 29 import org.openide.*; 30 import org.openide.options.SystemOption; 31 import org.openide.util.HelpCtx; 32 import org.openide.util.NbBundle; 33 import org.openide.filesystems.FileSystem; 34 import java.io.*; 35 import java.util.Enumeration ; 36 import junit.framework.*; 37 import org.netbeans.junit.*; 38 39 public class JUnitSettingsTest extends NbTestCase { 40 41 public JUnitSettingsTest(java.lang.String testName) { 42 super(testName); 43 } 44 45 public static void main(java.lang.String [] args) { 46 junit.textui.TestRunner.run(suite()); 47 } 48 49 public static Test suite() { 50 return new TestSuite(JUnitSettingsTest.class); 51 } 52 53 54 public void testReadExternal() { 55 System.out.println("testReadExternal"); 56 57 } 59 60 61 public void testWriteExternal() throws Exception { 62 System.out.println("testWriteExternal"); 63 JUnitSettings def1 = JUnitSettings.getDefault(); 64 65 File fTmp = new File(System.getProperty("xdata") + "/JUnitSettings/ser1.test"); 66 File fSer = new File(System.getProperty("xdata") + "/JUnitSettings/ser1.pass"); 67 FileInputStream fis; 68 ObjectInputStream ois; 69 FileOutputStream fos; 70 ObjectOutputStream oos; 71 72 fos = new FileOutputStream(fTmp); 74 oos = new ObjectOutputStream(fos); 75 76 def1.setFileSystem(TST_FILE_SYSTEM_1); 77 def1.setSuiteTemplate(TST_SUITE_TEMPLATE_1); 78 def1.setClassTemplate(TST_CLASS_TEMPLATE_1); 79 def1.setMembersPublic(false); 80 def1.setMembersProtected(true); 81 def1.setMembersPackage(false); 82 def1.setBodyComments(true); 83 def1.setBodyContent(false); 84 def1.setJavaDoc(true); 85 def1.setCfgCreateEnabled(false); 86 def1.setCfgExecEnabled(true); 87 def1.setExecutorType(JUnitSettings.EXECUTOR_DEBUGGER); 88 def1.setGenerateExceptionClasses(false); 89 def1.setTestRunner(TST_TEST_RUNNER_1); 90 def1.setProperties(TST_PROPERTIES_1); 91 92 JUnitSettings.getDefault().writeExternal(oos); 93 oos.close(); 94 assertFile(fTmp, fSer, new File(System.getProperty("xresults"))); 95 96 fis = new FileInputStream(fSer); 98 ois = new ObjectInputStream(fis); 99 100 JUnitSettings.getDefault().readExternal(ois); 101 assertTrue(def1.getFileSystem().equals(TST_FILE_SYSTEM_1)); 102 assertTrue(def1.getSuiteTemplate().equals(TST_SUITE_TEMPLATE_1)); 103 assertTrue(def1.getClassTemplate().equals(TST_CLASS_TEMPLATE_1)); 104 assertTrue(false == def1.isMembersPublic()); 105 assertTrue(def1.isMembersProtected()); 106 assertTrue(false == def1.isMembersPackage()); 107 assertTrue(def1.isBodyComments()); 108 assertTrue(false == def1.isBodyContent()); 109 assertTrue(def1.isJavaDoc()); 110 assertTrue(false == def1.isCfgCreateEnabled()); 111 assertTrue(def1.isCfgExecEnabled()); 112 assertTrue(JUnitSettings.EXECUTOR_DEBUGGER == def1.getExecutorType()); 113 assertTrue(false == def1.isGenerateExceptionClasses()); 114 assertEquals(def1.getTestRunner(), TST_TEST_RUNNER_1); 115 assertEquals(def1.getProperties(), TST_PROPERTIES_1); 116 117 fTmp = new File(System.getProperty("xdata") + "/JUnitSettings/ser2.test"); 118 fSer = new File(System.getProperty("xdata") + "/JUnitSettings/ser2.pass"); 119 120 fos = new FileOutputStream(fTmp); 122 oos = new ObjectOutputStream(fos); 123 124 def1.setFileSystem(TST_FILE_SYSTEM_2); 125 def1.setSuiteTemplate(TST_SUITE_TEMPLATE_2); 126 def1.setClassTemplate(TST_CLASS_TEMPLATE_2); 127 def1.setMembersPublic(true); 128 def1.setMembersProtected(false); 129 def1.setMembersPackage(true); 130 def1.setBodyComments(false); 131 def1.setBodyContent(true); 132 def1.setJavaDoc(false); 133 def1.setCfgCreateEnabled(true); 134 def1.setCfgExecEnabled(false); 135 def1.setExecutorType(JUnitSettings.EXECUTOR_INTERNAL); 136 def1.setGenerateExceptionClasses(true); 137 def1.setTestRunner(TST_TEST_RUNNER_2); 138 def1.setProperties(TST_PROPERTIES_2); 139 140 JUnitSettings.getDefault().writeExternal(oos); 141 142 fis = new FileInputStream(fSer); 144 ois = new ObjectInputStream(fis); 145 146 JUnitSettings.getDefault().readExternal(ois); 147 assertTrue(def1.getFileSystem().equals(TST_FILE_SYSTEM_2)); 148 assertTrue(def1.getSuiteTemplate().equals(TST_SUITE_TEMPLATE_2)); 149 assertTrue(def1.getClassTemplate().equals(TST_CLASS_TEMPLATE_2)); 150 assertTrue(def1.isMembersPublic()); 151 assertTrue(false == def1.isMembersProtected()); 152 assertTrue(def1.isMembersPackage()); 153 assertTrue(false == def1.isBodyComments()); 154 assertTrue(def1.isBodyContent()); 155 assertTrue(false == def1.isJavaDoc()); 156 assertTrue(def1.isCfgCreateEnabled()); 157 assertTrue(false == def1.isCfgExecEnabled()); 158 assertTrue(JUnitSettings.EXECUTOR_INTERNAL == def1.getExecutorType()); 159 assertTrue(def1.isGenerateExceptionClasses()); 160 assertEquals(def1.getTestRunner(), TST_TEST_RUNNER_2); 161 assertEquals(def1.getProperties(), TST_PROPERTIES_2); 162 163 oos.close(); 164 assertFile(fTmp, fSer, new File(System.getProperty("xresults"))); 165 } 166 167 168 public void testDisplayName() { 169 System.out.println("testDisplayName"); 170 assertTrue(null != JUnitSettings.getDefault().displayName()); 171 } 172 173 174 public void testGetHelpCtx() { 175 System.out.println("testGetHelpCtx"); 176 } 178 179 180 public void testGetDefault() { 181 System.out.println("testGetDefault"); 182 JUnitSettings def1 = JUnitSettings.getDefault(); 183 JUnitSettings def2 = JUnitSettings.getDefault(); 184 185 assertTrue(null != def1); assertTrue(def1 == def2); 188 def1.initialize(); 190 assertTrue(def1.getFileSystem().equals("")); 192 assertTrue(def1.getSuiteTemplate().equals("Templates/JUnit/SimpleTest.java")); 193 assertTrue(def1.getClassTemplate().equals("Templates/JUnit/SimpleTest.java")); 194 assertTrue(def1.isMembersPublic()); 195 assertTrue(def1.isMembersProtected()); 196 assertTrue(def1.isMembersPackage()); 197 assertTrue(def1.isBodyComments()); 198 assertTrue(def1.isBodyContent()); 199 assertTrue(def1.isJavaDoc()); 200 assertTrue(def1.isCfgCreateEnabled()); 201 assertTrue(def1.isCfgExecEnabled()); 202 assertTrue(JUnitSettings.EXECUTOR_EXTERNAL == def1.getExecutorType()); 203 } 204 205 206 public void testGetFileSystem() { 207 System.out.println("testGetFileSystem"); 208 JUnitSettings.getDefault().setFileSystem(TST_FILE_SYSTEM_1); 209 assertTrue(JUnitSettings.getDefault().getFileSystem().equals(TST_FILE_SYSTEM_1)); 210 JUnitSettings.getDefault().setFileSystem(TST_FILE_SYSTEM_2); 211 assertTrue(JUnitSettings.getDefault().getFileSystem().equals(TST_FILE_SYSTEM_2)); 212 } 213 214 215 public void testSetFileSystem() { 216 System.out.println("testSetFileSystem"); 217 } 219 220 221 public void testGetSuiteTemplate() { 222 System.out.println("testGetSuiteTemplate"); 223 JUnitSettings.getDefault().setSuiteTemplate(TST_SUITE_TEMPLATE_1); 224 assertTrue(JUnitSettings.getDefault().getSuiteTemplate().equals(TST_SUITE_TEMPLATE_1)); 225 JUnitSettings.getDefault().setSuiteTemplate(TST_SUITE_TEMPLATE_2); 226 assertTrue(JUnitSettings.getDefault().getSuiteTemplate().equals(TST_SUITE_TEMPLATE_2)); 227 } 228 229 230 public void testSetSuiteTemplate() { 231 System.out.println("testSetSuiteTemplate"); 232 } 234 235 236 public void testGetClassTemplate() { 237 System.out.println("testGetClassTemplate"); 238 JUnitSettings.getDefault().setClassTemplate(TST_CLASS_TEMPLATE_1); 239 assertTrue(JUnitSettings.getDefault().getClassTemplate().equals(TST_CLASS_TEMPLATE_1)); 240 JUnitSettings.getDefault().setClassTemplate(TST_CLASS_TEMPLATE_2); 241 assertTrue(JUnitSettings.getDefault().getClassTemplate().equals(TST_CLASS_TEMPLATE_2)); 242 } 243 244 245 public void testSetClassTemplate() { 246 System.out.println("testSetClassTemplate"); 247 } 249 250 251 public void testIsMembersPublic() { 252 System.out.println("testIsMembersPublic"); 253 JUnitSettings.getDefault().setMembersPublic(true); 254 assertTrue(JUnitSettings.getDefault().isMembersPublic()); 255 JUnitSettings.getDefault().setMembersPublic(false); 256 assertTrue(false == JUnitSettings.getDefault().isMembersPublic()); 257 } 258 259 260 public void testSetMembersPublic() { 261 System.out.println("testSetMembersPublic"); 262 } 264 265 266 public void testIsMembersProtected() { 267 System.out.println("testIsMembersProtected"); 268 JUnitSettings.getDefault().setMembersProtected(true); 269 assertTrue(JUnitSettings.getDefault().isMembersProtected()); 270 JUnitSettings.getDefault().setMembersProtected(false); 271 assertTrue(false == JUnitSettings.getDefault().isMembersProtected()); 272 } 273 274 275 public void testSetMembersProtected() { 276 System.out.println("testSetMembersProtected"); 277 } 279 280 281 public void testIsMembersPackage() { 282 System.out.println("testIsMembersPackage"); 283 JUnitSettings.getDefault().setMembersPackage(true); 284 assertTrue(JUnitSettings.getDefault().isMembersPackage()); 285 JUnitSettings.getDefault().setMembersPackage(false); 286 assertTrue(false == JUnitSettings.getDefault().isMembersPackage()); 287 } 288 289 290 public void testSetMembersPackage() { 291 System.out.println("testSetMembersPackage"); 292 } 294 295 296 public void testIsBodyComments() { 297 System.out.println("testIsBodyComments"); 298 JUnitSettings.getDefault().setBodyComments(true); 299 assertTrue(JUnitSettings.getDefault().isBodyComments()); 300 JUnitSettings.getDefault().setBodyComments(false); 301 assertTrue(false == JUnitSettings.getDefault().isBodyComments()); 302 } 303 304 305 public void testSetBodyComments() { 306 System.out.println("testSetBodyComments"); 307 } 309 310 311 public void testIsBodyContent() { 312 System.out.println("testIsBodyContent"); 313 JUnitSettings.getDefault().setBodyContent(true); 314 assertTrue(JUnitSettings.getDefault().isBodyContent()); 315 JUnitSettings.getDefault().setBodyContent(false); 316 assertTrue(false == JUnitSettings.getDefault().isBodyContent()); 317 } 318 319 320 public void testSetBodyContent() { 321 System.out.println("testSetBodyContent"); 322 } 324 325 326 public void testIsJavaDoc() { 327 System.out.println("testIsJavaDoc"); 328 JUnitSettings.getDefault().setJavaDoc(true); 329 assertTrue(JUnitSettings.getDefault().isJavaDoc()); 330 JUnitSettings.getDefault().setJavaDoc(false); 331 assertTrue(false == JUnitSettings.getDefault().isJavaDoc()); 332 } 333 334 335 public void testSetJavaDoc() { 336 System.out.println("testSetJavaDoc"); 337 } 339 340 341 public void testIsCfgCreateEnabled() { 342 System.out.println("testIsCfgCreateEnabled"); 343 JUnitSettings.getDefault().setCfgCreateEnabled(true); 344 assertTrue(JUnitSettings.getDefault().isCfgCreateEnabled()); 345 JUnitSettings.getDefault().setCfgCreateEnabled(false); 346 assertTrue(false == JUnitSettings.getDefault().isCfgCreateEnabled()); 347 } 348 349 350 public void testSetCfgCreateEnabled() { 351 System.out.println("testSetCfgCreateEnabled"); 352 } 354 355 356 public void testIsCfgExecEnabled() { 357 System.out.println("testIsCfgExecEnabled"); 358 JUnitSettings.getDefault().setCfgExecEnabled(true); 359 assertTrue(JUnitSettings.getDefault().isCfgExecEnabled()); 360 JUnitSettings.getDefault().setCfgExecEnabled(false); 361 assertTrue(false == JUnitSettings.getDefault().isCfgExecEnabled()); 362 } 363 364 365 public void testSetCfgExecEnabled() { 366 System.out.println("testSetCfgExecEnabled"); 367 } 369 370 371 public void testGetExecutorType() { 372 System.out.println("testGetExecutorType"); 373 JUnitSettings.getDefault().setExecutorType(JUnitSettings.EXECUTOR_INTERNAL); 374 assertTrue(JUnitSettings.EXECUTOR_INTERNAL == JUnitSettings.getDefault().getExecutorType()); 375 JUnitSettings.getDefault().setExecutorType(JUnitSettings.EXECUTOR_DEBUGGER); 376 assertTrue(JUnitSettings.EXECUTOR_DEBUGGER == JUnitSettings.getDefault().getExecutorType()); 377 } 378 379 380 public void testSetExecutorType() { 381 System.out.println("testSetExecutorType"); 382 } 384 385 386 public void testIsGenerateExceptionClasses() { 387 System.out.println("testIsGenerateExceptionClasses"); 388 JUnitSettings.getDefault().setGenerateExceptionClasses(true); 389 assertTrue(JUnitSettings.getDefault().isGenerateExceptionClasses()); 390 JUnitSettings.getDefault().setGenerateExceptionClasses(false); 391 assertTrue(false == JUnitSettings.getDefault().isGenerateExceptionClasses()); 392 } 393 394 395 public void testSetGenerateExceptionClasses() { 396 System.out.println("testSetGenerateExceptionClasses"); 397 } 399 400 401 public void testGetTestRunner() { 402 System.out.println("testGetTestRunner"); 403 JUnitSettings.getDefault().setTestRunner(TST_TEST_RUNNER_1); 404 assertEquals(JUnitSettings.getDefault().getTestRunner(), TST_TEST_RUNNER_1); 405 JUnitSettings.getDefault().setTestRunner(TST_TEST_RUNNER_2); 406 assertEquals(JUnitSettings.getDefault().getTestRunner(), TST_TEST_RUNNER_2); 407 } 408 409 410 public void testSetTestRunner() { 411 System.out.println("testSetTestRunner"); 412 } 414 415 416 public void testGetProperties() { 417 System.out.println("testGetProperties"); 418 JUnitSettings.getDefault().setProperties(TST_PROPERTIES_1); 419 assertEquals(JUnitSettings.getDefault().getProperties(), TST_PROPERTIES_1); 420 JUnitSettings.getDefault().setProperties(TST_PROPERTIES_2); 421 assertEquals(JUnitSettings.getDefault().getProperties(), TST_PROPERTIES_2); 422 } 423 424 425 public void testSetProperties() { 426 System.out.println("testSetProperties"); 427 } 429 430 431 public void testInitialize() { 432 System.out.println("testInitialize"); 433 } 435 436 protected File dump = new File(System.getProperty("xdata") + "/JUnitSettings/settings.dump"); 438 439 protected void setUp() { 440 FileOutputStream fos; 441 ObjectOutputStream oos; 442 443 try { 444 fos = new FileOutputStream(dump); 446 oos = new ObjectOutputStream(fos); 447 448 JUnitSettings.getDefault().writeExternal(oos); 449 oos.close(); 450 } 451 catch (IOException e) { 452 System.out.println("JUnitSettingsTest.setUp has failed " + e.getMessage()); 453 } 454 } 455 456 protected void tearDown() { 457 FileInputStream fis; 458 ObjectInputStream ois; 459 460 try { 461 fis = new FileInputStream(dump); 463 ois = new ObjectInputStream(fis); 464 465 JUnitSettings.getDefault().readExternal(ois); 466 ois.close(); 467 } 468 catch (Exception e) { 469 System.out.println("JUnitSettingsTest.tearDown has failed " + e.getMessage()); 470 } 471 } 472 473 private static final String TST_FILE_SYSTEM_1 = "MyTestFileSystem"; 475 private static final String TST_SUITE_TEMPLATE_1 = "My/Test.Suite\\Template 1"; 476 private static final String TST_CLASS_TEMPLATE_1 = "My/Test Class\\Template.1"; 477 private static final String TST_TEST_RUNNER_1 = "test.of.test.runner.property"; 478 private static final String TST_PROPERTIES_1 = "prop1=val1\nprop2=val2\n"; 479 480 private static final String TST_FILE_SYSTEM_2 = "MyTestFileSystem"; 481 private static final String TST_SUITE_TEMPLATE_2 = "My/Test.Suite\\Template 1"; 482 private static final String TST_CLASS_TEMPLATE_2 = "My/Test Class\\Template.1"; 483 private static final String TST_TEST_RUNNER_2 = "test.of.test.runner.property"; 484 private static final String TST_PROPERTIES_2 = "# comment\n\n"; 485 } 486 | Popular Tags |