|
40 | 40 | import java.net.SocketPermission;
|
41 | 41 | import java.nio.file.Files;
|
42 | 42 | import java.nio.file.Paths;
|
| 43 | +import java.security.AccessControlException; |
43 | 44 | import java.security.Permission;
|
44 | 45 | import java.util.ArrayList;
|
45 | 46 | import java.util.Arrays;
|
|
76 | 77 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
77 | 78 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
78 | 79 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
| 80 | +import static org.junit.jupiter.api.Assertions.fail; |
| 81 | +import static org.junit.jupiter.api.Assumptions.assumeTrue; |
79 | 82 | import static org.mockito.Mockito.mock;
|
80 | 83 | import static org.mockito.Mockito.when;
|
81 | 84 |
|
@@ -266,18 +269,30 @@ public void testGroupPolicies()
|
266 | 269 |
|
267 | 270 | @Test
|
268 | 271 | public void testGrant() throws Exception {
|
269 |
| - FilePermission grantPermission = |
270 |
| - new FilePermission(grantFile.getAbsolutePath(), "read"); |
271 |
| - securityManager.checkPermission(grantPermission); |
| 272 | + try { |
| 273 | + FilePermission grantPermission = |
| 274 | + new FilePermission(grantFile.getAbsolutePath(), "read"); |
| 275 | + securityManager.checkPermission(grantPermission); |
| 276 | + //Expected |
| 277 | + } catch (AccessControlException e) { |
| 278 | + assertTrue(false, "Permission should have been granted"); |
| 279 | + } catch (SecurityException e) { |
| 280 | + assumeTrue(false, "SecurityManager is non-functional (i.e. Java 24+)"); |
| 281 | + } |
272 | 282 | }
|
273 | 283 |
|
274 | 284 | @Test
|
275 | 285 | public void testDeny() throws Exception {
|
276 |
| - assertThrows(java.security.AccessControlException.class, () -> { |
| 286 | + try { |
277 | 287 | FilePermission denyPermission =
|
278 | 288 | new FilePermission(denyFile.getAbsolutePath(), "read");
|
279 | 289 | securityManager.checkPermission(denyPermission);
|
280 |
| - }); |
| 290 | + fail("Should have thrown AccessControlException"); |
| 291 | + } catch (AccessControlException e) { |
| 292 | + //Expected |
| 293 | + } catch (SecurityException e) { |
| 294 | + assumeTrue(false, "SecurityManager is non-functional (i.e. Java 24+)"); |
| 295 | + } |
281 | 296 | }
|
282 | 297 |
|
283 | 298 | @Test
|
|
0 commit comments