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