2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @author Vera Y. Petrashkova
23 package org.apache.harmony.security.tests.java.security;
25 import dalvik.annotation.TestTargetClass;
26 import dalvik.annotation.TestTargets;
27 import dalvik.annotation.TestLevel;
28 import dalvik.annotation.TestTargetNew;
30 import java.security.DigestException;
32 import junit.framework.TestCase;
33 @TestTargetClass(DigestException.class)
35 * Tests for <code>DigestException</code> class constructors and methods.
38 public class DigestExceptionTest extends TestCase {
40 private static String[] msgs = {
43 "Check new message Check new message Check new message Check new message Check new message" };
45 private static Throwable tCause = new Throwable("Throwable for exception");
48 * Test for <code>DigestException()</code> constructor Assertion:
49 * constructs DigestException with no detail message
52 level = TestLevel.COMPLETE,
54 method = "DigestException",
57 public void testDigestException01() {
58 DigestException tE = new DigestException();
59 assertNull("getMessage() must return null.", tE.getMessage());
60 assertNull("getCause() must return null", tE.getCause());
64 * Test for <code>DigestException(String)</code> constructor Assertion:
65 * constructs DigestException with detail message msg. Parameter
66 * <code>msg</code> is not null.
69 level = TestLevel.PARTIAL_COMPLETE,
70 notes = "Verifies case with differents parameters (parameter is not null)",
71 method = "DigestException",
72 args = {java.lang.String.class}
74 public void testDigestException02() {
76 for (int i = 0; i < msgs.length; i++) {
77 tE = new DigestException(msgs[i]);
78 assertEquals("getMessage() must return: ".concat(msgs[i]), tE
79 .getMessage(), msgs[i]);
80 assertNull("getCause() must return null", tE.getCause());
85 * Test for <code>DigestException(String)</code> constructor Assertion:
86 * constructs DigestException when <code>msg</code> is null
89 level = TestLevel.PARTIAL_COMPLETE,
90 notes = "Verifies case with null parameter",
91 method = "DigestException",
92 args = {java.lang.String.class}
94 public void testDigestException03() {
96 DigestException tE = new DigestException(msg);
97 assertNull("getMessage() must return null.", tE.getMessage());
98 assertNull("getCause() must return null", tE.getCause());
102 * Test for <code>DigestException(Throwable)</code> constructor Assertion:
103 * constructs DigestException when <code>cause</code> is null
106 level = TestLevel.PARTIAL_COMPLETE,
107 notes = "Verifies case with null parameter",
108 method = "DigestException",
109 args = {java.lang.Throwable.class}
111 public void testDigestException04() {
112 Throwable cause = null;
113 DigestException tE = new DigestException(cause);
114 assertNull("getMessage() must return null.", tE.getMessage());
115 assertNull("getCause() must return null", tE.getCause());
119 * Test for <code>DigestException(Throwable)</code> constructor Assertion:
120 * constructs DigestException when <code>cause</code> is not null
123 level = TestLevel.PARTIAL_COMPLETE,
124 notes = "Verifies case with not null parameter",
125 method = "DigestException",
126 args = {java.lang.Throwable.class}
128 public void testDigestException05() {
129 DigestException tE = new DigestException(tCause);
130 if (tE.getMessage() != null) {
131 String toS = tCause.toString();
132 String getM = tE.getMessage();
133 assertTrue("getMessage() should contain ".concat(toS), (getM
134 .indexOf(toS) != -1));
136 assertNotNull("getCause() must not return null", tE.getCause());
137 assertEquals("getCause() must return ".concat(tCause.toString()), tE
138 .getCause(), tCause);
142 * Test for <code>DigestException(String, Throwable)</code> constructor
143 * Assertion: constructs DigestException when <code>cause</code> is null
144 * <code>msg</code> is null
147 level = TestLevel.PARTIAL_COMPLETE,
149 method = "DigestException",
150 args = {java.lang.String.class, java.lang.Throwable.class}
152 public void testDigestException06() {
153 DigestException tE = new DigestException(null, null);
154 assertNull("getMessage() must return null", tE.getMessage());
155 assertNull("getCause() must return null", tE.getCause());
159 * Test for <code>DigestException(String, Throwable)</code> constructor
160 * Assertion: constructs DigestException when <code>cause</code> is null
161 * <code>msg</code> is not null
164 level = TestLevel.PARTIAL_COMPLETE,
166 method = "DigestException",
167 args = {java.lang.String.class, java.lang.Throwable.class}
169 public void testDigestException07() {
171 for (int i = 0; i < msgs.length; i++) {
172 tE = new DigestException(msgs[i], null);
173 assertEquals("getMessage() must return: ".concat(msgs[i]), tE
174 .getMessage(), msgs[i]);
175 assertNull("getCause() must return null", tE.getCause());
180 * Test for <code>DigestException(String, Throwable)</code> constructor
181 * Assertion: constructs DigestException when <code>cause</code> is not
182 * null <code>msg</code> is null
185 level = TestLevel.PARTIAL_COMPLETE,
187 method = "DigestException",
188 args = {java.lang.String.class, java.lang.Throwable.class}
190 public void testDigestException08() {
191 DigestException tE = new DigestException(null, tCause);
192 if (tE.getMessage() != null) {
193 String toS = tCause.toString();
194 String getM = tE.getMessage();
195 assertTrue("getMessage() must should ".concat(toS), (getM
196 .indexOf(toS) != -1));
198 assertNotNull("getCause() must not return null", tE.getCause());
199 assertEquals("getCause() must return ".concat(tCause.toString()), tE
200 .getCause(), tCause);
204 * Test for <code>DigestException(String, Throwable)</code> constructor
205 * Assertion: constructs DigestException when <code>cause</code> is not
206 * null <code>msg</code> is not null
209 level = TestLevel.PARTIAL_COMPLETE,
211 method = "DigestException",
212 args = {java.lang.String.class, java.lang.Throwable.class}
214 public void testDigestException09() {
216 for (int i = 0; i < msgs.length; i++) {
217 tE = new DigestException(msgs[i], tCause);
218 String getM = tE.getMessage();
219 String toS = tCause.toString();
220 if (msgs[i].length() > 0) {
221 assertTrue("getMessage() must contain ".concat(msgs[i]), getM
222 .indexOf(msgs[i]) != -1);
223 if (!getM.equals(msgs[i])) {
224 assertTrue("getMessage() should contain ".concat(toS), getM
225 .indexOf(toS) != -1);
228 assertNotNull("getCause() must not return null", tE.getCause());
229 assertEquals("getCause() must return ".concat(tCause.toString()),
230 tE.getCause(), tCause);