java.security.cert.CollectionCertStoreParameters#clone()源码实例Demo

下面列出了java.security.cert.CollectionCertStoreParameters#clone() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Test #1 for <code>clone()</code> method<br>
 */
public final void testClone01() {
    Vector<Certificate> certificates = new Vector<Certificate>();
    certificates.add(new MyCertificate("TEST", new byte[] {(byte)4}));
    CollectionCertStoreParameters cp1 =
        new CollectionCertStoreParameters(certificates);
    CollectionCertStoreParameters cp2 =
        (CollectionCertStoreParameters)cp1.clone();
    // check that that we have new object
    assertTrue(cp1 != cp2);
}
 
/**
 * Test #2 for <code>clone()</code> method<br>
 */
public final void testClone02() {
    Vector<Certificate> certificates = new Vector<Certificate>();
    certificates.add(new MyCertificate("TEST", new byte[] {(byte)4}));
    CollectionCertStoreParameters cp1 =
        new CollectionCertStoreParameters(certificates);
    CollectionCertStoreParameters cp2 =
        (CollectionCertStoreParameters)cp1.clone();
    // check that both objects hold the same reference
    assertTrue(cp1.getCollection() == cp2.getCollection());
}
 
/**
 * Test #3 for <code>clone()</code> method<br>
 */
public final void testClone03() {
    CollectionCertStoreParameters cp1 =
        new CollectionCertStoreParameters();
    CollectionCertStoreParameters cp2 =
        (CollectionCertStoreParameters)cp1.clone();
    CollectionCertStoreParameters cp3 =
        (CollectionCertStoreParameters)cp2.clone();
    // check that all objects hold the same reference
    assertTrue(cp1.getCollection() == cp2.getCollection() &&
               cp3.getCollection() == cp2.getCollection());
}