Home | History | Annotate | Download | only in spec
      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 Vladimir N. Molotkov
     20 * @version $Revision$
     21 */
     22 
     23 package tests.security.spec;
     24 
     25 import junit.framework.TestCase;
     26 
     27 import java.math.BigInteger;
     28 import java.security.spec.RSAOtherPrimeInfo;
     29 
     30 /**
     31  * Tests for <code>RSAOtherPrimeInfo</code> class fields and methods.
     32  *
     33  */
     34 public class RSAOtherPrimeInfoTest extends TestCase {
     35 
     36     /**
     37      * Test #1 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor
     38      * Assertion: constructs <code>RSAOtherPrimeInfo</code>
     39      * object using valid parameter
     40      */
     41     public final void testRSAOtherPrimeInfo01() {
     42         Object o =
     43             new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
     44                                   BigInteger.valueOf(2L),
     45                                   BigInteger.valueOf(3L));
     46         assertTrue(o instanceof RSAOtherPrimeInfo);
     47     }
     48 
     49     /**
     50      * Test #2 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor
     51      * Assertion: NullPointerException if prime is null
     52      */
     53     public final void testRSAOtherPrimeInfo02() {
     54         try {
     55             new RSAOtherPrimeInfo(null,
     56                                   BigInteger.valueOf(2L),
     57                                   BigInteger.valueOf(3L));
     58             fail("Expected NPE not thrown");
     59         } catch (NullPointerException e) {
     60         }
     61     }
     62 
     63     /**
     64      * Test #3 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor
     65      * Assertion: NullPointerException if primeExponent is null
     66      */
     67     public final void testRSAOtherPrimeInfo03() {
     68         try {
     69             new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
     70                                   null,
     71                                   BigInteger.valueOf(3L));
     72             fail("Expected NPE not thrown");
     73         } catch (NullPointerException e) {
     74         }
     75     }
     76 
     77     /**
     78      * Test #4 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor
     79      * Assertion: NullPointerException if crtCoefficient is null
     80      */
     81     public final void testRSAOtherPrimeInfo04() {
     82         try {
     83             new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
     84                                   BigInteger.valueOf(2L),
     85                                   null);
     86             fail("Expected NPE not thrown");
     87         } catch (NullPointerException e) {
     88         }
     89     }
     90 
     91     /**
     92      * Test #5 for <code>RSAOtherPrimeInfo(BigInteger,BigInteger,BigInteger)</code> ctor
     93      * Assertion: NullPointerException if prime and crtCoefficient is null
     94      */
     95     public final void testRSAOtherPrimeInfo05() {
     96         try {
     97             new RSAOtherPrimeInfo(null,
     98                                   BigInteger.valueOf(2L),
     99                                   null);
    100             fail("Expected NPE not thrown");
    101         } catch (NullPointerException e) {
    102         }
    103     }
    104 
    105     /**
    106      * Test for <code>getCrtCoefficient()</code> method<br>
    107      * Assertion: returns CRT coefficient value
    108      */
    109     public final void testGetCrtCoefficient() {
    110         RSAOtherPrimeInfo ropi =
    111             new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
    112                                   BigInteger.valueOf(2L),
    113                                   BigInteger.valueOf(3L));
    114         assertEquals(3L, ropi.getCrtCoefficient().longValue());
    115     }
    116 
    117     /**
    118      * Test for <code>getPrime()</code> method<br>
    119      * Assertion: returns prime value
    120      */
    121     public final void testGetPrime() {
    122         RSAOtherPrimeInfo ropi =
    123             new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
    124                                   BigInteger.valueOf(2L),
    125                                   BigInteger.valueOf(3L));
    126         assertEquals(1L, ropi.getPrime().longValue());
    127     }
    128 
    129     /**
    130      * Test for <code>getExponent()</code> method<br>
    131      * Assertion: returns prime exponent value
    132      */
    133     public final void testGetExponent() {
    134         RSAOtherPrimeInfo ropi =
    135             new RSAOtherPrimeInfo(BigInteger.valueOf(1L),
    136                                   BigInteger.valueOf(2L),
    137                                   BigInteger.valueOf(3L));
    138         assertEquals(2L, ropi.getExponent().longValue());
    139     }
    140 
    141 }
    142