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