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 Alexander V. Astapchuk
23 package org.apache.harmony.security.tests.java.security;
25 import dalvik.annotation.TestTargetClass;
26 import dalvik.annotation.TestTargetNew;
27 import dalvik.annotation.TestTargets;
28 import dalvik.annotation.TestLevel;
30 import java.security.Timestamp;
31 import java.security.cert.CertPath;
32 import java.util.Date;
34 import org.apache.harmony.security.tests.support.cert.MyCertPath;
36 import junit.framework.TestCase;
37 @TestTargetClass(Timestamp.class)
39 * Tests for <code>Timestamp</code> class fields and methods
43 public class TimestampTest extends TestCase {
44 private Date now = new Date();
46 private static final byte[] encoding = { 1, 2, 3 };
48 private CertPath cpath = new MyCertPath(encoding);
51 level = TestLevel.COMPLETE,
54 args = {java.util.Date.class, java.security.cert.CertPath.class}
56 public void testTimestamp() {
58 new Timestamp(null, cpath);
59 fail("null was accepted");
60 } catch (NullPointerException ex) { /* ok */
64 new Timestamp(now, null);
65 fail("null was accepted");
67 } catch (NullPointerException ex) { /* ok */
70 Timestamp timestamp = new Timestamp(now, cpath);
71 assertEquals("not expected value", now, timestamp.getTimestamp());
72 assertEquals("not expected cert path", cpath, timestamp.getSignerCertPath());
76 * Class under test for boolean equals(Object)
79 level = TestLevel.COMPLETE,
82 args = {java.lang.Object.class}
84 public void testEqualsObject() {
85 Timestamp one = new Timestamp(now, cpath);
86 Timestamp two = new Timestamp(now, cpath);
88 assertTrue(one.equals(one));
89 assertTrue(one.equals(two));
90 assertTrue(two.equals(one));
91 assertFalse(one.equals(null));
92 assertFalse(one.equals(new Object()));
94 Timestamp two1 = new Timestamp(new Date(9999), cpath);
95 assertFalse(one.equals(two1));
96 assertTrue(two1.equals(two1));
100 level = TestLevel.COMPLETE,
102 method = "getSignerCertPath",
105 public void testGetSignerCertPath() {
106 assertSame(new Timestamp(now, cpath).getSignerCertPath(), cpath);
110 level = TestLevel.COMPLETE,
112 method = "getTimestamp",
115 public void testGetTimestamp() {
116 Timestamp t = new Timestamp(now, cpath);
117 assertEquals(now, t.getTimestamp());
118 assertNotSame(now, t.getTimestamp());
122 * Class under test for String toString()
125 level = TestLevel.COMPLETE,
130 public void testToString() {
132 String tt = new Timestamp(now, cpath).toString();
133 } catch (Exception e) {
134 fail("Unexpected exception");
139 * Class under test for String hashCode()
142 level = TestLevel.COMPLETE,
147 public void testHashCode() {
148 Timestamp one = new Timestamp(now, cpath);
149 Timestamp two = new Timestamp(now, cpath);
150 Timestamp three = new Timestamp(now, new MyCertPath(new byte[] { 10,
152 Timestamp four = null;
154 assertTrue(one.hashCode() == two.hashCode());
155 assertTrue(one.hashCode() != three.hashCode());
156 assertTrue(two.hashCode() != three.hashCode());
160 fail("NullPointerException expected");
161 } catch (NullPointerException e) {