Code example for Subject

Methods: doAsPrivileged

0
         
        try { 
            Subject s = new Subject(true, null, null, null);
            fail("NullPointerException wasn't thrown");
        } catch (NullPointerException npe) {
        } 
    } 
     
    /** 
     * @tests javax.security.auth.Subject#doAs(Subject subject, PrivilegedAction action) 
     */ 
    @TestTargetNew( 
        level = TestLevel.COMPLETE, 
        notes = "", 
        method = "doAs", 
        args = {Subject.class, PrivilegedAction.class}
    ) 
    public void test_doAs_01() { 
        Subject subj = new Subject();
        PrivilegedAction<Object> pa = new myPrivilegedAction();
        PrivilegedAction<Object> paNull = null;
         
        try { 
            Object obj = Subject.doAs(null, pa);
        } catch (Exception e) {
            fail("Unexpected exception: " + e);
        } 
         
        try { 
            Object obj = Subject.doAs(subj, pa);
        } catch (Exception e) {
            fail("Unexpected exception: " + e);
        } 
         
        try { 
            Object obj = Subject.doAs(subj, paNull);
            fail("NullPointerException wasn't thrown");