Home | History | Annotate | Download | only in cert
      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.CertificateEncodingException;
     28 
     29 
     30 /**
     31  * Tests for <code>CertificateEncodingException</code> class constructors and
     32  * methods.
     33  *
     34  */
     35 public class CertificateEncodingExceptionTest 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>CertificateEncodingException()</code> constructor
     46      * Assertion: constructs CertificateEncodingException with no detail message
     47      */
     48     public void testCertificateEncodingException01() {
     49         CertificateEncodingException tE = new CertificateEncodingException();
     50         assertNull("getMessage() must return null.", tE.getMessage());
     51         assertNull("getCause() must return null", tE.getCause());
     52     }
     53 
     54     /**
     55      * Test for <code>CertificateEncodingException(String)</code> constructor
     56      * Assertion: constructs CertificateEncodingException with detail message
     57      * msg. Parameter <code>msg</code> is not null.
     58      */
     59     public void testCertificateEncodingException02() {
     60         CertificateEncodingException tE;
     61         for (int i = 0; i < msgs.length; i++) {
     62             tE = new CertificateEncodingException(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>CertificateEncodingException(String)</code> constructor
     71      * Assertion: constructs CertificateEncodingException when <code>msg</code>
     72      * is null
     73      */
     74     public void testCertificateEncodingException03() {
     75         String msg = null;
     76         CertificateEncodingException tE = new CertificateEncodingException(msg);
     77         assertNull("getMessage() must return null.", tE.getMessage());
     78         assertNull("getCause() must return null", tE.getCause());
     79     }
     80 
     81     /**
     82      * Test for <code>CertificateEncodingException(Throwable)</code>
     83      * constructor Assertion: constructs CertificateEncodingException when
     84      * <code>cause</code> is null
     85      */
     86     public void testCertificateEncodingException04() {
     87         Throwable cause = null;
     88         CertificateEncodingException tE = new CertificateEncodingException(
     89                 cause);
     90         assertNull("getMessage() must return null.", tE.getMessage());
     91         assertNull("getCause() must return null", tE.getCause());
     92     }
     93 
     94     /**
     95      * Test for <code>CertificateEncodingException(Throwable)</code>
     96      * constructor Assertion: constructs CertificateEncodingException when
     97      * <code>cause</code> is not null
     98      */
     99     public void testCertificateEncodingException05() {
    100         CertificateEncodingException tE = new CertificateEncodingException(
    101                 tCause);
    102         if (tE.getMessage() != null) {
    103             String toS = tCause.toString();
    104             String getM = tE.getMessage();
    105             assertTrue("getMessage() should contain ".concat(toS), (getM
    106                     .indexOf(toS) != -1));
    107         }
    108         assertNotNull("getCause() must not return null", tE.getCause());
    109         assertEquals("getCause() must return ".concat(tCause.toString()), tE
    110                 .getCause(), tCause);
    111     }
    112 
    113     /**
    114      * Test for <code>CertificateEncodingException(String, Throwable)</code>
    115      * constructor Assertion: constructs CertificateEncodingException when
    116      * <code>cause</code> is null <code>msg</code> is null
    117      */
    118     public void testCertificateEncodingException06() {
    119         CertificateEncodingException tE = new CertificateEncodingException(
    120                 null, null);
    121         assertNull("getMessage() must return null", tE.getMessage());
    122         assertNull("getCause() must return null", tE.getCause());
    123     }
    124 
    125     /**
    126      * Test for <code>CertificateEncodingException(String, Throwable)</code>
    127      * constructor Assertion: constructs CertificateEncodingException when
    128      * <code>cause</code> is null <code>msg</code> is not null
    129      */
    130     public void testCertificateEncodingException07() {
    131         CertificateEncodingException tE;
    132         for (int i = 0; i < msgs.length; i++) {
    133             tE = new CertificateEncodingException(msgs[i], null);
    134             assertEquals("getMessage() must return: ".concat(msgs[i]), tE
    135                     .getMessage(), msgs[i]);
    136             assertNull("getCause() must return null", tE.getCause());
    137         }
    138     }
    139 
    140     /**
    141      * Test for <code>CertificateEncodingException(String, Throwable)</code>
    142      * constructor Assertion: constructs CertificateEncodingException when
    143      * <code>cause</code> is not null <code>msg</code> is null
    144      */
    145     public void testCertificateEncodingException08() {
    146         CertificateEncodingException tE = new CertificateEncodingException(
    147                 null, tCause);
    148         if (tE.getMessage() != null) {
    149             String toS = tCause.toString();
    150             String getM = tE.getMessage();
    151             assertTrue("getMessage() must should ".concat(toS), (getM
    152                     .indexOf(toS) != -1));
    153         }
    154         assertNotNull("getCause() must not return null", tE.getCause());
    155         assertEquals("getCause() must return ".concat(tCause.toString()), tE
    156                 .getCause(), tCause);
    157     }
    158 
    159     /**
    160      * Test for <code>CertificateEncodingException(String, Throwable)</code>
    161      * constructor Assertion: constructs CertificateEncodingException when
    162      * <code>cause</code> is not null <code>msg</code> is not null
    163      */
    164     public void testCertificateEncodingException09() {
    165         CertificateEncodingException tE;
    166         for (int i = 0; i < msgs.length; i++) {
    167             tE = new CertificateEncodingException(msgs[i], tCause);
    168             String getM = tE.getMessage();
    169             String toS = tCause.toString();
    170             if (msgs[i].length() > 0) {
    171                 assertTrue("getMessage() must contain ".concat(msgs[i]), getM
    172                         .indexOf(msgs[i]) != -1);
    173                 if (!getM.equals(msgs[i])) {
    174                     assertTrue("getMessage() should contain ".concat(toS), getM
    175                             .indexOf(toS) != -1);
    176                 }
    177             }
    178             assertNotNull("getCause() must not return null", tE.getCause());
    179             assertEquals("getCause() must return ".concat(tCause.toString()),
    180                     tE.getCause(), tCause);
    181         }
    182     }
    183 }
    184