test/java/util/Currency/PropertiesTest.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -20,15 +20,16 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.*;
+import java.text.*;
import java.util.*;
import java.util.regex.*;
public class PropertiesTest {
- public static void main(String[] s) {
+ public static void main(String[] s) throws Exception {
for (int i = 0; i < s.length; i ++) {
if ("-d".equals(s[i])) {
i++;
if (i == s.length) {
throw new RuntimeException("-d needs output file name");
@@ -74,11 +75,11 @@
}
pw.flush();
pw.close();
}
- private static void compare(String beforeFile, String afterFile) {
+ private static void compare(String beforeFile, String afterFile) throws Exception {
// load file contents
Properties before = new Properties();
Properties after = new Properties();
try {
before.load(new FileReader(beforeFile));
@@ -115,12 +116,22 @@
keys = p.stringPropertyNames();
Pattern propertiesPattern =
Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*([0-3])");
for (String key: keys) {
String val = p.getProperty(key);
+ try {
+ if (countOccurrences(val, ',') == 3 && !isPastCutoverDate(val)) {
+ System.out.println("Skipping since date is in future");
+ continue; // skip since date in future (no effect)
+ }
+ } catch (ParseException pe) {
+ // swallow - currency class should not honour this value
+ continue;
+ }
String afterVal = after.getProperty(key);
System.out.printf("Testing key: %s, val: %s... ", key, val);
+ System.out.println("AfterVal is : " + afterVal);
Matcher m = propertiesPattern.matcher(val.toUpperCase(Locale.ROOT));
if (!m.find()) {
// format is not recognized.
System.out.printf("Format is not recognized.\n");
@@ -129,11 +140,10 @@
}
// ignore this
continue;
}
-
Matcher mAfter = propertiesPattern.matcher(afterVal);
mAfter.find();
String code = m.group(1);
String codeAfter = mAfter.group(1);
@@ -162,6 +172,31 @@
.append("\n");
}
throw new RuntimeException(sb.toString());
}
}
+
+ private static boolean isPastCutoverDate(String s)
+ throws IndexOutOfBoundsException, NullPointerException, ParseException {
+ String dateString = s.substring(s.lastIndexOf(',')+1, s.length()).trim();
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
+ format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ format.setLenient(false);
+
+ long time = format.parse(dateString).getTime();
+ if (System.currentTimeMillis() - time >= 0L) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private static int countOccurrences(String value, char match) {
+ int count = 0;
+ for (char c : value.toCharArray()) {
+ if (c == match) {
+ ++count;
+ }
+ }
+ return count;
+ }
}