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