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