1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jdtaus.banking.it;
22
23 import java.util.Calendar;
24 import java.util.Currency;
25 import java.util.Date;
26 import junit.framework.Assert;
27 import junit.framework.TestCase;
28 import org.jdtaus.banking.CurrencyDirectory;
29
30
31
32
33
34
35
36 public class CurrencyDirectoryTest extends TestCase
37 {
38
39
40 private CurrencyDirectory directory;
41
42
43
44
45
46
47 public CurrencyDirectory getCurrencyDirectory()
48 {
49 return this.directory;
50 }
51
52
53
54
55
56
57 public final void setCurrencyDirectory( final CurrencyDirectory value )
58 {
59 this.directory = value;
60 }
61
62
63
64
65
66
67
68
69
70 protected void assertContainsCurrency( final Currency[] currencies, final String isoCode )
71 {
72 if ( currencies == null )
73 {
74 throw new NullPointerException( "currencies" );
75 }
76 if ( isoCode == null )
77 {
78 throw new NullPointerException( "isoCode" );
79 }
80
81 boolean contains = false;
82 for ( int i = currencies.length - 1; i >= 0; i-- )
83 {
84 if ( currencies[i].getCurrencyCode().equals( isoCode ) )
85 {
86 contains = true;
87 break;
88 }
89 }
90
91 if ( !contains )
92 {
93 throw new AssertionError( isoCode );
94 }
95 }
96
97
98
99
100
101
102
103
104
105 protected void assertNotContainsCurrency( final Currency[] currencies, final String isoCode )
106 {
107 if ( currencies == null )
108 {
109 throw new NullPointerException( "currencies" );
110 }
111 if ( isoCode == null )
112 {
113 throw new NullPointerException( "isoCode" );
114 }
115
116 boolean contains = false;
117 for ( int i = currencies.length - 1; i >= 0; i-- )
118 {
119 if ( currencies[i].getCurrencyCode().equals( isoCode ) )
120 {
121 contains = true;
122 break;
123 }
124 }
125
126 if ( contains )
127 {
128 throw new AssertionError( isoCode );
129 }
130 }
131
132
133
134
135
136 public void testGetDtausCurrenciesNull()
137 {
138 assert this.getCurrencyDirectory() != null;
139
140 try
141 {
142 this.getCurrencyDirectory().getDtausCurrencies( null );
143 throw new AssertionError();
144 }
145 catch ( NullPointerException e )
146 {
147 Assert.assertNotNull( e.getMessage() );
148 System.out.println( e.toString() );
149 }
150 }
151
152
153 public void testGetDtausCurrencies() throws Exception
154 {
155 assert this.getCurrencyDirectory() != null;
156 Assert.assertTrue( this.getCurrencyDirectory().getDtausCurrencies( new Date() ).length >= 0 );
157 }
158
159
160
161
162
163 public void testCurrencyConstraints() throws Exception
164 {
165 assert this.getCurrencyDirectory() != null;
166
167 final Calendar cal = Calendar.getInstance();
168 final Date now = cal.getTime();
169
170 cal.set( Calendar.YEAR, 2001 );
171 cal.set( Calendar.MONTH, 11 );
172 cal.set( Calendar.DAY_OF_MONTH, 31 );
173
174 final Date lastDayDEM = cal.getTime();
175
176 cal.set( Calendar.YEAR, 2002 );
177 cal.set( Calendar.MONTH, 0 );
178 cal.set( Calendar.DAY_OF_MONTH, 1 );
179
180 final Date firstDayEUR = cal.getTime();
181
182 this.assertContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( now ), "EUR" );
183 this.assertNotContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( now ), "DEM" );
184 this.assertNotContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( lastDayDEM ), "EUR" );
185 this.assertContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( lastDayDEM ), "DEM" );
186 this.assertContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( firstDayEUR ), "EUR" );
187 this.assertNotContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( firstDayEUR ), "DEM" );
188 }
189
190 }