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 Boris V. Kuznetsov 20 */ 21 22 package java.security; 23 24 import org.apache.harmony.security.tests.support.MySignature1; 25 26 import junit.framework.TestCase; 27 28 /** 29 * Tests for <code>Signature</code> constructor and methods 30 * 31 */ 32 public class Signature_Impl1Test extends TestCase { 33 34 /* 35 * Class under test for int sign(byte[], int, int) 36 */ testSignbyteArrayintint()37 public void testSignbyteArrayintint() throws Exception { 38 MySignature1 s = new MySignature1("ABC"); 39 byte[] b = new byte[8]; 40 try { 41 s.sign(b, 0, 5); 42 fail("No expected SignatureException 1"); 43 } catch (SignatureException e) { 44 } 45 46 s.initVerify(new MyPublicKey()); 47 48 try { 49 s.sign(b, 0, 5); 50 fail("No expected SignatureException 1"); 51 } catch (SignatureException e) { 52 } 53 54 s.initSign(new MyPrivateKey()); 55 s.sign(b, 0, 5); 56 assertEquals("state", Signature.SIGN, s.getState()); 57 assertTrue("sign() failed", s.runEngineSign); 58 } 59 60 /* 61 * Class under test for String toString() 62 */ testToString()63 public void testToString() { 64 MySignature1 s = new MySignature1("ABC"); 65 assertEquals("toString() failed", "SIGNATURE ABC state: UNINITIALIZED", 66 s.toString()); 67 } 68 69 private class MyKey implements Key { getFormat()70 public String getFormat() { 71 return "123"; 72 } getEncoded()73 public byte[] getEncoded() { 74 return null; 75 } getAlgorithm()76 public String getAlgorithm() { 77 return "aaa"; 78 } 79 } 80 81 private class MyPublicKey extends MyKey implements PublicKey {} 82 83 private class MyPrivateKey extends MyKey implements PrivateKey {} 84 85 } 86