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