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