1/* 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 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 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. 16 */ 17 18/** 19* @author Vera Y. Petrashkova 20*/ 21 22package org.apache.harmony.security.tests.java.security; 23import java.security.*; 24import java.security.cert.Certificate; 25 26import org.apache.harmony.security.tests.support.cert.MyCertificate; 27 28import junit.framework.TestCase; 29 30/** 31 * Tests for <code>KeyStore.TrustedCertificateEntry</code> class constructor and methods 32 * 33 */ 34 35public class KSTrustedCertificateEntryTest extends TestCase { 36 37 /** 38 * Test for <codfe>KeyStore.TrustedCertificateEntry(Certificate trustCert)</code> 39 * constructor 40 * Assertion: throws NullPointerException when trustCert is null 41 */ 42 public void testTrustedCertificateEntry() { 43 Certificate cert = null; 44 try { 45 new KeyStore.TrustedCertificateEntry(cert); 46 fail("NullPointerException must be thrown when trustCert is null"); 47 } catch (NullPointerException e) { 48 } 49 } 50 51 /** 52 * Test for <codfe>getTrustedCertificate()</code> method 53 * Assertion: returns trusted Certificate from goven entry 54 */ 55 public void testGetTrustedCertificate() { 56 Certificate cert = new MyCertificate("TEST", new byte[10]); 57 KeyStore.TrustedCertificateEntry ksTCE = 58 new KeyStore.TrustedCertificateEntry(cert); 59 assertEquals("Incorrect certificate", cert, ksTCE.getTrustedCertificate()); 60 } 61 62 /** 63 * Test for <codfe>toString()</code> method 64 * Assertion: returns non null string 65 */ 66 public void testToString() { 67 Certificate cert = new MyCertificate("TEST", new byte[10]); 68 KeyStore.TrustedCertificateEntry ksTCE = 69 new KeyStore.TrustedCertificateEntry(cert); 70 assertNotNull("toString() returns null string", ksTCE.toString()); 71 } 72} 73