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