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