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.CertPathBuilderException; 25 26import junit.framework.TestCase; 27 28 29/** 30 * Tests for <code>CertPathBuilderException</code> class constructors and 31 * methods. 32 * 33 */ 34public class CertPathBuilderExceptionTest extends TestCase { 35 36 public static void main(String[] args) { 37 } 38 39 /** 40 * Constructor for CertPathBuilderExceptionTests. 41 * 42 * @param arg0 43 */ 44 public CertPathBuilderExceptionTest(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>CertPathBuilderException()</code> constructor Assertion: 57 * constructs CertPathBuilderException with no detail message 58 */ 59 public void testCertPathBuilderException01() { 60 CertPathBuilderException tE = new CertPathBuilderException(); 61 assertNull("getMessage() must return null.", tE.getMessage()); 62 assertNull("getCause() must return null", tE.getCause()); 63 } 64 65 /** 66 * Test for <code>CertPathBuilderException(String)</code> constructor 67 * Assertion: constructs CertPathBuilderException with detail message msg. 68 * Parameter <code>msg</code> is not null. 69 */ 70 public void testCertPathBuilderException02() { 71 CertPathBuilderException tE; 72 for (int i = 0; i < msgs.length; i++) { 73 tE = new CertPathBuilderException(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>CertPathBuilderException(String)</code> constructor 82 * Assertion: constructs CertPathBuilderException when <code>msg</code> is 83 * null 84 */ 85 public void testCertPathBuilderException03() { 86 String msg = null; 87 CertPathBuilderException tE = new CertPathBuilderException(msg); 88 assertNull("getMessage() must return null.", tE.getMessage()); 89 assertNull("getCause() must return null", tE.getCause()); 90 } 91 92 /** 93 * Test for <code>CertPathBuilderException(Throwable)</code> constructor 94 * Assertion: constructs CertPathBuilderException when <code>cause</code> 95 * is null 96 */ 97 public void testCertPathBuilderException04() { 98 Throwable cause = null; 99 CertPathBuilderException tE = new CertPathBuilderException(cause); 100 assertNull("getMessage() must return null.", tE.getMessage()); 101 assertNull("getCause() must return null", tE.getCause()); 102 } 103 104 /** 105 * Test for <code>CertPathBuilderException(Throwable)</code> constructor 106 * Assertion: constructs CertPathBuilderException when <code>cause</code> 107 * is not null 108 */ 109 public void testCertPathBuilderException05() { 110 CertPathBuilderException tE = new CertPathBuilderException(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>CertPathBuilderException(String, Throwable)</code> 124 * constructor Assertion: constructs CertPathBuilderException when 125 * <code>cause</code> is null <code>msg</code> is null 126 */ 127 public void testCertPathBuilderException06() { 128 CertPathBuilderException tE = new CertPathBuilderException(null, null); 129 assertNull("getMessage() must return null", tE.getMessage()); 130 assertNull("getCause() must return null", tE.getCause()); 131 } 132 133 /** 134 * Test for <code>CertPathBuilderException(String, Throwable)</code> 135 * constructor Assertion: constructs CertPathBuilderException when 136 * <code>cause</code> is null <code>msg</code> is not null 137 */ 138 public void testCertPathBuilderException07() { 139 CertPathBuilderException tE; 140 for (int i = 0; i < msgs.length; i++) { 141 tE = new CertPathBuilderException(msgs[i], null); 142 assertEquals("getMessage() must return: ".concat(msgs[i]), tE 143 .getMessage(), msgs[i]); 144 assertNull("getCause() must return null", tE.getCause()); 145 } 146 } 147 148 /** 149 * Test for <code>CertPathBuilderException(String, Throwable)</code> 150 * constructor Assertion: constructs CertPathBuilderException when 151 * <code>cause</code> is not null <code>msg</code> is null 152 */ 153 public void testCertPathBuilderException08() { 154 CertPathBuilderException tE = new CertPathBuilderException(null, tCause); 155 if (tE.getMessage() != null) { 156 String toS = tCause.toString(); 157 String getM = tE.getMessage(); 158 assertTrue("getMessage() must should ".concat(toS), (getM 159 .indexOf(toS) != -1)); 160 } 161 assertNotNull("getCause() must not return null", tE.getCause()); 162 assertEquals("getCause() must return ".concat(tCause.toString()), tE 163 .getCause(), tCause); 164 } 165 166 /** 167 * Test for <code>CertPathBuilderException(String, Throwable)</code> 168 * constructor Assertion: constructs CertPathBuilderException when 169 * <code>cause</code> is not null <code>msg</code> is not null 170 */ 171 public void testCertPathBuilderException09() { 172 CertPathBuilderException tE; 173 for (int i = 0; i < msgs.length; i++) { 174 tE = new CertPathBuilderException(msgs[i], tCause); 175 String getM = tE.getMessage(); 176 String toS = tCause.toString(); 177 if (msgs[i].length() > 0) { 178 assertTrue("getMessage() must contain ".concat(msgs[i]), getM 179 .indexOf(msgs[i]) != -1); 180 if (!getM.equals(msgs[i])) { 181 assertTrue("getMessage() should contain ".concat(toS), getM 182 .indexOf(toS) != -1); 183 } 184 } 185 assertNotNull("getCause() must not return null", tE.getCause()); 186 assertEquals("getCause() must return ".concat(tCause.toString()), 187 tE.getCause(), tCause); 188 } 189 } 190} 191