8150324: java/util/Currency/CurrencyTest.java does not restore default TimeZone
Reviewed-by: okutsu, peytoia
Contributed-by: Nishit Jain <nishit.jain@oracle.com>
--- a/jdk/test/java/util/Currency/CurrencyTest.java Mon Apr 11 11:45:30 2016 -0700
+++ b/jdk/test/java/util/Currency/CurrencyTest.java Tue Apr 12 10:15:09 2016 +0900
@@ -23,7 +23,7 @@
/*
* @test
* @bug 4290801 4692419 4693631 5101540 5104960 6296410 6336600 6371531
- * 6488442 7036905 8008577 8039317 8074350 8074351
+ * 6488442 7036905 8008577 8039317 8074350 8074351 8150324
* @summary Basic tests for Currency class.
* @modules jdk.localedata
*/
@@ -32,12 +32,12 @@
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.util.Calendar;
-import java.util.Date;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
import java.util.Currency;
-import java.util.GregorianCalendar;
import java.util.Locale;
-import java.util.TimeZone;
public class CurrencyTest {
@@ -137,7 +137,7 @@
/*
* check currency changes
- * In current implementation, there is no data of old currency and transition date at jdk/src/share/classes/java/util/CurrencyData.properties.
+ * In current implementation, there is no data of old currency and transition date at jdk/make/data/currency/CurrencyData.properties.
* So, all the switch data arrays are empty. In the future, if data of old currency and transition date are necessary for any country, the
* arrays here can be updated so that the program can check the currency switch.
*/
@@ -146,15 +146,16 @@
String[] switchOverNew = {};
String[] switchOverTZ = {};
int[] switchOverYear = {};
- int[] switchOverMonth = {};
+ int[] switchOverMonth = {}; // java.time APIs accept month starting from 1 i.e. 01 for January
int[] switchOverDay = {};
for (int i = 0; i < switchOverCtry.length; i++) {
- TimeZone.setDefault(TimeZone.getTimeZone(switchOverTZ[i]));
- Calendar date = new GregorianCalendar(switchOverYear[i], switchOverMonth[i], switchOverDay[i]);
- long switchOver = date.getTime().getTime();
- boolean switchedOver = System.currentTimeMillis() >= switchOver;
- checkCountryCurrency(switchOverCtry[i], switchedOver ? switchOverNew[i] : switchOverOld[i]);
+ ZoneId zoneId = ZoneId.of(switchOverTZ[i]);
+ ZonedDateTime zonedDateAndTime = ZonedDateTime.of(LocalDate.of(switchOverYear[i], switchOverMonth[i], switchOverDay[i]),
+ LocalTime.MIDNIGHT, zoneId);
+ ZonedDateTime currentZonedDateAndTime = ZonedDateTime.now(zoneId);
+ checkCountryCurrency(switchOverCtry[i], (currentZonedDateAndTime.isAfter(zonedDateAndTime) ||
+ currentZonedDateAndTime.isEqual(zonedDateAndTime)) ? switchOverNew[i] : switchOverOld[i]);
}
// check a country code which doesn't have a currency