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