![JAR search and dependency download from the Maven repository](/logo.png)
nl.open.jwtdependency.org.bouncycastle.asn1.test.Iso4217CurrencyCodeUnitTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-jwt-nodependencies Show documentation
Show all versions of java-jwt-nodependencies Show documentation
This is a drop in replacement for the auth0 java-jwt library (see https://github.com/auth0/java-jwt). This jar makes sure there are no external dependencies (e.g. fasterXml, Apacha Commons) needed. This is useful when deploying to an application server (e.g. tomcat with Alfreso or Pega).
The newest version!
package org.bouncycastle.asn1.test;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.x509.qualified.Iso4217CurrencyCode;
import org.bouncycastle.util.test.SimpleTest;
public class Iso4217CurrencyCodeUnitTest
extends SimpleTest
{
private static final String ALPHABETIC_CURRENCY_CODE = "AUD";
private static final int NUMERIC_CURRENCY_CODE = 1;
public String getName()
{
return "Iso4217CurrencyCode";
}
public void performTest()
throws Exception
{
//
// alphabetic
//
Iso4217CurrencyCode cc = new Iso4217CurrencyCode(ALPHABETIC_CURRENCY_CODE);
checkNumeric(cc, ALPHABETIC_CURRENCY_CODE);
cc = Iso4217CurrencyCode.getInstance(cc);
checkNumeric(cc, ALPHABETIC_CURRENCY_CODE);
ASN1Primitive obj = cc.toASN1Primitive();
cc = Iso4217CurrencyCode.getInstance(obj);
checkNumeric(cc, ALPHABETIC_CURRENCY_CODE);
//
// numeric
//
cc = new Iso4217CurrencyCode(NUMERIC_CURRENCY_CODE);
checkNumeric(cc, NUMERIC_CURRENCY_CODE);
cc = Iso4217CurrencyCode.getInstance(cc);
checkNumeric(cc, NUMERIC_CURRENCY_CODE);
obj = cc.toASN1Primitive();
cc = Iso4217CurrencyCode.getInstance(obj);
checkNumeric(cc, NUMERIC_CURRENCY_CODE);
cc = Iso4217CurrencyCode.getInstance(null);
if (cc != null)
{
fail("null getInstance() failed.");
}
try
{
Iso4217CurrencyCode.getInstance(new Object());
fail("getInstance() failed to detect bad object.");
}
catch (IllegalArgumentException e)
{
// expected
}
try
{
new Iso4217CurrencyCode("ABCD");
fail("constructor failed to detect out of range currencycode.");
}
catch (IllegalArgumentException e)
{
// expected
}
try
{
new Iso4217CurrencyCode(0);
fail("constructor failed to detect out of range small numeric code.");
}
catch (IllegalArgumentException e)
{
// expected
}
try
{
new Iso4217CurrencyCode(1000);
fail("constructor failed to detect out of range large numeric code.");
}
catch (IllegalArgumentException e)
{
// expected
}
}
private void checkNumeric(
Iso4217CurrencyCode cc,
String code)
{
if (!cc.isAlphabetic())
{
fail("non-alphabetic code found when one expected.");
}
if (!cc.getAlphabetic().equals(code))
{
fail("string codes don't match.");
}
}
private void checkNumeric(
Iso4217CurrencyCode cc,
int code)
{
if (cc.isAlphabetic())
{
fail("alphabetic code found when one not expected.");
}
if (cc.getNumeric() != code)
{
fail("numeric codes don't match.");
}
}
public static void main(
String[] args)
{
runTest(new Iso4217CurrencyCodeUnitTest());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy