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
18/**
19* @author Vera Y. Petrashkova
20*/
21
22package org.apache.harmony.security.tests.java.security.cert;
23
24import java.security.cert.CertificateEncodingException;
25
26import junit.framework.TestCase;
27
28
29/**
30 * Tests for <code>CertificateEncodingException</code> class constructors and
31 * methods.
32 *
33 */
34public class CertificateEncodingExceptionTest extends TestCase {
35
36    public static void main(String[] args) {
37    }
38
39    /**
40     * Constructor for CertificateEncodingExceptionTests.
41     *
42     * @param arg0
43     */
44    public CertificateEncodingExceptionTest(String arg0) {
45        super(arg0);
46    }
47
48    private static String[] msgs = {
49            "",
50            "Check new message",
51            "Check new message Check new message Check new message Check new message Check new message" };
52
53    private static Throwable tCause = new Throwable("Throwable for exception");
54
55    /**
56     * Test for <code>CertificateEncodingException()</code> constructor
57     * Assertion: constructs CertificateEncodingException with no detail message
58     */
59    public void testCertificateEncodingException01() {
60        CertificateEncodingException tE = new CertificateEncodingException();
61        assertNull("getMessage() must return null.", tE.getMessage());
62        assertNull("getCause() must return null", tE.getCause());
63    }
64
65    /**
66     * Test for <code>CertificateEncodingException(String)</code> constructor
67     * Assertion: constructs CertificateEncodingException with detail message
68     * msg. Parameter <code>msg</code> is not null.
69     */
70    public void testCertificateEncodingException02() {
71        CertificateEncodingException tE;
72        for (int i = 0; i < msgs.length; i++) {
73            tE = new CertificateEncodingException(msgs[i]);
74            assertEquals("getMessage() must return: ".concat(msgs[i]), tE
75                    .getMessage(), msgs[i]);
76            assertNull("getCause() must return null", tE.getCause());
77        }
78    }
79
80    /**
81     * Test for <code>CertificateEncodingException(String)</code> constructor
82     * Assertion: constructs CertificateEncodingException when <code>msg</code>
83     * is null
84     */
85    public void testCertificateEncodingException03() {
86        String msg = null;
87        CertificateEncodingException tE = new CertificateEncodingException(msg);
88        assertNull("getMessage() must return null.", tE.getMessage());
89        assertNull("getCause() must return null", tE.getCause());
90    }
91
92    /**
93     * Test for <code>CertificateEncodingException(Throwable)</code>
94     * constructor Assertion: constructs CertificateEncodingException when
95     * <code>cause</code> is null
96     */
97    public void testCertificateEncodingException04() {
98        Throwable cause = null;
99        CertificateEncodingException tE = new CertificateEncodingException(
100                cause);
101        assertNull("getMessage() must return null.", tE.getMessage());
102        assertNull("getCause() must return null", tE.getCause());
103    }
104
105    /**
106     * Test for <code>CertificateEncodingException(Throwable)</code>
107     * constructor Assertion: constructs CertificateEncodingException when
108     * <code>cause</code> is not null
109     */
110    public void testCertificateEncodingException05() {
111        CertificateEncodingException tE = new CertificateEncodingException(
112                tCause);
113        if (tE.getMessage() != null) {
114            String toS = tCause.toString();
115            String getM = tE.getMessage();
116            assertTrue("getMessage() should contain ".concat(toS), (getM
117                    .indexOf(toS) != -1));
118        }
119        assertNotNull("getCause() must not return null", tE.getCause());
120        assertEquals("getCause() must return ".concat(tCause.toString()), tE
121                .getCause(), tCause);
122    }
123
124    /**
125     * Test for <code>CertificateEncodingException(String, Throwable)</code>
126     * constructor Assertion: constructs CertificateEncodingException when
127     * <code>cause</code> is null <code>msg</code> is null
128     */
129    public void testCertificateEncodingException06() {
130        CertificateEncodingException tE = new CertificateEncodingException(
131                null, null);
132        assertNull("getMessage() must return null", tE.getMessage());
133        assertNull("getCause() must return null", tE.getCause());
134    }
135
136    /**
137     * Test for <code>CertificateEncodingException(String, Throwable)</code>
138     * constructor Assertion: constructs CertificateEncodingException when
139     * <code>cause</code> is null <code>msg</code> is not null
140     */
141    public void testCertificateEncodingException07() {
142        CertificateEncodingException tE;
143        for (int i = 0; i < msgs.length; i++) {
144            tE = new CertificateEncodingException(msgs[i], null);
145            assertEquals("getMessage() must return: ".concat(msgs[i]), tE
146                    .getMessage(), msgs[i]);
147            assertNull("getCause() must return null", tE.getCause());
148        }
149    }
150
151    /**
152     * Test for <code>CertificateEncodingException(String, Throwable)</code>
153     * constructor Assertion: constructs CertificateEncodingException when
154     * <code>cause</code> is not null <code>msg</code> is null
155     */
156    public void testCertificateEncodingException08() {
157        CertificateEncodingException tE = new CertificateEncodingException(
158                null, tCause);
159        if (tE.getMessage() != null) {
160            String toS = tCause.toString();
161            String getM = tE.getMessage();
162            assertTrue("getMessage() must should ".concat(toS), (getM
163                    .indexOf(toS) != -1));
164        }
165        assertNotNull("getCause() must not return null", tE.getCause());
166        assertEquals("getCause() must return ".concat(tCause.toString()), tE
167                .getCause(), tCause);
168    }
169
170    /**
171     * Test for <code>CertificateEncodingException(String, Throwable)</code>
172     * constructor Assertion: constructs CertificateEncodingException when
173     * <code>cause</code> is not null <code>msg</code> is not null
174     */
175    public void testCertificateEncodingException09() {
176        CertificateEncodingException tE;
177        for (int i = 0; i < msgs.length; i++) {
178            tE = new CertificateEncodingException(msgs[i], tCause);
179            String getM = tE.getMessage();
180            String toS = tCause.toString();
181            if (msgs[i].length() > 0) {
182                assertTrue("getMessage() must contain ".concat(msgs[i]), getM
183                        .indexOf(msgs[i]) != -1);
184                if (!getM.equals(msgs[i])) {
185                    assertTrue("getMessage() should contain ".concat(toS), getM
186                            .indexOf(toS) != -1);
187                }
188            }
189            assertNotNull("getCause() must not return null", tE.getCause());
190            assertEquals("getCause() must return ".concat(tCause.toString()),
191                    tE.getCause(), tCause);
192        }
193    }
194}
195