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 tests.security.cert; 24 25 import junit.framework.TestCase; 26 27 import java.security.cert.CertStoreException; 28 29 /** 30 * Tests for <code>CertStoreException</code> class constructors and methods. 31 * 32 */ 33 public class CertStoreExceptionTest extends TestCase { 34 35 private static String[] msgs = { 36 "", 37 "Check new message", 38 "Check new message Check new message Check new message Check new message Check new message" }; 39 40 private static Throwable tCause = new Throwable("Throwable for exception"); 41 42 /** 43 * Test for <code>CertStoreException()</code> constructor Assertion: 44 * constructs CertStoreException with no detail message 45 */ 46 public void testCertStoreException01() { 47 CertStoreException tE = new CertStoreException(); 48 assertNull("getMessage() must return null.", tE.getMessage()); 49 assertNull("getCause() must return null", tE.getCause()); 50 } 51 52 /** 53 * Test for <code>CertStoreException(String)</code> constructor Assertion: 54 * constructs CertStoreException with detail message msg. Parameter 55 * <code>msg</code> is not null. 56 */ 57 public void testCertStoreException02() { 58 CertStoreException tE; 59 for (int i = 0; i < msgs.length; i++) { 60 tE = new CertStoreException(msgs[i]); 61 assertEquals("getMessage() must return: ".concat(msgs[i]), tE 62 .getMessage(), msgs[i]); 63 assertNull("getCause() must return null", tE.getCause()); 64 } 65 } 66 67 /** 68 * Test for <code>CertStoreException(String)</code> constructor Assertion: 69 * constructs CertStoreException when <code>msg</code> is null 70 */ 71 public void testCertStoreException03() { 72 String msg = null; 73 CertStoreException tE = new CertStoreException(msg); 74 assertNull("getMessage() must return null.", tE.getMessage()); 75 assertNull("getCause() must return null", tE.getCause()); 76 } 77 78 /** 79 * Test for <code>CertStoreException(Throwable)</code> constructor 80 * Assertion: constructs CertStoreException when <code>cause</code> is 81 * null 82 */ 83 public void testCertStoreException04() { 84 Throwable cause = null; 85 CertStoreException tE = new CertStoreException(cause); 86 assertNull("getMessage() must return null.", tE.getMessage()); 87 assertNull("getCause() must return null", tE.getCause()); 88 } 89 90 /** 91 * Test for <code>CertStoreException(Throwable)</code> constructor 92 * Assertion: constructs CertStoreException when <code>cause</code> is not 93 * null 94 */ 95 public void testCertStoreException05() { 96 CertStoreException tE = new CertStoreException(tCause); 97 if (tE.getMessage() != null) { 98 String toS = tCause.toString(); 99 String getM = tE.getMessage(); 100 assertTrue("getMessage() should contain ".concat(toS), (getM 101 .indexOf(toS) != -1)); 102 } 103 assertNotNull("getCause() must not return null", tE.getCause()); 104 assertEquals("getCause() must return ".concat(tCause.toString()), tE 105 .getCause(), tCause); 106 } 107 108 /** 109 * Test for <code>CertStoreException(String, Throwable)</code> constructor 110 * Assertion: constructs CertStoreException when <code>cause</code> is 111 * null <code>msg</code> is null 112 */ 113 public void testCertStoreException06() { 114 CertStoreException tE = new CertStoreException(null, null); 115 assertNull("getMessage() must return null", tE.getMessage()); 116 assertNull("getCause() must return null", tE.getCause()); 117 } 118 119 /** 120 * Test for <code>CertStoreException(String, Throwable)</code> constructor 121 * Assertion: constructs CertStoreException when <code>cause</code> is 122 * null <code>msg</code> is not null 123 */ 124 public void testCertStoreException07() { 125 CertStoreException tE; 126 for (int i = 0; i < msgs.length; i++) { 127 tE = new CertStoreException(msgs[i], null); 128 assertEquals("getMessage() must return: ".concat(msgs[i]), tE 129 .getMessage(), msgs[i]); 130 assertNull("getCause() must return null", tE.getCause()); 131 } 132 } 133 134 /** 135 * Test for <code>CertStoreException(String, Throwable)</code> constructor 136 * Assertion: constructs CertStoreException when <code>cause</code> is not 137 * null <code>msg</code> is null 138 */ 139 public void testCertStoreException08() { 140 CertStoreException tE = new CertStoreException(null, tCause); 141 if (tE.getMessage() != null) { 142 String toS = tCause.toString(); 143 String getM = tE.getMessage(); 144 assertTrue("getMessage() must should ".concat(toS), (getM 145 .indexOf(toS) != -1)); 146 } 147 assertNotNull("getCause() must not return null", tE.getCause()); 148 assertEquals("getCause() must return ".concat(tCause.toString()), tE 149 .getCause(), tCause); 150 } 151 152 /** 153 * Test for <code>CertStoreException(String, Throwable)</code> constructor 154 * Assertion: constructs CertStoreException when <code>cause</code> is not 155 * null <code>msg</code> is not null 156 */ 157 public void testCertStoreException09() { 158 CertStoreException tE; 159 for (int i = 0; i < msgs.length; i++) { 160 tE = new CertStoreException(msgs[i], tCause); 161 String getM = tE.getMessage(); 162 String toS = tCause.toString(); 163 if (msgs[i].length() > 0) { 164 assertTrue("getMessage() must contain ".concat(msgs[i]), getM 165 .indexOf(msgs[i]) != -1); 166 if (!getM.equals(msgs[i])) { 167 assertTrue("getMessage() should contain ".concat(toS), getM 168 .indexOf(toS) != -1); 169 } 170 } 171 assertNotNull("getCause() must not return null", tE.getCause()); 172 assertEquals("getCause() must return ".concat(tCause.toString()), 173 tE.getCause(), tCause); 174 } 175 } 176 } 177