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 Alexander V. Astapchuk 20 */ 21 22package org.apache.harmony.security.tests.java.security; 23 24import java.security.*; 25import java.security.cert.CertPath; 26import java.util.Date; 27 28import org.apache.harmony.security.tests.support.TestCertUtils; 29 30import junit.framework.TestCase; 31 32 33/** 34 * Unit test for CodeSigner. 35 */ 36 37public class CodeSignerTest extends TestCase { 38 39 private CertPath cpath = TestCertUtils.genCertPath(3, 0); 40 private Date now = new Date(); 41 42 private Timestamp ts = new Timestamp(now, cpath); 43 44 /** 45 * must throw NPE if signerCertPath is null 46 */ 47 public void testCodeSigner_00() { 48 try { 49 new CodeSigner(null, ts); 50 fail("must not accept null"); 51 } catch (NullPointerException ex) { 52 /* it's ok */ 53 } 54 } 55 56 /** 57 * timestamp can be null 58 */ 59 public final void testCodeSigner_01() { 60 new CodeSigner(cpath, null); 61 } 62 63 /** 64 * Test various assertions about equals() 65 */ 66 public final void testEqualsObject() { 67 68 CodeSigner one = new CodeSigner(cpath, ts); 69 CodeSigner two = new CodeSigner(cpath, ts); 70 CodeSigner three = new CodeSigner(cpath, null); 71 72 CertPath cpath2 = TestCertUtils.genCertPath(5, 3); 73 CodeSigner four = new CodeSigner(cpath2, null); 74 75 assertTrue(one.equals(one)); 76 assertTrue(one.equals(two)); 77 assertTrue(two.equals(one)); 78 assertFalse(one.equals(three)); 79 assertFalse(three.equals(one)); 80 assertTrue(three.equals(three)); 81 // different CertPaths 82 assertFalse(three.equals(four)); 83 // special cases 84 assertFalse(one.equals(null)); 85 assertFalse(one.equals(new Object())); 86 } 87 88 /** 89 * Tests CodeSigner.getSignerCertPath() 90 */ 91 public void testGetSignerCertPath() { 92 assertSame(new CodeSigner(cpath, null).getSignerCertPath(), cpath); 93 } 94 95 /** 96 * Tests CodeSigner.getTimeStamp() 97 */ 98 public void testGetTimestamp() { 99 assertNull(new CodeSigner(cpath, null).getTimestamp()); 100 assertSame(new CodeSigner(cpath, ts).getTimestamp(), ts); 101 } 102 103 /** 104 * Tests CodeSigner.toString() 105 */ 106 public void testToString() { 107 new CodeSigner(cpath, null).toString(); 108 new CodeSigner(cpath, ts).toString(); 109 } 110 111} 112