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 NonGuiHandleCheckOfLicenseTest extends NbTestCase { 28 private static NonGuiHandleCheckOfLicenseTest instance; 29 30 private File user; 31 private File userVar; 32 private boolean updaterInvoked; 33 private Throwable toThrow; 34 35 public static void showLicensePanel () throws Throwable { 36 if (instance != null) { 37 instance.nowDoTheInstall (); 39 return; 40 } else { 41 junit.textui.TestRunner.run(new junit.framework.TestSuite (NonGuiHandleCheckOfLicenseTest.class)); 43 } 44 } 45 46 public NonGuiHandleCheckOfLicenseTest (String name) { 47 super(name); 48 } 49 50 protected void setUp () throws Exception { 51 clearWorkDir (); 52 CLIOptions.clearForTests (); 53 54 File home = new File (getWorkDir (), "nb/home"); 55 user = new File (getWorkDir (), "user"); 56 userVar = new File (user,"var"); 57 58 assertTrue ("Home dir created", home.mkdirs ()); 59 assertTrue ("User dir created", user.mkdirs ()); 60 61 System.setProperty ("netbeans.home", home.toString ()); 62 System.setProperty ("netbeans.user", user.toString ()); 63 64 System.setProperty ("netbeans.accept_license_class", NonGuiHandleCheckOfLicenseTest.class.getName ()); 65 66 File f = new File (userVar,"license_accepted"); 67 if (f.exists()) { 68 f.delete(); 69 } 70 71 instance = this; 72 } 73 74 protected void tearDown () throws Exception { 75 instance = null; 76 } 77 78 private void nowDoTheInstall () throws Throwable { 79 assertTrue ("Called from AWT thread", javax.swing.SwingUtilities.isEventDispatchThread ()); 80 if (toThrow != null) { 81 Throwable t = toThrow; 82 toThrow = null; 83 throw t; 84 } 85 86 updaterInvoked = true; 87 } 88 89 90 public void testIfTheUserDirIsEmptyTheLicenseCheckIsInvoked () { 91 assertTrue ("Ok, returns without problems", Main.handleLicenseCheck ()); 92 assertTrue ("the main method invoked", updaterInvoked); 93 94 toThrow = new RuntimeException (); 95 96 assertTrue ("The check is not called anymore 1", Main.handleLicenseCheck ()); 99 assertTrue ("The check is not called anymore 2", Main.handleLicenseCheck ()); 100 assertTrue ("The check is not called anymore 3", Main.handleLicenseCheck ()); 101 assertTrue ("The check is not called anymore 4", Main.handleLicenseCheck ()); 102 103 File f = new File (userVar,"license_accepted"); 104 if (f.exists()) { 105 f.delete(); 106 } 107 } 108 109 public void testIfInvokedAndThrowsExceptionTheExecutionStops () { 110 toThrow = new RuntimeException (); 111 112 assertFalse ("Says no as exception was thrown", Main.handleLicenseCheck()); 113 assertNull ("Justs to be sure the exception was cleared", toThrow); 114 } 115 116 public void testIfThrowsUserCancelExThenLicenseCheckIsCalledAgain () { 117 toThrow = new org.openide.util.UserCancelException(); 118 assertFalse("Says no as user did not accept the license", Main.handleLicenseCheck()); 119 assertNull("Justs to be sure the exception was cleared", toThrow); 120 121 toThrow = new org.openide.util.UserCancelException(); 122 assertFalse("Says no as user did not accept the license", Main.handleLicenseCheck()); 123 assertNull("Justs to be sure the exception was cleared", toThrow); 124 } 125 126 } 127 | Popular Tags |