11package io .github .albertus82 .jface .sysinfo ;
22
3- import java .lang .management .ManagementPermission ;
4- import java .security .Permission ;
5- import java .util .logging .Level ;
63import java .util .logging .Logger ;
74
8- import org .junit .AfterClass ;
95import org .junit .Assert ;
10- import org .junit .BeforeClass ;
116import org .junit .Test ;
127
138import io .github .albertus82 .util .logging .LoggerFactory ;
@@ -16,104 +11,9 @@ public class SystemInformationDialogTest {
1611
1712 private static final Logger log = LoggerFactory .getLogger (SystemInformationDialogTest .class );
1813
19- private static boolean skip = false ;
20-
21- @ BeforeClass
22- public static void beforeAll () {
23- if (System .getSecurityManager () != null ) {
24- log .log (Level .WARNING , "SecurityManager detected, ignoring test {0}." , SystemInformationDialogTest .class );
25- skip = true ;
26- }
27- else {
28- try {
29- System .setSecurityManager (new SecurityManager ());
30- }
31- catch (final UnsupportedOperationException e ) {
32- log .log (Level .WARNING , "SecurityManager deprecated, ignoring test {0}." , SystemInformationDialogTest .class );
33- skip = true ;
34- }
35- }
36- }
37-
38- @ AfterClass
39- public static void afterAll () {
40- if (!skip ) {
41- System .setSecurityManager (null );
42- }
43- }
44-
4514 @ Test
4615 public void testIsAvailable () {
47- if (skip ) {
48- return ;
49- }
50-
51- Assert .assertTrue (SystemInformationDialog .isAvailable ());
52-
53- System .setSecurityManager (new SecurityManager () {
54- @ Override
55- public void checkPropertiesAccess () {
56- throw new SecurityException ("1" );
57- }
58-
59- @ Override
60- public void checkPermission (final Permission perm ) { /* NOOP */ }
61- });
62- Assert .assertTrue (SystemInformationDialog .isAvailable ());
63-
64- System .setSecurityManager (new SecurityManager () {
65- @ Override
66- public void checkPropertiesAccess () { /* NOOP */ }
67-
68- @ Override
69- public void checkPermission (final Permission perm ) {
70- if (new RuntimePermission ("getenv.*" ).equals (perm )) {
71- throw new SecurityException ("2" );
72- }
73- }
74- });
75- Assert .assertTrue (SystemInformationDialog .isAvailable ());
76-
77- System .setSecurityManager (new SecurityManager () {
78- @ Override
79- public void checkPropertiesAccess () { /* NOOP */ }
80-
81- @ Override
82- public void checkPermission (final Permission perm ) {
83- if (new ManagementPermission ("monitor" ).equals (perm )) {
84- throw new SecurityException ("3" );
85- }
86- }
87- });
8816 Assert .assertTrue (SystemInformationDialog .isAvailable ());
89-
90- System .setSecurityManager (new SecurityManager () {
91- @ Override
92- public void checkPropertiesAccess () { /* NOOP */ }
93-
94- @ Override
95- public void checkPermission (final Permission perm ) {
96- if (new RuntimePermission ("getenv.*" ).equals (perm ) || new ManagementPermission ("monitor" ).equals (perm )) {
97- throw new SecurityException ("4" );
98- }
99- }
100- });
101- Assert .assertTrue (SystemInformationDialog .isAvailable ());
102-
103- System .setSecurityManager (new SecurityManager () {
104- @ Override
105- public void checkPropertiesAccess () {
106- throw new SecurityException ("5" );
107- }
108-
109- @ Override
110- public void checkPermission (final Permission perm ) {
111- if (new RuntimePermission ("getenv.*" ).equals (perm ) || new ManagementPermission ("monitor" ).equals (perm )) {
112- throw new SecurityException ("6" );
113- }
114- }
115- });
116- Assert .assertFalse (SystemInformationDialog .isAvailable ());
11717 }
11818
11919}
0 commit comments