|
1
|
|
package abbot;
|
|
2
|
|
|
|
3
|
|
import javax.swing.JFrame;
|
|
4
|
|
|
|
5
|
|
import junit.extensions.abbot.TestHelper;
|
|
6
|
|
import junit.framework.TestCase;
|
|
7
|
|
|
|
8
|
|
public class NoExitSecurityManagerTest extends TestCase {
|
|
9
|
|
|
|
10
|
|
private SecurityManager oldsm;
|
|
11
|
2
|
protected void setUp() {
|
|
12
|
2
|
oldsm = System.getSecurityManager();
|
|
13
|
2
|
System.setSecurityManager(new NoExitSecurityManager() {
|
|
14
|
2
|
public void exitCalled(int code) {
|
|
15
|
|
}
|
|
16
|
|
});
|
|
17
|
|
}
|
|
18
|
|
|
|
19
|
2
|
protected void tearDown() {
|
|
20
|
2
|
System.setSecurityManager(oldsm);
|
|
21
|
|
}
|
|
22
|
|
|
|
23
|
1
|
public void testExitPrevented() {
|
|
24
|
1
|
try {
|
|
25
|
1
|
System.exit(0);
|
|
26
|
|
}
|
|
27
|
|
catch(ExitException ee) {
|
|
28
|
1
|
assertEquals("Wrong exit code", 0, ee.getStatus());
|
|
29
|
|
}
|
|
30
|
1
|
try {
|
|
31
|
1
|
System.exit(1);
|
|
32
|
|
}
|
|
33
|
|
catch(ExitException ee) {
|
|
34
|
1
|
assertEquals("Wrong exit code", 1, ee.getStatus());
|
|
35
|
|
}
|
|
36
|
|
}
|
|
37
|
|
|
|
38
|
1
|
public void testNonExitAllowed() {
|
|
39
|
1
|
JFrame frame = new JFrame(getName());
|
|
40
|
1
|
try {
|
|
41
|
|
|
|
42
|
1
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
43
|
|
|
|
44
|
|
}
|
|
45
|
|
catch(SecurityException se) {
|
|
46
|
0
|
fail("Code should be allowed to set the default frame operation.");
|
|
47
|
|
}
|
|
48
|
|
}
|
|
49
|
|
|
|
50
|
2
|
public NoExitSecurityManagerTest(String name) {
|
|
51
|
2
|
super(name);
|
|
52
|
|
}
|
|
53
|
|
|
|
54
|
0
|
public static void main(String[] args) {
|
|
55
|
0
|
TestHelper.runTests(args, NoExitSecurityManagerTest.class);
|
|
56
|
|
}
|
|
57
|
|
}
|
|
58
|
|
|