1adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/*
2adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  Licensed to the Apache Software Foundation (ASF) under one or more
3adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  contributor license agreements.  See the NOTICE file distributed with
4adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  this work for additional information regarding copyright ownership.
5adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  The ASF licenses this file to You under the Apache License, Version 2.0
6adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  (the "License"); you may not use this file except in compliance with
7adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  the License.  You may obtain a copy of the License at
8adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *
9adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *     http://www.apache.org/licenses/LICENSE-2.0
10adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *
11adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  Unless required by applicable law or agreed to in writing, software
12adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  distributed under the License is distributed on an "AS IS" BASIS,
13adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  See the License for the specific language governing permissions and
15adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  limitations under the License.
16adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */
17adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
18adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/**
19adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project* @author Vera Y. Petrashkova
20adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project* @version $Revision$
21adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project*/
22adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
23adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectpackage tests.security.cert;
24adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
25adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport junit.framework.TestCase;
26adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
27adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport java.security.cert.CertStoreException;
28adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
29adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/**
30adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project * Tests for <code>CertStoreException</code> class constructors and methods.
31f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes *
32adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */
33adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectpublic class CertStoreExceptionTest extends TestCase {
34adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
35adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    private static String[] msgs = {
36adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            "",
37adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            "Check new message",
38adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            "Check new message Check new message Check new message Check new message Check new message" };
39adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
40adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    private static Throwable tCause = new Throwable("Throwable for exception");
41adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
42adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    /**
43adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Test for <code>CertStoreException()</code> constructor Assertion:
44adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * constructs CertStoreException with no detail message
45adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     */
46adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public void testCertStoreException01() {
47adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        CertStoreException tE = new CertStoreException();
48adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertNull("getMessage() must return null.", tE.getMessage());
49adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertNull("getCause() must return null", tE.getCause());
50adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
51adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
52adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    /**
53adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Test for <code>CertStoreException(String)</code> constructor Assertion:
54adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * constructs CertStoreException with detail message msg. Parameter
55adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * <code>msg</code> is not null.
56adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     */
57adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public void testCertStoreException02() {
58adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        CertStoreException tE;
59adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        for (int i = 0; i < msgs.length; i++) {
60adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            tE = new CertStoreException(msgs[i]);
61adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            assertEquals("getMessage() must return: ".concat(msgs[i]), tE
62adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                    .getMessage(), msgs[i]);
63adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            assertNull("getCause() must return null", tE.getCause());
64adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
65adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
66adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
67adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    /**
68adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Test for <code>CertStoreException(String)</code> constructor Assertion:
69adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * constructs CertStoreException when <code>msg</code> is null
70adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     */
71adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public void testCertStoreException03() {
72adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        String msg = null;
73adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        CertStoreException tE = new CertStoreException(msg);
74adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertNull("getMessage() must return null.", tE.getMessage());
75adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertNull("getCause() must return null", tE.getCause());
76adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
77adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
78adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    /**
79adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Test for <code>CertStoreException(Throwable)</code> constructor
80adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Assertion: constructs CertStoreException when <code>cause</code> is
81adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * null
82adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     */
83adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public void testCertStoreException04() {
84adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        Throwable cause = null;
85adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        CertStoreException tE = new CertStoreException(cause);
86adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertNull("getMessage() must return null.", tE.getMessage());
87adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertNull("getCause() must return null", tE.getCause());
88adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
89adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
90adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    /**
91adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Test for <code>CertStoreException(Throwable)</code> constructor
92adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Assertion: constructs CertStoreException when <code>cause</code> is not
93adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * null
94adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     */
95adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public void testCertStoreException05() {
96adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        CertStoreException tE = new CertStoreException(tCause);
97adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        if (tE.getMessage() != null) {
98adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            String toS = tCause.toString();
99adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            String getM = tE.getMessage();
100adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            assertTrue("getMessage() should contain ".concat(toS), (getM
101adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                    .indexOf(toS) != -1));
102adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
103adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertNotNull("getCause() must not return null", tE.getCause());
104adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertEquals("getCause() must return ".concat(tCause.toString()), tE
105adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                .getCause(), tCause);
106adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
107adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
108adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    /**
109adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Test for <code>CertStoreException(String, Throwable)</code> constructor
110adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Assertion: constructs CertStoreException when <code>cause</code> is
111adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * null <code>msg</code> is null
112adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     */
113adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public void testCertStoreException06() {
114adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        CertStoreException tE = new CertStoreException(null, null);
115adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertNull("getMessage() must return null", tE.getMessage());
116adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertNull("getCause() must return null", tE.getCause());
117adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
118adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
119adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    /**
120adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Test for <code>CertStoreException(String, Throwable)</code> constructor
121adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Assertion: constructs CertStoreException when <code>cause</code> is
122adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * null <code>msg</code> is not null
123adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     */
124adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public void testCertStoreException07() {
125adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        CertStoreException tE;
126adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        for (int i = 0; i < msgs.length; i++) {
127adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            tE = new CertStoreException(msgs[i], null);
128adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            assertEquals("getMessage() must return: ".concat(msgs[i]), tE
129adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                    .getMessage(), msgs[i]);
130adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            assertNull("getCause() must return null", tE.getCause());
131adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
132adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
133adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
134adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    /**
135adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Test for <code>CertStoreException(String, Throwable)</code> constructor
136adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Assertion: constructs CertStoreException when <code>cause</code> is not
137adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * null <code>msg</code> is null
138adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     */
139adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public void testCertStoreException08() {
140adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        CertStoreException tE = new CertStoreException(null, tCause);
141adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        if (tE.getMessage() != null) {
142adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            String toS = tCause.toString();
143adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            String getM = tE.getMessage();
144adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            assertTrue("getMessage() must should ".concat(toS), (getM
145adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                    .indexOf(toS) != -1));
146adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
147adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertNotNull("getCause() must not return null", tE.getCause());
148adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        assertEquals("getCause() must return ".concat(tCause.toString()), tE
149adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                .getCause(), tCause);
150adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
151adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
152adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    /**
153adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Test for <code>CertStoreException(String, Throwable)</code> constructor
154adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * Assertion: constructs CertStoreException when <code>cause</code> is not
155adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     * null <code>msg</code> is not null
156adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project     */
157adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public void testCertStoreException09() {
158adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        CertStoreException tE;
159adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        for (int i = 0; i < msgs.length; i++) {
160adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            tE = new CertStoreException(msgs[i], tCause);
161adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            String getM = tE.getMessage();
162adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            String toS = tCause.toString();
163adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            if (msgs[i].length() > 0) {
164adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                assertTrue("getMessage() must contain ".concat(msgs[i]), getM
165adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                        .indexOf(msgs[i]) != -1);
166adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                if (!getM.equals(msgs[i])) {
167adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                    assertTrue("getMessage() should contain ".concat(toS), getM
168adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                            .indexOf(toS) != -1);
169adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                }
170adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            }
171adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            assertNotNull("getCause() must not return null", tE.getCause());
172adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            assertEquals("getCause() must return ".concat(tCause.toString()),
173adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project                    tE.getCause(), tCause);
174adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
175adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
176adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project}
177