OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / org / apache / harmony / security / tests / java / security / DigestExceptionTest.java
1 /*
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 /**
19 * @author Vera Y. Petrashkova
20 * @version $Revision$
21 */
22
23 package org.apache.harmony.security.tests.java.security;
24
25 import dalvik.annotation.TestTargetClass;
26 import dalvik.annotation.TestTargets;
27 import dalvik.annotation.TestLevel;
28 import dalvik.annotation.TestTargetNew;
29
30 import java.security.DigestException;
31
32 import junit.framework.TestCase;
33 @TestTargetClass(DigestException.class)
34 /**
35  * Tests for <code>DigestException</code> class constructors and methods.
36  *
37  */
38 public class DigestExceptionTest extends TestCase {
39
40     private static String[] msgs = {
41             "",
42             "Check new message",
43             "Check new message Check new message Check new message Check new message Check new message" };
44
45     private static Throwable tCause = new Throwable("Throwable for exception");
46
47     /**
48      * Test for <code>DigestException()</code> constructor Assertion:
49      * constructs DigestException with no detail message
50      */
51     @TestTargetNew(
52         level = TestLevel.COMPLETE,
53         notes = "",
54         method = "DigestException",
55         args = {}
56     )
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());
61     }
62
63     /**
64      * Test for <code>DigestException(String)</code> constructor Assertion:
65      * constructs DigestException with detail message msg. Parameter
66      * <code>msg</code> is not null.
67      */
68     @TestTargetNew(
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}
73     )
74     public void testDigestException02() {
75         DigestException tE;
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());
81         }
82     }
83
84     /**
85      * Test for <code>DigestException(String)</code> constructor Assertion:
86      * constructs DigestException when <code>msg</code> is null
87      */
88     @TestTargetNew(
89         level = TestLevel.PARTIAL_COMPLETE,
90         notes = "Verifies case with null parameter",
91         method = "DigestException",
92         args = {java.lang.String.class}
93     )
94     public void testDigestException03() {
95         String msg = null;
96         DigestException tE = new DigestException(msg);
97         assertNull("getMessage() must return null.", tE.getMessage());
98         assertNull("getCause() must return null", tE.getCause());
99     }
100
101     /**
102      * Test for <code>DigestException(Throwable)</code> constructor Assertion:
103      * constructs DigestException when <code>cause</code> is null
104      */
105     @TestTargetNew(
106         level = TestLevel.PARTIAL_COMPLETE,
107         notes = "Verifies case with null parameter",
108         method = "DigestException",
109         args = {java.lang.Throwable.class}
110     )
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());
116     }
117
118     /**
119      * Test for <code>DigestException(Throwable)</code> constructor Assertion:
120      * constructs DigestException when <code>cause</code> is not null
121      */
122     @TestTargetNew(
123         level = TestLevel.PARTIAL_COMPLETE,
124         notes = "Verifies case with not null parameter",
125         method = "DigestException",
126         args = {java.lang.Throwable.class}
127     )
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));
135         }
136         assertNotNull("getCause() must not return null", tE.getCause());
137         assertEquals("getCause() must return ".concat(tCause.toString()), tE
138                 .getCause(), tCause);
139     }
140
141     /**
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
145      */
146     @TestTargetNew(
147         level = TestLevel.PARTIAL_COMPLETE,
148         notes = "",
149         method = "DigestException",
150         args = {java.lang.String.class, java.lang.Throwable.class}
151     )
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());
156     }
157
158     /**
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
162      */
163     @TestTargetNew(
164         level = TestLevel.PARTIAL_COMPLETE,
165         notes = "",
166         method = "DigestException",
167         args = {java.lang.String.class, java.lang.Throwable.class}
168     )
169     public void testDigestException07() {
170         DigestException tE;
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());
176         }
177     }
178
179     /**
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
183      */
184     @TestTargetNew(
185         level = TestLevel.PARTIAL_COMPLETE,
186         notes = "",
187         method = "DigestException",
188         args = {java.lang.String.class, java.lang.Throwable.class}
189     )
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));
197         }
198         assertNotNull("getCause() must not return null", tE.getCause());
199         assertEquals("getCause() must return ".concat(tCause.toString()), tE
200                 .getCause(), tCause);
201     }
202
203     /**
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
207      */
208     @TestTargetNew(
209         level = TestLevel.PARTIAL_COMPLETE,
210         notes = "",
211         method = "DigestException",
212         args = {java.lang.String.class, java.lang.Throwable.class}
213     )
214     public void testDigestException09() {
215         DigestException tE;
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);
226                 }
227             }
228             assertNotNull("getCause() must not return null", tE.getCause());
229             assertEquals("getCause() must return ".concat(tCause.toString()),
230                     tE.getCause(), tCause);
231         }
232     }
233 }