FileDocCategorySizeDatePackage
JavaLangReflectAccessibleObjectTest.javaAPI DocAndroid 1.5 API3628Wed May 06 22:41:06 BST 2009tests.security.permissions

JavaLangReflectAccessibleObjectTest

public class JavaLangReflectAccessibleObjectTest extends TestCase

Fields Summary
SecurityManager
old
Constructors Summary
Methods Summary
protected voidsetUp()

        old = System.getSecurityManager();
        super.setUp();
    
protected voidtearDown()

        System.setSecurityManager(old);
        super.tearDown();
    
public voidtest_setAccessibleB()

        
        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(true);
        
        assertTrue(
                "java.lang.reflect.AccessibleObject.setAccessible(boolean)  " +
                "must call checkPermission on security permissions",
                s.called);
    
public voidtest_setAccessibleLAccessibleObjectB()

        
        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);