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.InvalidKeyException;
024:
025: import junit.framework.TestCase;
026:
027: /**
028: * Tests for <code>InvalidKeyException</code> class constructors and methods.
029: *
030: */
031: public class InvalidKeyExceptionTest extends TestCase {
032:
033: public static void main(String[] args) {
034: }
035:
036: /**
037: * Constructor for InvalidKeyExceptionTests.
038: *
039: * @param arg0
040: */
041: public InvalidKeyExceptionTest(String arg0) {
042: super (arg0);
043: }
044:
045: private static String[] msgs = {
046: "",
047: "Check new message",
048: "Check new message Check new message Check new message Check new message Check new message" };
049:
050: private static Throwable tCause = new Throwable(
051: "Throwable for exception");
052:
053: /**
054: * Test for <code>InvalidKeyException()</code> constructor Assertion:
055: * constructs InvalidKeyException with no detail message
056: */
057: public void testInvalidKeyException01() {
058: InvalidKeyException tE = new InvalidKeyException();
059: assertNull("getMessage() must return null.", tE.getMessage());
060: assertNull("getCause() must return null", tE.getCause());
061: }
062:
063: /**
064: * Test for <code>InvalidKeyException(String)</code> constructor
065: * Assertion: constructs InvalidKeyException with detail message msg.
066: * Parameter <code>msg</code> is not null.
067: */
068: public void testInvalidKeyException02() {
069: InvalidKeyException tE;
070: for (int i = 0; i < msgs.length; i++) {
071: tE = new InvalidKeyException(msgs[i]);
072: assertEquals("getMessage() must return: ".concat(msgs[i]),
073: tE.getMessage(), msgs[i]);
074: assertNull("getCause() must return null", tE.getCause());
075: }
076: }
077:
078: /**
079: * Test for <code>InvalidKeyException(String)</code> constructor
080: * Assertion: constructs InvalidKeyException when <code>msg</code> is null
081: */
082: public void testInvalidKeyException03() {
083: String msg = null;
084: InvalidKeyException tE = new InvalidKeyException(msg);
085: assertNull("getMessage() must return null.", tE.getMessage());
086: assertNull("getCause() must return null", tE.getCause());
087: }
088:
089: /**
090: * Test for <code>InvalidKeyException(Throwable)</code> constructor
091: * Assertion: constructs InvalidKeyException when <code>cause</code> is
092: * null
093: */
094: public void testInvalidKeyException04() {
095: Throwable cause = null;
096: InvalidKeyException tE = new InvalidKeyException(cause);
097: assertNull("getMessage() must return null.", tE.getMessage());
098: assertNull("getCause() must return null", tE.getCause());
099: }
100:
101: /**
102: * Test for <code>InvalidKeyException(Throwable)</code> constructor
103: * Assertion: constructs InvalidKeyException when <code>cause</code> is
104: * not null
105: */
106: public void testInvalidKeyException05() {
107: InvalidKeyException tE = new InvalidKeyException(tCause);
108: if (tE.getMessage() != null) {
109: String toS = tCause.toString();
110: String getM = tE.getMessage();
111: assertTrue("getMessage() should contain ".concat(toS),
112: (getM.indexOf(toS) != -1));
113: }
114: assertNotNull("getCause() must not return null", tE.getCause());
115: assertEquals("getCause() must return "
116: .concat(tCause.toString()), tE.getCause(), tCause);
117: }
118:
119: /**
120: * Test for <code>InvalidKeyException(String, Throwable)</code>
121: * constructor Assertion: constructs InvalidKeyException when
122: * <code>cause</code> is null <code>msg</code> is null
123: */
124: public void testInvalidKeyException06() {
125: InvalidKeyException tE = new InvalidKeyException(null, null);
126: assertNull("getMessage() must return null", tE.getMessage());
127: assertNull("getCause() must return null", tE.getCause());
128: }
129:
130: /**
131: * Test for <code>InvalidKeyException(String, Throwable)</code>
132: * constructor Assertion: constructs InvalidKeyException when
133: * <code>cause</code> is null <code>msg</code> is not null
134: */
135: public void testInvalidKeyException07() {
136: InvalidKeyException tE;
137: for (int i = 0; i < msgs.length; i++) {
138: tE = new InvalidKeyException(msgs[i], null);
139: assertEquals("getMessage() must return: ".concat(msgs[i]),
140: tE.getMessage(), msgs[i]);
141: assertNull("getCause() must return null", tE.getCause());
142: }
143: }
144:
145: /**
146: * Test for <code>InvalidKeyException(String, Throwable)</code>
147: * constructor Assertion: constructs InvalidKeyException when
148: * <code>cause</code> is not null <code>msg</code> is null
149: */
150: public void testInvalidKeyException08() {
151: InvalidKeyException tE = new InvalidKeyException(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 "
160: .concat(tCause.toString()), tE.getCause(), tCause);
161: }
162:
163: /**
164: * Test for <code>InvalidKeyException(String, Throwable)</code>
165: * constructor Assertion: constructs InvalidKeyException when
166: * <code>cause</code> is not null <code>msg</code> is not null
167: */
168: public void testInvalidKeyException09() {
169: InvalidKeyException tE;
170: for (int i = 0; i < msgs.length; i++) {
171: tE = new InvalidKeyException(msgs[i], tCause);
172: String getM = tE.getMessage();
173: String toS = tCause.toString();
174: if (msgs[i].length() > 0) {
175: assertTrue(
176: "getMessage() must contain ".concat(msgs[i]),
177: getM.indexOf(msgs[i]) != -1);
178: if (!getM.equals(msgs[i])) {
179: assertTrue("getMessage() should contain "
180: .concat(toS), getM.indexOf(toS) != -1);
181: }
182: }
183: assertNotNull("getCause() must not return null", tE
184: .getCause());
185: assertEquals("getCause() must return ".concat(tCause
186: .toString()), tE.getCause(), tCause);
187: }
188: }
189: }
|