001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Vera Y. Petrashkova
020: * @version $Revision$
021: */package org.apache.harmony.security.tests.java.security;
022:
023: import java.security.InvalidAlgorithmParameterException;
024:
025: import junit.framework.TestCase;
026:
027: /**
028: * Tests for <code>InvalidAlgorithmParameterException</code> class
029: * constructors and methods.
030: *
031: */
032: public class InvalidAlgorithmParameterExceptionTest extends TestCase {
033:
034: public static void main(String[] args) {
035: }
036:
037: /**
038: * Constructor for InvalidAlgorithmParameterExceptionTests.
039: *
040: * @param arg0
041: */
042: public InvalidAlgorithmParameterExceptionTest(String arg0) {
043: super (arg0);
044: }
045:
046: private static String[] msgs = {
047: "",
048: "Check new message",
049: "Check new message Check new message Check new message Check new message Check new message" };
050:
051: private static Throwable tCause = new Throwable(
052: "Throwable for exception");
053:
054: /**
055: * Test for <code>InvalidAlgorithmParameterException()</code> constructor
056: * Assertion: constructs InvalidAlgorithmParameterException with no detail
057: * message
058: */
059: public void testInvalidAlgorithmParameterException01() {
060: InvalidAlgorithmParameterException tE = new InvalidAlgorithmParameterException();
061: assertNull("getMessage() must return null.", tE.getMessage());
062: assertNull("getCause() must return null", tE.getCause());
063: }
064:
065: /**
066: * Test for <code>InvalidAlgorithmParameterException(String)</code>
067: * constructor Assertion: constructs InvalidAlgorithmParameterException with
068: * detail message msg. Parameter <code>msg</code> is not null.
069: */
070: public void testInvalidAlgorithmParameterException02() {
071: InvalidAlgorithmParameterException tE;
072: for (int i = 0; i < msgs.length; i++) {
073: tE = new InvalidAlgorithmParameterException(msgs[i]);
074: assertEquals("getMessage() must return: ".concat(msgs[i]),
075: tE.getMessage(), msgs[i]);
076: assertNull("getCause() must return null", tE.getCause());
077: }
078: }
079:
080: /**
081: * Test for <code>InvalidAlgorithmParameterException(String)</code>
082: * constructor Assertion: constructs InvalidAlgorithmParameterException when
083: * <code>msg</code> is null
084: */
085: public void testInvalidAlgorithmParameterException03() {
086: String msg = null;
087: InvalidAlgorithmParameterException tE = new InvalidAlgorithmParameterException(
088: msg);
089: assertNull("getMessage() must return null.", tE.getMessage());
090: assertNull("getCause() must return null", tE.getCause());
091: }
092:
093: /**
094: * Test for <code>InvalidAlgorithmParameterException(Throwable)</code>
095: * constructor Assertion: constructs InvalidAlgorithmParameterException when
096: * <code>cause</code> is null
097: */
098: public void testInvalidAlgorithmParameterException04() {
099: 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),
118: (getM.indexOf(toS) != -1));
119: }
120: assertNotNull("getCause() must not return null", tE.getCause());
121: assertEquals("getCause() must return "
122: .concat(tCause.toString()), tE.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]),
149: tE.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 "
171: .concat(tCause.toString()), tE.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(
188: "getMessage() must contain ".concat(msgs[i]),
189: getM.indexOf(msgs[i]) != -1);
190: if (!getM.equals(msgs[i])) {
191: assertTrue("getMessage() should contain "
192: .concat(toS), getM.indexOf(toS) != -1);
193: }
194: }
195: assertNotNull("getCause() must not return null", tE
196: .getCause());
197: assertEquals("getCause() must return ".concat(tCause
198: .toString()), tE.getCause(), tCause);
199: }
200: }
201: }
|