1 /* |
1 /* |
2 * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
23 |
23 |
24 import java.io.*; |
24 import java.io.*; |
25 import java.text.*; |
25 import java.text.*; |
26 import java.util.*; |
26 import java.util.*; |
27 import java.util.regex.*; |
27 import java.util.regex.*; |
|
28 import java.util.stream.Collectors; |
28 |
29 |
29 public class PropertiesTest { |
30 public class PropertiesTest { |
30 public static void main(String[] args) throws Exception { |
31 public static void main(String[] args) throws Exception { |
31 if (args.length == 2 && args[0].equals("-d")) { |
32 if (args.length == 2 && args[0].equals("-d")) { |
32 dump(args[1]); |
33 dump(args[1]); |
33 } else if (args.length == 4 && args[0].equals("-c")) { |
34 } else if (args.length == 4 && args[0].equals("-c")) { |
34 compare(args[1], args[2], args[3]); |
35 compare(args[1], args[2], args[3]); |
|
36 } else if (args.length == 1 && args[0].equals("bug7102969")) { |
|
37 bug7102969(); |
|
38 } else if (args.length == 1 && args[0].equals("bug8157138")) { |
|
39 bug8157138(); |
35 } else { |
40 } else { |
36 System.err.println("Usage: java PropertiesTest -d <dumpfile>"); |
41 System.err.println("Usage: java PropertiesTest -d <dumpfile>"); |
37 System.err.println(" java PropertiesTest -c <beforedump> <afterdump> <propsfile>"); |
42 System.err.println(" java PropertiesTest -c <beforedump> <afterdump> <propsfile>"); |
|
43 System.err.println(" java PropertiesTest bug[JBS bug id number] e.g. bug7102969"); |
38 System.exit(-1); |
44 System.exit(-1); |
39 } |
45 } |
40 } |
46 } |
41 |
47 |
42 private static void dump(String outfile) { |
48 private static void dump(String outfile) { |
172 } |
178 } |
173 throw new RuntimeException(sb.toString()); |
179 throw new RuntimeException(sb.toString()); |
174 } |
180 } |
175 } |
181 } |
176 |
182 |
|
183 private static void bug7102969() { |
|
184 |
|
185 // check the correct overriding of special case entries |
|
186 Currency cur = Currency.getInstance(new Locale("", "JP")); |
|
187 if (!cur.getCurrencyCode().equals("ABC")) { |
|
188 throw new RuntimeException("[Expected: ABC as currency code of JP, found: " |
|
189 + cur.getCurrencyCode() + "]"); |
|
190 } |
|
191 |
|
192 /* check if the currency instance is returned by |
|
193 * getAvailableCurrencies() method |
|
194 */ |
|
195 if (!Currency.getAvailableCurrencies().contains(cur)) { |
|
196 throw new RuntimeException("[The Currency instance [" |
|
197 + cur.getCurrencyCode() + ", " |
|
198 + cur.getNumericCode() + ", " |
|
199 + cur.getDefaultFractionDigits() |
|
200 + "] is not available in the currencies list]"); |
|
201 } |
|
202 |
|
203 } |
|
204 |
|
205 private static void bug8157138() { |
|
206 |
|
207 /* check the currencies which exist only as a special case are |
|
208 * accessible i.e. it should not throw IllegalArgumentException |
|
209 */ |
|
210 try { |
|
211 Currency.getInstance("MAD"); |
|
212 } catch (IllegalArgumentException ex) { |
|
213 throw new RuntimeException("Test Failed: " |
|
214 + "special case currency instance MAD not found" |
|
215 + " via Currency.getInstance(\"MAD\")"); |
|
216 } |
|
217 |
|
218 try { |
|
219 Currency.getInstance("ABC"); |
|
220 } catch (IllegalArgumentException ex) { |
|
221 throw new RuntimeException("Test Failed: " |
|
222 + "special case currency instance ABC not found" |
|
223 + " via Currency.getInstance(\"ABC\")"); |
|
224 } |
|
225 |
|
226 /* check the currency value is returned by getAvailableCurrencies() |
|
227 * method |
|
228 */ |
|
229 List<Currency> list = Currency.getAvailableCurrencies().stream() |
|
230 .filter(cur -> cur.getCurrencyCode().equals("MAD")) |
|
231 .collect(Collectors.toList()); |
|
232 |
|
233 if (list.isEmpty()) { |
|
234 throw new RuntimeException("Test Failed: " |
|
235 + "special case currency instance MAD not found" |
|
236 + " in Currency.getAvailableCurrencies() list"); |
|
237 } |
|
238 |
|
239 list = Currency.getAvailableCurrencies().stream() |
|
240 .filter(cur -> cur.getCurrencyCode().equals("ABC")) |
|
241 .collect(Collectors.toList()); |
|
242 |
|
243 if (list.isEmpty()) { |
|
244 throw new RuntimeException("Test Failed: " |
|
245 + "special case currency instance ABC not found" |
|
246 + " in Currency.getAvailableCurrencies() list"); |
|
247 } |
|
248 |
|
249 } |
|
250 |
177 private static boolean isPastCutoverDate(String s) |
251 private static boolean isPastCutoverDate(String s) |
178 throws IndexOutOfBoundsException, NullPointerException, ParseException { |
252 throws IndexOutOfBoundsException, NullPointerException, ParseException { |
179 String dateString = s.substring(s.lastIndexOf(',')+1, s.length()).trim(); |
253 String dateString = s.substring(s.lastIndexOf(',')+1, s.length()).trim(); |
180 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT); |
254 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT); |
181 format.setTimeZone(TimeZone.getTimeZone("GMT")); |
255 format.setTimeZone(TimeZone.getTimeZone("GMT")); |