001/*
002 *  jDTAUS Banking Test Suite
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.banking.spi.it;
022
023import java.util.Currency;
024import java.util.Date;
025import junit.framework.Assert;
026import org.jdtaus.banking.it.CurrencyDirectoryTest;
027import org.jdtaus.banking.spi.CurrencyMapper;
028import org.jdtaus.banking.spi.UnsupportedCurrencyException;
029
030/**
031 * Testcase for {@code CurrencyMapper} implementations.
032 *
033 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
034 * @version $JDTAUS: CurrencyMapperTest.java 8661 2012-09-27 11:29:58Z schulte $
035 */
036public class CurrencyMapperTest extends CurrencyDirectoryTest
037{
038
039    /** Implementation to test. */
040    private CurrencyMapper mapper;
041
042    /**
043     * Gets the {@code CurrencyMapper} implementation tests are performed with.
044     *
045     * @return the {@code CurrencyMapper} implementation tests are performed with.
046     */
047    public CurrencyMapper getCurrencyMapper()
048    {
049        return this.mapper;
050    }
051
052    /**
053     * Sets the {@code CurrencyMapper} implementation tests are performed with.
054     *
055     * @param value the {@code CurrencyMapper} implementation to perform tests with.
056     */
057    public final void setCurrencyMapper( final CurrencyMapper value )
058    {
059        this.setCurrencyDirectory( value );
060        this.mapper = value;
061    }
062
063    /**
064     * Tests the {@link CurrencyMapper#getDtausCode(Currency,Date)} method to handle illegal arguments correctly and to
065     * return the {@code 1} DTAUS code for the {@code EUR} currency.
066     */
067    public void testGetDtausCode() throws Exception
068    {
069        assert this.getCurrencyMapper() != null;
070
071        try
072        {
073            this.getCurrencyMapper().getDtausCode( null, new Date() );
074            throw new AssertionError();
075        }
076        catch ( NullPointerException e )
077        {
078            Assert.assertNotNull( e.getMessage() );
079            System.out.println( e.toString() );
080        }
081
082        try
083        {
084            this.getCurrencyMapper().getDtausCode( Currency.getInstance( "EUR" ), null );
085            throw new AssertionError();
086        }
087        catch ( NullPointerException e )
088        {
089            Assert.assertNotNull( e.getMessage() );
090            System.out.println( e.toString() );
091        }
092
093        try
094        {
095            this.getCurrencyMapper().getDtausCode( Currency.getInstance( "DEM" ), new Date() );
096            throw new AssertionError();
097        }
098        catch ( UnsupportedCurrencyException e )
099        {
100            Assert.assertNotNull( e.getMessage() );
101            System.out.println( e.toString() );
102        }
103
104        Assert.assertTrue( this.getCurrencyMapper().getDtausCode( Currency.getInstance( "EUR" ), new Date() ) == '1' );
105    }
106
107    /**
108     * Tests the {@link CurrencyMapper#getDtausCurrency(char,Date)} method to handle illegal arguments correctly and to
109     * return the {@code EUR} currency for the {@code 1} DTAUS code.
110     */
111    public void testGetDtausCurrency() throws Exception
112    {
113        assert this.getCurrencyMapper() != null;
114
115        try
116        {
117            this.getCurrencyMapper().getDtausCurrency( '1', null );
118            throw new AssertionError();
119        }
120        catch ( NullPointerException e )
121        {
122            Assert.assertNotNull( e.getMessage() );
123            System.out.println( e.toString() );
124        }
125
126
127        Assert.assertEquals( this.getCurrencyMapper().getDtausCurrency( '1', new Date() ),
128                             Currency.getInstance( "EUR" ) );
129
130    }
131
132}