The Android Open Source Project | b5de22c | 2012-04-01 00:00:00 -0700 | [diff] [blame] | 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 | * @version $Revision$ |
| 21 | */ |
| 22 | |
| 23 | package tests.security.cert; |
| 24 | |
| 25 | import junit.framework.TestCase; |
| 26 | |
| 27 | import java.security.cert.CertPathBuilderException; |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * Tests for <code>CertPathBuilderException</code> class constructors and |
| 32 | * methods. |
| 33 | * |
| 34 | */ |
| 35 | public class CertPathBuilderExceptionTest extends TestCase { |
| 36 | |
| 37 | private static String[] msgs = { |
| 38 | "", |
| 39 | "Check new message", |
| 40 | "Check new message Check new message Check new message Check new message Check new message" }; |
| 41 | |
| 42 | private static Throwable tCause = new Throwable("Throwable for exception"); |
| 43 | |
| 44 | /** |
| 45 | * Test for <code>CertPathBuilderException()</code> constructor Assertion: |
| 46 | * constructs CertPathBuilderException with no detail message |
| 47 | */ |
| 48 | public void testCertPathBuilderException01() { |
| 49 | CertPathBuilderException tE = new CertPathBuilderException(); |
| 50 | assertNull("getMessage() must return null.", tE.getMessage()); |
| 51 | assertNull("getCause() must return null", tE.getCause()); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Test for <code>CertPathBuilderException(String)</code> constructor |
| 56 | * Assertion: constructs CertPathBuilderException with detail message msg. |
| 57 | * Parameter <code>msg</code> is not null. |
| 58 | */ |
| 59 | public void testCertPathBuilderException02() { |
| 60 | CertPathBuilderException tE; |
| 61 | for (int i = 0; i < msgs.length; i++) { |
| 62 | tE = new CertPathBuilderException(msgs[i]); |
| 63 | assertEquals("getMessage() must return: ".concat(msgs[i]), tE |
| 64 | .getMessage(), msgs[i]); |
| 65 | assertNull("getCause() must return null", tE.getCause()); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Test for <code>CertPathBuilderException(String)</code> constructor |
| 71 | * Assertion: constructs CertPathBuilderException when <code>msg</code> is |
| 72 | * null |
| 73 | */ |
| 74 | public void testCertPathBuilderException03() { |
| 75 | String msg = null; |
| 76 | CertPathBuilderException tE = new CertPathBuilderException(msg); |
| 77 | assertNull("getMessage() must return null.", tE.getMessage()); |
| 78 | assertNull("getCause() must return null", tE.getCause()); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Test for <code>CertPathBuilderException(Throwable)</code> constructor |
| 83 | * Assertion: constructs CertPathBuilderException when <code>cause</code> |
| 84 | * is null |
| 85 | */ |
| 86 | public void testCertPathBuilderException04() { |
| 87 | Throwable cause = null; |
| 88 | CertPathBuilderException tE = new CertPathBuilderException(cause); |
| 89 | assertNull("getMessage() must return null.", tE.getMessage()); |
| 90 | assertNull("getCause() must return null", tE.getCause()); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Test for <code>CertPathBuilderException(Throwable)</code> constructor |
| 95 | * Assertion: constructs CertPathBuilderException when <code>cause</code> |
| 96 | * is not null |
| 97 | */ |
| 98 | public void testCertPathBuilderException05() { |
| 99 | CertPathBuilderException tE = new CertPathBuilderException(tCause); |
| 100 | if (tE.getMessage() != null) { |
| 101 | String toS = tCause.toString(); |
| 102 | String getM = tE.getMessage(); |
| 103 | assertTrue("getMessage() should contain ".concat(toS), (getM |
| 104 | .indexOf(toS) != -1)); |
| 105 | } |
| 106 | assertNotNull("getCause() must not return null", tE.getCause()); |
| 107 | assertEquals("getCause() must return ".concat(tCause.toString()), tE |
| 108 | .getCause(), tCause); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Test for <code>CertPathBuilderException(String, Throwable)</code> |
| 113 | * constructor Assertion: constructs CertPathBuilderException when |
| 114 | * <code>cause</code> is null <code>msg</code> is null |
| 115 | */ |
| 116 | public void testCertPathBuilderException06() { |
| 117 | CertPathBuilderException tE = new CertPathBuilderException(null, null); |
| 118 | assertNull("getMessage() must return null", tE.getMessage()); |
| 119 | assertNull("getCause() must return null", tE.getCause()); |
| 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 not null |
| 126 | */ |
| 127 | public void testCertPathBuilderException07() { |
| 128 | CertPathBuilderException tE; |
| 129 | for (int i = 0; i < msgs.length; i++) { |
| 130 | tE = new CertPathBuilderException(msgs[i], null); |
| 131 | assertEquals("getMessage() must return: ".concat(msgs[i]), tE |
| 132 | .getMessage(), msgs[i]); |
| 133 | assertNull("getCause() must return null", tE.getCause()); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Test for <code>CertPathBuilderException(String, Throwable)</code> |
| 139 | * constructor Assertion: constructs CertPathBuilderException when |
| 140 | * <code>cause</code> is not null <code>msg</code> is null |
| 141 | */ |
| 142 | public void testCertPathBuilderException08() { |
| 143 | CertPathBuilderException tE = new CertPathBuilderException(null, tCause); |
| 144 | if (tE.getMessage() != null) { |
| 145 | String toS = tCause.toString(); |
| 146 | String getM = tE.getMessage(); |
| 147 | assertTrue("getMessage() must should ".concat(toS), (getM |
| 148 | .indexOf(toS) != -1)); |
| 149 | } |
| 150 | assertNotNull("getCause() must not return null", tE.getCause()); |
| 151 | assertEquals("getCause() must return ".concat(tCause.toString()), tE |
| 152 | .getCause(), tCause); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Test for <code>CertPathBuilderException(String, Throwable)</code> |
| 157 | * constructor Assertion: constructs CertPathBuilderException when |
| 158 | * <code>cause</code> is not null <code>msg</code> is not null |
| 159 | */ |
| 160 | public void testCertPathBuilderException09() { |
| 161 | CertPathBuilderException tE; |
| 162 | for (int i = 0; i < msgs.length; i++) { |
| 163 | tE = new CertPathBuilderException(msgs[i], tCause); |
| 164 | String getM = tE.getMessage(); |
| 165 | String toS = tCause.toString(); |
| 166 | if (msgs[i].length() > 0) { |
| 167 | assertTrue("getMessage() must contain ".concat(msgs[i]), getM |
| 168 | .indexOf(msgs[i]) != -1); |
| 169 | if (!getM.equals(msgs[i])) { |
| 170 | assertTrue("getMessage() should contain ".concat(toS), getM |
| 171 | .indexOf(toS) != -1); |
| 172 | } |
| 173 | } |
| 174 | assertNotNull("getCause() must not return null", tE.getCause()); |
| 175 | assertEquals("getCause() must return ".concat(tCause.toString()), |
| 176 | tE.getCause(), tCause); |
| 177 | } |
| 178 | } |
| 179 | } |