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