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