94 static final String otherCodes =
95 "ADP-AFA-ATS-AYM-BEF-BGL-BOV-BYB-CLF-CYP-DEM-ESP-FIM-FRF-GRD-GWP-IEP-ITL-LUF-MGF-MTL-MXV-NLG-PTE-RUR-SDD-SIT-SRG-TPE-TRL-VEF-USN-USS-XAG-XAU-XBA-XBB-XBC-XBD-XDR-XFO-XFU-XPD-XPT-XTS-XXX-YUM-ZWN";
96
97 static boolean err = false;
98
99 static Set<Currency> testCurrencies = new HashSet<Currency>();
100
101 public static void main(String[] args) throws Exception {
102 CheckDataVersion.check();
103 test1();
104 test2();
105 getAvailableCurrenciesTest();
106
107 if (err) {
108 throw new RuntimeException("Failed: Validation ISO 4217 data");
109 }
110 }
111
112 static void test1() throws Exception {
113
114 FileReader fr = new FileReader(new File(System.getProperty("test.src", "."), datafile));
115 BufferedReader in = new BufferedReader(fr);
116 String line;
117 SimpleDateFormat format = null;
118
119 while ((line = in.readLine()) != null) {
120 if (line.length() == 0 || line.charAt(0) == '#') {
121 continue;
122 }
123
124 StringTokenizer tokens = new StringTokenizer(line, "\t");
125 String country = tokens.nextToken();
126 if (country.length() != 2) {
127 continue;
128 }
129
130 String currency;
131 String numeric;
132 String minorUnit;
133 int tokensCount = tokens.countTokens();
134 if (tokensCount < 3) {
135 currency = "";
144 // check for the cutover
145 if (tokensCount > 3) {
146 if (format == null) {
147 format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
148 format.setTimeZone(TimeZone.getTimeZone("GMT"));
149 format.setLenient(false);
150 }
151 if (format.parse(tokens.nextToken()).getTime() <
152 System.currentTimeMillis()) {
153 currency = tokens.nextToken();
154 numeric = tokens.nextToken();
155 minorUnit = tokens.nextToken();
156 testCurrencies.add(Currency.getInstance(currency));
157 }
158 }
159 }
160 int index = toIndex(country);
161 testCountryCurrency(country, currency, Integer.parseInt(numeric),
162 Integer.parseInt(minorUnit), index);
163 }
164 in.close();
165
166 for (int i = 0; i < additionalCodes.length; i++) {
167 int index = toIndex(additionalCodes[i][0]);
168 if (additionalCodes[i][1].length() != 0) {
169 testCountryCurrency(additionalCodes[i][0], additionalCodes[i][1],
170 Integer.parseInt(additionalCodes[i][2]),
171 Integer.parseInt(additionalCodes[i][3]), index);
172 testCurrencies.add(Currency.getInstance(additionalCodes[i][1]));
173 } else {
174 codes[index] = SKIPPED;
175 }
176 }
177 }
178
179 static int toIndex(String s) {
180 return ((s.charAt(0) - 'A') * ALPHA_NUM + s.charAt(1) - 'A');
181 }
182
183 static void testCountryCurrency(String country, String currencyCode,
184 int numericCode, int digits, int index) {
|
94 static final String otherCodes =
95 "ADP-AFA-ATS-AYM-BEF-BGL-BOV-BYB-CLF-CYP-DEM-ESP-FIM-FRF-GRD-GWP-IEP-ITL-LUF-MGF-MTL-MXV-NLG-PTE-RUR-SDD-SIT-SRG-TPE-TRL-VEF-USN-USS-XAG-XAU-XBA-XBB-XBC-XBD-XDR-XFO-XFU-XPD-XPT-XTS-XXX-YUM-ZWN";
96
97 static boolean err = false;
98
99 static Set<Currency> testCurrencies = new HashSet<Currency>();
100
101 public static void main(String[] args) throws Exception {
102 CheckDataVersion.check();
103 test1();
104 test2();
105 getAvailableCurrenciesTest();
106
107 if (err) {
108 throw new RuntimeException("Failed: Validation ISO 4217 data");
109 }
110 }
111
112 static void test1() throws Exception {
113
114 try (FileReader fr = new FileReader(new File(System.getProperty("test.src", "."), datafile));
115 BufferedReader in = new BufferedReader(fr))
116 {
117 String line;
118 SimpleDateFormat format = null;
119
120 while ((line = in.readLine()) != null) {
121 if (line.length() == 0 || line.charAt(0) == '#') {
122 continue;
123 }
124
125 StringTokenizer tokens = new StringTokenizer(line, "\t");
126 String country = tokens.nextToken();
127 if (country.length() != 2) {
128 continue;
129 }
130
131 String currency;
132 String numeric;
133 String minorUnit;
134 int tokensCount = tokens.countTokens();
135 if (tokensCount < 3) {
136 currency = "";
145 // check for the cutover
146 if (tokensCount > 3) {
147 if (format == null) {
148 format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
149 format.setTimeZone(TimeZone.getTimeZone("GMT"));
150 format.setLenient(false);
151 }
152 if (format.parse(tokens.nextToken()).getTime() <
153 System.currentTimeMillis()) {
154 currency = tokens.nextToken();
155 numeric = tokens.nextToken();
156 minorUnit = tokens.nextToken();
157 testCurrencies.add(Currency.getInstance(currency));
158 }
159 }
160 }
161 int index = toIndex(country);
162 testCountryCurrency(country, currency, Integer.parseInt(numeric),
163 Integer.parseInt(minorUnit), index);
164 }
165 }
166
167 for (int i = 0; i < additionalCodes.length; i++) {
168 int index = toIndex(additionalCodes[i][0]);
169 if (additionalCodes[i][1].length() != 0) {
170 testCountryCurrency(additionalCodes[i][0], additionalCodes[i][1],
171 Integer.parseInt(additionalCodes[i][2]),
172 Integer.parseInt(additionalCodes[i][3]), index);
173 testCurrencies.add(Currency.getInstance(additionalCodes[i][1]));
174 } else {
175 codes[index] = SKIPPED;
176 }
177 }
178 }
179
180 static int toIndex(String s) {
181 return ((s.charAt(0) - 'A') * ALPHA_NUM + s.charAt(1) - 'A');
182 }
183
184 static void testCountryCurrency(String country, String currencyCode,
185 int numericCode, int digits, int index) {
|