Code example for Subject

Methods: doAs

0
        } 
    } 
     
    /** 
     * @tests javax.security.auth.Subject#Subject(boolean readOnly, 
     *                                            Set<? extends Principal> principals, 
     *                                            Set<?> pubCredentials, 
     *                                            Set<?> privCredentials) 
     */ 
    @TestTargetNew( 
        level = TestLevel.COMPLETE, 
        notes = "", 
        method = "Subject", 
        args = {boolean.class, Set.class, Set.class, Set.class}
    ) 
    public void test_Constructor_02() { 
        Set <Principal> principal = new HashSet<Principal>();
        Set <Object> pubCredentials = new HashSet<Object>();
        Set <Object> privCredentials = new HashSet<Object>();
        Principal pr1 = new PrincipalImpl("TestPrincipal1");
        Principal pr2 = new PrincipalImpl("TestPrincipal2");
        principal.add(pr1);
        principal.add(pr2);
        Object pubCredential1 = new Object();
        Object pubCredential2 = new Object();
        pubCredentials.add(pubCredential1);
        pubCredentials.add(pubCredential2);
        Object privCredential1 = new Object();
        Object privCredential2 = new Object();
        privCredentials.add(privCredential1);
        privCredentials.add(privCredential2);
         
        try { 
            Subject s = new Subject(true, principal, pubCredentials, privCredentials);
            assertNotNull("Null object returned", s);
            assertTrue("Not read-only object", s.isReadOnly());