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
18package tests.api.javax.net.ssl;
19
20import dalvik.annotation.TestTargetClass;
21import dalvik.annotation.TestTargets;
22import dalvik.annotation.TestLevel;
23import dalvik.annotation.TestTargetNew;
24
25import java.security.cert.CertPathParameters;
26import javax.net.ssl.CertPathTrustManagerParameters;
27
28import junit.framework.TestCase;
29
30/**
31 * Tests for <code>CertPathTrustManagerParameters</code> class constructors
32 * and methods.
33 *
34 */
35@TestTargetClass(CertPathTrustManagerParameters.class)
36public class CertPathTrustManagerParametersTest extends TestCase {
37
38    /**
39     * @tests javax.net.ssl.CertPathTrustManagerParameters#
40     *     CertPathTrustManagerParameters(java.security.cert.CertPathParameters)
41     * Case 1: Try to construct object.
42     * Case 2: Check NullPointerException.
43     */
44    @TestTargetNew(
45        level = TestLevel.COMPLETE,
46        notes = "",
47        method = "CertPathTrustManagerParameters",
48        args = {java.security.cert.CertPathParameters.class}
49    )
50    public void test_ConstructorLjava_security_cert_CertPathParameters() {
51        // case 1: Try to construct object.
52        try {
53            CertPathParameters parameters = new MyCertPathParameters();
54            CertPathTrustManagerParameters p =
55                new CertPathTrustManagerParameters(parameters);
56            assertNotSame("Parameters were cloned incorrectly",
57                    parameters, p.getParameters());
58        } catch (Exception e) {
59            fail("Unexpected exception " + e.toString());
60        }
61
62        // case 2: Check NullPointerException.
63        try {
64            new CertPathTrustManagerParameters(null);
65            fail("Expected CertPathTrustManagerParameters was not thrown");
66        } catch (NullPointerException npe) {
67            // expected
68        }
69    }
70
71    /**
72     * @tests javax.net.ssl.CertPathTrustManagerParameters#getParameters()
73     */
74    @TestTargetNew(
75        level = TestLevel.COMPLETE,
76        notes = "",
77        method = "getParameters",
78        args = {}
79    )
80    public void test_getParameters() {
81        CertPathParameters parameters = new MyCertPathParameters();
82        CertPathTrustManagerParameters p = new CertPathTrustManagerParameters(
83                parameters);
84        if (!(p.getParameters() instanceof MyCertPathParameters)) {
85            fail("incorrect parameters");
86        }
87        assertNotSame("Parameters were cloned incorrectly",
88                parameters, p.getParameters());
89    }
90}
91
92class MyCertPathParameters implements CertPathParameters {
93    public Object clone() {
94        return new MyCertPathParameters();
95    }
96}
97