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