All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testifyproject.bouncycastle.asn1.test.DeclarationOfMajorityUnitTest Maven / Gradle / Ivy

package org.testifyproject.bouncycastle.asn1.test;

import java.org.testifyproject.testifyproject.IOException;

import org.testifyproject.bouncycastle.asn1.ASN1GeneralizedTime;
import org.testifyproject.bouncycastle.asn1.ASN1InputStream;
import org.testifyproject.bouncycastle.asn1.DERTaggedObject;
import org.testifyproject.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 org.testifyproject.testifyprojectcl = new DeclarationOfMajority(dateOfBirth);

        checkConstruction(org.testifyproject.testifyprojectcl, DeclarationOfMajority.dateOfBirth, dateOfBirth, -1);

        org.testifyproject.testifyprojectcl = new DeclarationOfMajority(6);

        checkConstruction(org.testifyproject.testifyprojectcl, DeclarationOfMajority.notYoungerThan, null, 6);

        org.testifyproject.testifyprojectcl = DeclarationOfMajority.getInstance(null);

        if (org.testifyproject.testifyprojectcl != null)
        {
            fail("null getInstance() failed.");
        }

        try
        {
            DeclarationOfMajority.getInstance(new Object());

            fail("getInstance() failed to org.testifyproject.testifyprojecttect bad object.");
        }
        catch (IllegalArgumentException e)
        {
            // expected
        }
    }

    private void checkConstruction(
        DeclarationOfMajority org.testifyproject.testifyprojectcl,
        int                   type,
        ASN1GeneralizedTime   dateOfBirth,
        int                   notYoungerThan)
        throws IOException
    {
        checkValues(org.testifyproject.testifyprojectcl, type, dateOfBirth, notYoungerThan);

        org.testifyproject.testifyprojectcl = DeclarationOfMajority.getInstance(org.testifyproject.testifyprojectcl);

        checkValues(org.testifyproject.testifyprojectcl, type, dateOfBirth, notYoungerThan);

        ASN1InputStream aIn = new ASN1InputStream(org.testifyproject.testifyprojectcl.toASN1Object().getEncoded());

        DERTaggedObject info = (DERTaggedObject)aIn.readObject();

        org.testifyproject.testifyprojectcl = DeclarationOfMajority.getInstance(info);

        checkValues(org.testifyproject.testifyprojectcl, type, dateOfBirth, notYoungerThan);
    }

    private void checkValues(
        DeclarationOfMajority org.testifyproject.testifyprojectcl,
        int                   type,
        ASN1GeneralizedTime   dateOfBirth,
        int                   notYoungerThan)
    {
        checkMandatoryField("type", type, org.testifyproject.testifyprojectcl.getType());
        checkOptionalField("dateOfBirth", dateOfBirth, org.testifyproject.testifyprojectcl.getDateOfBirth());
        if (notYoungerThan != -1 && notYoungerThan != org.testifyproject.testifyprojectcl.notYoungerThan())
        {
            fail("notYoungerThan mismatch");
        }
    }

    public static void main(
        String[]    args)
    {
        runTest(new DeclarationOfMajorityUnitTest());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy