01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * @version $Revision$
21: */package org.apache.harmony.security.tests.java.security;
22:
23: import java.security.*;
24: import java.security.cert.CertPath;
25: import java.util.Date;
26:
27: import org.apache.harmony.security.tests.support.cert.MyCertPath;
28:
29: import junit.framework.TestCase;
30:
31: /**
32: * Tests for <code>Timestamp</code> class fields and methods
33: *
34: */
35:
36: public class TimestampTest extends TestCase {
37:
38: public static void main(String[] args) {
39: junit.textui.TestRunner.run(TimestampTest.class);
40: }
41:
42: private Date now = new Date();
43:
44: private static final byte[] encoding = { 1, 2, 3 };
45:
46: private CertPath cpath = new MyCertPath(encoding);
47:
48: public void testTimestamp() {
49: try {
50: new Timestamp(null, cpath);
51: fail("null was accepted");
52: } catch (NullPointerException ex) { /* ok */
53: }
54:
55: try {
56: new Timestamp(now, null);
57: fail("null was accepted");
58: return;
59: } catch (NullPointerException ex) { /* ok */
60: }
61: }
62:
63: /*
64: * Class under test for boolean equals(Object)
65: */
66: public void testEqualsObject() {
67: Timestamp one = new Timestamp(now, cpath);
68: Timestamp two = new Timestamp(now, cpath);
69:
70: assertTrue(one.equals(one));
71: assertTrue(one.equals(two));
72: assertTrue(two.equals(one));
73: assertFalse(one.equals(null));
74: assertFalse(one.equals(new Object()));
75:
76: Timestamp two1 = new Timestamp(new Date(9999), cpath);
77: assertFalse(one.equals(two1));
78: assertTrue(two1.equals(two1));
79: }
80:
81: public void testGetSignerCertPath() {
82: assertSame(new Timestamp(now, cpath).getSignerCertPath(), cpath);
83: }
84:
85: public void testGetTimestamp() {
86: Timestamp t = new Timestamp(now, cpath);
87: assertEquals(now, t.getTimestamp());
88: assertNotSame(now, t.getTimestamp());
89: }
90:
91: /*
92: * Class under test for String toString()
93: */
94: public void testToString() {
95: new Timestamp(now, cpath).toString();
96: }
97:
98: }
|