Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.asn1.test;
  
  
  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
         //
 
         checkNumeric(cc);
         
         cc = Iso4217CurrencyCode.getInstance(cc);
         
         checkNumeric(cc);
         
         ASN1Primitive obj = cc.toASN1Object();
         
         cc = Iso4217CurrencyCode.getInstance(obj);
         
         checkNumeric(cc);
         
         //
         // numeric
         //
         cc = new Iso4217CurrencyCode();
 
         checkNumeric(cc);
         
         cc = Iso4217CurrencyCode.getInstance(cc);
         
         checkNumeric(cc);
         
         obj = cc.toASN1Object();
         
         cc = Iso4217CurrencyCode.getInstance(obj);
         
         checkNumeric(cc);
         
         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());
    }
New to GrepCode? Check out our FAQ X