X509CRLEntryTest.java revision 561ee011997c6c2f1befbfaa9d5f0a99771c1d63
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 Alexander Y. Kleymenov 20*/ 21 22package org.apache.harmony.security.tests.java.security.cert; 23 24import java.math.BigInteger; 25import java.security.cert.CRLException; 26import java.security.cert.X509CRLEntry; 27import java.util.Date; 28import java.util.Set; 29 30import junit.framework.Test; 31import junit.framework.TestCase; 32import junit.framework.TestSuite; 33 34/** 35 */ 36 37public class X509CRLEntryTest extends TestCase { 38 39 X509CRLEntry tbt_crlentry; 40 41 /** 42 * The stub class used for testing of non abstract methods. 43 */ 44 private class TBTCRLEntry extends X509CRLEntry { 45 public Set getNonCriticalExtensionOIDs() { 46 return null; 47 } 48 49 public Set getCriticalExtensionOIDs() { 50 return null; 51 } 52 53 public byte[] getExtensionValue(String oid) { 54 return null; 55 } 56 57 public boolean hasUnsupportedCriticalExtension() { 58 return false; 59 } 60 61 public byte[] getEncoded() throws CRLException { 62 return null; 63 } 64 65 public BigInteger getSerialNumber() { 66 return null; 67 } 68 69 public Date getRevocationDate() { 70 return null; 71 } 72 73 public boolean hasExtensions() { 74 return false; 75 } 76 77 public String toString() { 78 return null; 79 } 80 } 81 82 public X509CRLEntryTest() { 83 tbt_crlentry = new TBTCRLEntry() { 84 public byte[] getEncoded() throws CRLException { 85 return new byte[] {1, 2, 3}; 86 } 87 }; 88 } 89 90 /** 91 * equals(Object other) method testing. Tests the correctness of equal 92 * operation: it should be reflexive, symmetric, transitive, consistent 93 * and should be false on null object. 94 */ 95 public void testEquals() { 96 TBTCRLEntry tbt_crlentry_1 = new TBTCRLEntry() { 97 public byte[] getEncoded() { 98 return new byte[] {1, 2, 3}; 99 } 100 }; 101 102 TBTCRLEntry tbt_crlentry_2 = new TBTCRLEntry() { 103 public byte[] getEncoded() { 104 return new byte[] {1, 2, 3}; 105 } 106 }; 107 108 TBTCRLEntry tbt_crlentry_3 = new TBTCRLEntry() { 109 public byte[] getEncoded() { 110 return new byte[] {3, 2, 1}; 111 } 112 }; 113 114 // checking for reflexive law: 115 assertTrue("The equivalence relation should be reflexive.", 116 tbt_crlentry.equals(tbt_crlentry)); 117 118 assertEquals("The CRL Entries with equals encoded form should be equal", 119 tbt_crlentry, tbt_crlentry_1); 120 // checking for symmetric law: 121 assertTrue("The equivalence relation should be symmetric.", 122 tbt_crlentry_1.equals(tbt_crlentry)); 123 124 assertEquals("The CRL Entries with equals encoded form should be equal", 125 tbt_crlentry_1, tbt_crlentry_2); 126 // checking for transitive law: 127 assertTrue("The equivalence relation should be transitive.", 128 tbt_crlentry.equals(tbt_crlentry_2)); 129 130 assertFalse("Should not be equal to null object.", 131 tbt_crlentry.equals(null)); 132 133 assertFalse("The CRL Entries with differing encoded form " 134 + "should not be equal.", 135 tbt_crlentry.equals(tbt_crlentry_3)); 136 assertFalse("The CRL Entries should not be equals to the object " 137 + "which is not an instance of X509CRLEntry.", 138 tbt_crlentry.equals(new Object())); 139 } 140 141 /** 142 * hashCode() method testing. Tests that for equal objects hash codes 143 * are equal. 144 */ 145 public void testHashCode() { 146 TBTCRLEntry tbt_crlentry_1 = new TBTCRLEntry() { 147 public byte[] getEncoded() { 148 return new byte[] {1, 2, 3}; 149 } 150 }; 151 assertTrue("Equal objects should have the same hash codes.", 152 tbt_crlentry.hashCode() == tbt_crlentry_1.hashCode()); 153 } 154 155 /** 156 * getCertificateIssuer() method testing. Tests if the method throws 157 * appropriate exception. 158 */ 159 public void testGetCertificateIssuer() { 160 assertNull("The default implementation should return null.", 161 tbt_crlentry.getCertificateIssuer()); 162 } 163 164 public static Test suite() { 165 return new TestSuite(X509CRLEntryTest.class); 166 } 167 168 public static void main(String[] args) { 169 junit.textui.TestRunner.run(suite()); 170 } 171} 172 173