Home | History | Annotate | Download | only in security
      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 package org.apache.harmony.security.tests.java.security;
     19 
     20 import java.security.KeyFactorySpi;
     21 import java.security.PrivateKey;
     22 import java.security.spec.KeySpec;
     23 import java.security.PublicKey;
     24 import java.security.Key;
     25 
     26 import junit.framework.TestCase;
     27 
     28 /**
     29  * Tests for <code>KeyFactorySpi</code> class constructors
     30  * and methods.
     31  *
     32  */
     33 public class KeyFactorySpiTest extends TestCase {
     34 
     35     /**
     36      * Test for <code>KeyFactorySpi</code> constructor
     37      * Assertion: constructs KeyFactorySpi
     38      */
     39     public void testKeyFactorySpi() {
     40         MyKeyFactorySpi keyFSpi = new MyKeyFactorySpi();
     41         assertTrue(keyFSpi instanceof KeyFactorySpi);
     42 
     43         KeySpec ks = new MyKeySpec();
     44         KeySpec kss = new MyKeySpec();
     45         try {
     46             keyFSpi.engineGeneratePrivate(ks);
     47             keyFSpi.engineGeneratePublic(ks);
     48             keyFSpi.engineGetKeySpec(null, java.lang.Class.class);
     49             keyFSpi.engineTranslateKey(null);
     50         } catch (Exception e) {
     51             fail("Unexpected exception");
     52         }
     53     }
     54 
     55     public class MyKeyFactorySpi extends KeyFactorySpi {
     56         protected PrivateKey engineGeneratePrivate(KeySpec keySpec){
     57             return null;
     58         }
     59         protected PublicKey engineGeneratePublic(KeySpec keySpec){
     60             return null;
     61         }
     62         protected KeySpec engineGetKeySpec(Key key, Class keySpec){
     63             return null;
     64         }
     65         protected Key engineTranslateKey(Key key){
     66             return null;
     67         }
     68     }
     69 
     70     class MyKeySpec implements KeySpec {}
     71 }
     72