Code example for KeyStore

Methods: containsAlias, getCertificate, getCertificateAlias, getCertificateChain, getCreationDate, getKey, isCertificateEntry, isKeyEntry, load, size

0
    private void checkResult(KeyStore keyS) throws KeyStoreException,
            IOException, CertificateException, NoSuchAlgorithmException, 
            UnrecoverableKeyException { 
        char[] pass = { 'a', 'b', 'c' };
        String alias = "aaa";        
        keyS.load(null, pass);
        assertNull("getKey must return null", keyS.getKey(alias, pass));
        assertNull("getCertificate must return null", keyS
                .getCertificate(alias));
        assertNull("getCertificateChain must return null", keyS
                .getCertificateChain(alias));
        assertEquals("Incorrect result of getCreationDate", keyS
                .getCreationDate(alias), new Date(0));
        assertEquals("Incorrect result of size", keyS.size(), 0);
        assertFalse("Incorrect result of isCertificateEntry", keyS
                .isCertificateEntry(alias));
        assertFalse("Incorrect result of isKeyEntry", keyS.isKeyEntry(alias));
        assertFalse("Incorrect result of containsAlias", keyS
                .containsAlias(alias));
        assertEquals("Incorrect result of getCertificateAlias", keyS
                .getCertificateAlias(null), "");
        try { 
            keyS.setCertificateEntry(alias, null);
            fail("KeyStoreException must be thrown because this method is not supported");
        } catch (KeyStoreException e) {
        }