1 /*
2 * jDTAUS Banking Test Suite
3 * Copyright (C) 2005 Christian Schulte
4 * <cs@schulte.it>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21 package org.jdtaus.banking.spi.it;
22
23 import java.util.Currency;
24 import java.util.Date;
25 import junit.framework.Assert;
26 import org.jdtaus.banking.it.CurrencyDirectoryTest;
27 import org.jdtaus.banking.spi.CurrencyMapper;
28 import org.jdtaus.banking.spi.UnsupportedCurrencyException;
29
30 /**
31 * Testcase for {@code CurrencyMapper} implementations.
32 *
33 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
34 * @version $JDTAUS: CurrencyMapperTest.java 8661 2012-09-27 11:29:58Z schulte $
35 */
36 public class CurrencyMapperTest extends CurrencyDirectoryTest
37 {
38
39 /** Implementation to test. */
40 private CurrencyMapper mapper;
41
42 /**
43 * Gets the {@code CurrencyMapper} implementation tests are performed with.
44 *
45 * @return the {@code CurrencyMapper} implementation tests are performed with.
46 */
47 public CurrencyMapper getCurrencyMapper()
48 {
49 return this.mapper;
50 }
51
52 /**
53 * Sets the {@code CurrencyMapper} implementation tests are performed with.
54 *
55 * @param value the {@code CurrencyMapper} implementation to perform tests with.
56 */
57 public final void setCurrencyMapper( final CurrencyMapper value )
58 {
59 this.setCurrencyDirectory( value );
60 this.mapper = value;
61 }
62
63 /**
64 * Tests the {@link CurrencyMapper#getDtausCode(Currency,Date)} method to handle illegal arguments correctly and to
65 * return the {@code 1} DTAUS code for the {@code EUR} currency.
66 */
67 public void testGetDtausCode() throws Exception
68 {
69 assert this.getCurrencyMapper() != null;
70
71 try
72 {
73 this.getCurrencyMapper().getDtausCode( null, new Date() );
74 throw new AssertionError();
75 }
76 catch ( NullPointerException e )
77 {
78 Assert.assertNotNull( e.getMessage() );
79 System.out.println( e.toString() );
80 }
81
82 try
83 {
84 this.getCurrencyMapper().getDtausCode( Currency.getInstance( "EUR" ), null );
85 throw new AssertionError();
86 }
87 catch ( NullPointerException e )
88 {
89 Assert.assertNotNull( e.getMessage() );
90 System.out.println( e.toString() );
91 }
92
93 try
94 {
95 this.getCurrencyMapper().getDtausCode( Currency.getInstance( "DEM" ), new Date() );
96 throw new AssertionError();
97 }
98 catch ( UnsupportedCurrencyException e )
99 {
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 }