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