com.fitbur.bouncycastle.asn1.test.DeclarationOfMajorityUnitTest Maven / Gradle / Ivy
package com.fitbur.bouncycastle.asn1.test;
import java.io.IOException;
import com.fitbur.bouncycastle.asn1.ASN1GeneralizedTime;
import com.fitbur.bouncycastle.asn1.ASN1InputStream;
import com.fitbur.bouncycastle.asn1.DERTaggedObject;
import com.fitbur.bouncycastle.asn1.isismtt.x509.DeclarationOfMajority;
public class DeclarationOfMajorityUnitTest
extends ASN1UnitTest
{
public String getName()
{
return "DeclarationOfMajority";
}
public void performTest()
throws Exception
{
ASN1GeneralizedTime dateOfBirth = new ASN1GeneralizedTime("20070315173729Z");
DeclarationOfMajority com.fitburcl = new DeclarationOfMajority(dateOfBirth);
checkConstruction(com.fitburcl, DeclarationOfMajority.dateOfBirth, dateOfBirth, -1);
com.fitburcl = new DeclarationOfMajority(6);
checkConstruction(com.fitburcl, DeclarationOfMajority.notYoungerThan, null, 6);
com.fitburcl = DeclarationOfMajority.getInstance(null);
if (com.fitburcl != null)
{
fail("null getInstance() failed.");
}
try
{
DeclarationOfMajority.getInstance(new Object());
fail("getInstance() failed to com.fitburtect bad object.");
}
catch (IllegalArgumentException e)
{
// expected
}
}
private void checkConstruction(
DeclarationOfMajority com.fitburcl,
int type,
ASN1GeneralizedTime dateOfBirth,
int notYoungerThan)
throws IOException
{
checkValues(com.fitburcl, type, dateOfBirth, notYoungerThan);
com.fitburcl = DeclarationOfMajority.getInstance(com.fitburcl);
checkValues(com.fitburcl, type, dateOfBirth, notYoungerThan);
ASN1InputStream aIn = new ASN1InputStream(com.fitburcl.toASN1Object().getEncoded());
DERTaggedObject info = (DERTaggedObject)aIn.readObject();
com.fitburcl = DeclarationOfMajority.getInstance(info);
checkValues(com.fitburcl, type, dateOfBirth, notYoungerThan);
}
private void checkValues(
DeclarationOfMajority com.fitburcl,
int type,
ASN1GeneralizedTime dateOfBirth,
int notYoungerThan)
{
checkMandatoryField("type", type, com.fitburcl.getType());
checkOptionalField("dateOfBirth", dateOfBirth, com.fitburcl.getDateOfBirth());
if (notYoungerThan != -1 && notYoungerThan != com.fitburcl.notYoungerThan())
{
fail("notYoungerThan mismatch");
}
}
public static void main(
String[] args)
{
runTest(new DeclarationOfMajorityUnitTest());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy