class TestSecurityManager extends SecurityManager {
boolean called = false;
@Override
public void checkPermission(Permission permission) {
if (permission instanceof ReflectPermission
&& "suppressAccessChecks".equals(permission.getName())) {
called = true;
}
}
}
TestSecurityManager s = new TestSecurityManager();
System.setSecurityManager(s);
Field field = TestClass.class.getDeclaredField("field");
field.setAccessible(TestClass.class.getDeclaredFields(), true);
assertTrue(
"java.lang.reflect.AccessibleObject.setAccessible(AccessibleObject[], boolean) "
+ "must call checkPermission on security permissions",
s.called);