1 19 20 package org.netbeans.core.startup; 21 22 import java.io.File ; 23 import org.netbeans.junit.NbTestCase; 24 25 27 public class NonGuiHandleImportOfUserDirTest extends NbTestCase { 28 private static NonGuiHandleImportOfUserDirTest instance; 29 30 private File user; 31 private boolean updaterInvoked; 32 private Throwable toThrow; 33 34 35 public static void main(java.lang.String [] args) throws Throwable { 36 if (instance != null) { 37 instance.nowDoTheInstall (); 39 return; 40 } else { 41 junit.textui.TestRunner.run(new junit.framework.TestSuite (NonGuiHandleImportOfUserDirTest.class)); 43 } 44 } 45 public NonGuiHandleImportOfUserDirTest (String name) { 46 super(name); 47 } 48 49 protected void setUp () throws Exception { 50 clearWorkDir (); 51 CLIOptions.clearForTests (); 52 53 File home = new File (getWorkDir (), "nb/home"); 54 user = new File (getWorkDir (), "user"); 55 56 assertTrue ("Home dir created", home.mkdirs ()); 57 assertTrue ("User dir created", user.mkdirs ()); 58 59 System.setProperty ("netbeans.home", home.toString ()); 60 System.setProperty ("netbeans.user", user.toString ()); 61 62 System.setProperty ("netbeans.importclass", NonGuiHandleImportOfUserDirTest.class.getName ()); 63 64 instance = this; 65 } 66 67 protected void tearDown () throws Exception { 68 instance = null; 69 } 70 71 72 private void nowDoTheInstall () throws Throwable { 73 assertTrue ("Called from AWT thread", javax.swing.SwingUtilities.isEventDispatchThread ()); 74 if (toThrow != null) { 75 Throwable t = toThrow; 76 toThrow = null; 77 throw t; 78 } 79 80 updaterInvoked = true; 81 } 82 83 public void testIfTheUserDirIsEmptyTheUpdaterIsInvoked () { 84 assertTrue ("Ok, returns without problems", Main.handleImportOfUserDir ()); 85 assertTrue ("the main method invoked", updaterInvoked); 86 87 toThrow = new RuntimeException (); 88 89 assertTrue ("The install is not called anymore 1", Main.handleImportOfUserDir ()); 90 assertTrue ("The install is not called anymore 2", Main.handleImportOfUserDir ()); 91 assertTrue ("The install is not called anymore 3", Main.handleImportOfUserDir ()); 92 assertTrue ("The install is not called anymore 4", Main.handleImportOfUserDir ()); 93 } 94 95 public void testIfInvokedAndThrowsExceptionTheExecutionStops () { 96 toThrow = new RuntimeException (); 97 98 assertFalse ("Says no as exception was thrown", Main.handleImportOfUserDir ()); 99 assertNull ("Justs to be sure the exception was cleared", toThrow); 100 } 101 102 public void testIfThrowsUserCancelExThenUpdateIsFinished () { 103 toThrow = new org.openide.util.UserCancelException (); 104 105 assertTrue ("Says yes as user canceled the import", Main.handleImportOfUserDir ()); 106 assertNull ("Justs to be sure the exception was cleared", toThrow); 107 108 assertTrue ("The install is not called anymore 1", Main.handleImportOfUserDir ()); 109 } 110 111 public void testExecutionGoesOnWhenThereIsIncorrctClass() { 112 System.setProperty ("netbeans.importclass", "IDoNotExists"); 113 assertFalse ("Says no as class does not exists", Main.handleImportOfUserDir ()); 114 } 115 } 116 | Popular Tags |