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
{
{
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());
}
{
try
{
new BodyPartID(0);
}
catch (Throwable t)
{
fail("Unexpected exception: " + t.getMessage(), t);
}
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);
}
}
}
{
try
{
new BodyPartID(4294967295L);
}
catch (Throwable t)
{
fail("Unexpected exception: " + t.getMessage(), t);
}
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());
}
}