01: package abbot;
02:
03: import javax.swing.JFrame;
04:
05: import junit.extensions.abbot.TestHelper;
06: import junit.framework.TestCase;
07:
08: public class NoExitSecurityManagerTest extends TestCase {
09:
10: private SecurityManager oldsm;
11:
12: protected void setUp() {
13: oldsm = System.getSecurityManager();
14: System.setSecurityManager(new NoExitSecurityManager() {
15: public void exitCalled(int code) {
16: }
17: });
18: }
19:
20: protected void tearDown() {
21: System.setSecurityManager(oldsm);
22: }
23:
24: public void testExitPrevented() {
25: try {
26: System.exit(0);
27: } catch (ExitException ee) {
28: assertEquals("Wrong exit code", 0, ee.getStatus());
29: }
30: try {
31: System.exit(1);
32: } catch (ExitException ee) {
33: assertEquals("Wrong exit code", 1, ee.getStatus());
34: }
35: }
36:
37: public void testNonExitAllowed() {
38: JFrame frame = new JFrame(getName());
39: try {
40: // Somebody used to call checkExit on this
41: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
42: //Runtime.getRuntime().runFinalizersOnExit(true);
43: } catch (SecurityException se) {
44: fail("Code should be allowed to set the default frame operation.");
45: }
46: }
47:
48: public NoExitSecurityManagerTest(String name) {
49: super (name);
50: }
51:
52: public static void main(String[] args) {
53: TestHelper.runTests(args, NoExitSecurityManagerTest.class);
54: }
55: }
|