01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package javax.crypto;
22:
23: import java.security.InvalidAlgorithmParameterException;
24: import java.security.SecureRandom;
25:
26: import java.security.spec.AlgorithmParameterSpec;
27:
28: import org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi;
29:
30: import junit.framework.TestCase;
31:
32: /**
33: * Tests for <code>KeyGeneratorSpi</code> class constructors and methods.
34: *
35: */
36:
37: public class KeyGeneratorSpiTest extends TestCase {
38:
39: /**
40: * Constructor for KeyGeneratorSpiTests.
41: *
42: * @param arg0
43: */
44: public KeyGeneratorSpiTest(String arg0) {
45: super (arg0);
46: }
47:
48: /**
49: * Test for <code>KeyGeneratorSpi</code> constructor Assertion: constructs
50: * KeyGeneratorSpi
51: */
52: public void testKeyGeneratorSpi01()
53: 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: }
|