2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @author Vera Y. Petrashkova
23 package org.apache.harmony.security.tests.java.security;
25 import dalvik.annotation.TestTargetClass;
26 import dalvik.annotation.TestTargets;
27 import dalvik.annotation.TestLevel;
28 import dalvik.annotation.TestTargetNew;
30 import java.security.KeyStore;
31 import java.security.cert.Certificate;
33 import org.apache.harmony.security.tests.support.cert.MyCertificate;
36 import junit.framework.TestCase;
37 @TestTargetClass(KeyStore.TrustedCertificateEntry.class)
39 * Tests for <code>KeyStore.TrustedCertificateEntry</code> class constructor and methods
43 public class KSTrustedCertificateEntryTest extends TestCase {
46 * Test for <codfe>KeyStore.TrustedCertificateEntry(Certificate trustCert)</code>
48 * Assertion: throws NullPointerException when trustCert is null
51 level = TestLevel.COMPLETE,
53 method = "TrustedCertificateEntry",
54 args = {java.security.cert.Certificate.class}
56 public void testTrustedCertificateEntry() {
57 Certificate cert = null;
59 new KeyStore.TrustedCertificateEntry(cert);
60 fail("NullPointerException must be thrown when trustCert is null");
61 } catch (NullPointerException e) {
64 cert = new MyCertificate("TEST", new byte[10]);
66 KeyStore.TrustedCertificateEntry ksTCE = new KeyStore.TrustedCertificateEntry(cert);
68 assertTrue(ksTCE instanceof KeyStore.TrustedCertificateEntry);
69 } catch (Exception e) {
70 fail("Unexpected exception was thrown when trustCert is not null");
75 * Test for <codfe>getTrustedCertificate()</code> method
76 * Assertion: returns trusted Certificate from goven entry
79 level = TestLevel.COMPLETE,
81 method = "getTrustedCertificate",
84 public void testGetTrustedCertificate() {
85 Certificate cert = new MyCertificate("TEST", new byte[10]);
86 KeyStore.TrustedCertificateEntry ksTCE =
87 new KeyStore.TrustedCertificateEntry(cert);
88 assertEquals("Incorrect certificate", cert, ksTCE.getTrustedCertificate());
92 * Test for <codfe>toString()</code> method
93 * Assertion: returns non null string
96 level = TestLevel.COMPLETE,
101 public void testToString() {
102 Certificate cert = new MyCertificate("TEST", new byte[10]);
103 KeyStore.TrustedCertificateEntry ksTCE =
104 new KeyStore.TrustedCertificateEntry(cert);
105 assertNotNull("toString() returns null string", ksTCE.toString());