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  */
21 
22 package javax.crypto;
23 
24 
25 import java.security.InvalidAlgorithmParameterException;
26 import java.security.SecureRandom;
27 
28 import java.security.spec.AlgorithmParameterSpec;
29 
30 import org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi;
31 
32 import junit.framework.TestCase;
33 
34 /**
35  * Tests for <code>KeyGeneratorSpi</code> class constructors and methods.
36  */
37 
38 public class KeyGeneratorSpiTest extends TestCase {
39 
40     /**
41      * Constructor for KeyGeneratorSpiTests.
42      *
43      * @param arg0
44      */
KeyGeneratorSpiTest(String arg0)45     public KeyGeneratorSpiTest(String arg0) {
46         super(arg0);
47     }
48 
49     /**
50      * Test for <code>KeyGeneratorSpi</code> constructor Assertion: constructs
51      * KeyGeneratorSpi
52      */
testKeyGeneratorSpi01()53     public void testKeyGeneratorSpi01() throws InvalidAlgorithmParameterException {
54         KeyGeneratorSpi kgSpi = new MyKeyGeneratorSpi();
55         assertNull("Not null result", kgSpi.engineGenerateKey());
56         try {
57             kgSpi.engineInit(77, new SecureRandom());
58             fail("IllegalArgumentException must be thrown");
59         } catch (IllegalArgumentException e) {
60         }
61         try {
62             kgSpi.engineInit(new SecureRandom());
63             fail("IllegalArgumentException must be thrown");
64         } catch (IllegalArgumentException e) {
65         }
66         AlgorithmParameterSpec aps = null;
67         try {
68             kgSpi.engineInit(aps, new SecureRandom());
69             fail("InvalidAlgorithmParameterException must be thrown when parameter is null");
70         } catch (InvalidAlgorithmParameterException e) {
71         }
72         aps = new APSpecSpi();
73         kgSpi.engineInit(aps, new SecureRandom());
74     }
75 }
76 
77 class APSpecSpi implements AlgorithmParameterSpec {
78 
79 }
80