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