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

org.bouncycastle.asn1.test.BodyPartIDTest Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.4.

There is a newer version: 1.79
Show newest version
package org.bouncycastle.asn1.test;


import org.bouncycastle.asn1.cmc.BodyPartID;
import org.bouncycastle.util.test.SimpleTest;

public class BodyPartIDTest
    extends SimpleTest
{


    public void performTest()
        throws Exception
    {
        // Test correct encode / decode


        {
            // Test encode and decode from Long and from other instance of BodyPartID
            BodyPartID bpd = new BodyPartID(10L);
            byte[] b = bpd.getEncoded();
            BodyPartID resBpd = BodyPartID.getInstance(b);
            isEquals("Correct / Encode byte array", resBpd.getID(), bpd.getID());

            BodyPartID rootPartID = new BodyPartID(12L);
            bpd = BodyPartID.getInstance(rootPartID);
            b = bpd.getEncoded();
            resBpd = BodyPartID.getInstance(b);
            isEquals("Correct / Encode byte array", resBpd.getID(), rootPartID.getID());
        }


        {
            // Test lower limit, should not throw exception
            try
            {
                new BodyPartID(0);
            }
            catch (Throwable t)
            {
                fail("Unexpected exception: " + t.getMessage(), t);
            }

            // Test below lower range
            try
            {
                new BodyPartID(-1);
                fail("Expecting IllegalArgumentException because of outside lower range");
            }
            catch (Throwable e)
            {
                if (!(e instanceof IllegalArgumentException))
                {
                    fail("Expecting only IllegalArgumentException, got:" + e.getMessage(), e);
                }
            }
        }

        {
            // Test upper limit, should not throw exception.
            try
            {
                new BodyPartID(4294967295L);
            }
            catch (Throwable t)
            {
                fail("Unexpected exception: " + t.getMessage(), t);
            }

            // Test above upper range
            try
            {
                new BodyPartID(4294967296L);
                fail("Expecting IllegalArgumentException because of outside upper range");
            }
            catch (Throwable e)
            {
                if (!(e instanceof IllegalArgumentException))
                {
                    fail("Expecting only IllegalArgumentException, got:" + e.getMessage(), e);
                }
            }
        }
    }

    public String getName()
    {
        return "BodyPartIDTest";
    }

    public static void main(String[] args)
        throws Exception
    {
        runTest(new BodyPartIDTest());
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy