FileDocCategorySizeDatePackage
PrivilegedExceptionActionTest.javaAPI DocAndroid 1.5 API2937Wed May 06 22:41:06 BST 2009org.apache.harmony.security.tests.java.security

PrivilegedExceptionActionTest

public class PrivilegedExceptionActionTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
    
public voidtestRun()

        MyPrivilegedExceptionAction action1 = new MyPrivilegedExceptionAction();
        try {
            String result = AccessController.doPrivileged(action1);
            assertEquals("unexpected result", "ok", result);
            assertTrue("method not called", action1.called);
        } catch (PrivilegedActionException e) {
            fail("unexpected exception : " + e);
        }
        
        Exception[] exceptions = {new NullPointerException(), new IOException(), null};
        for (int i = 0; i < exceptions.length; i++) {
            Exception exception = exceptions[i];
            MyPrivilegedExceptionAction2 action2 = new MyPrivilegedExceptionAction2(exception);
            try {
                String result = AccessController.doPrivileged(action2);
                assertTrue("method not called", action1.called);
                if (exception == null)
                {
                    assertEquals("unexpected result", "ok", result);
                }
                else {
                    fail("privileged action exception expected");
                }
            } catch (PrivilegedActionException e) {
                assertTrue("method not called", action2.called);
                assertSame("expected exception not thrown", exception, e.getCause());
                // ok
            } catch (RuntimeException e) {
                assertSame("expected exception not thrown", exception, e);
            }
        }