OldDateFormatTest is flaky; improve its output.
Hopefully this will let us debug the flakiness.
Bug: 6838286
(cherry-pick of 47cc9f97b6c91463b58e80996d36337caae91693)
Change-Id: I5862da2cebec6ad09a466b74ee1cc37bd1c5ec97
diff --git a/luni/src/test/java/libcore/java/text/OldDateFormatTest.java b/luni/src/test/java/libcore/java/text/OldDateFormatTest.java
index f614d6f..6b3885c 100644
--- a/luni/src/test/java/libcore/java/text/OldDateFormatTest.java
+++ b/luni/src/test/java/libcore/java/text/OldDateFormatTest.java
@@ -203,7 +203,7 @@
/**
* java.text.DateFormat#parse(String)
*/
- public void test_parseLString() {
+ public void test_parseLString() throws Exception {
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US);
try {
@@ -338,35 +338,29 @@
try {
format.parse("January 31 1970 7:52:34 AM PST");
fail("ParseException was not thrown.");
- } catch(ParseException pe) {
- //expected
+ } catch (ParseException expected) {
}
try {
format.parse("January 31 1970");
fail("ParseException was not thrown.");
- } catch(ParseException pe) {
- //expected
+ } catch (ParseException expected) {
}
format = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US);
- try {
- Date date = format.parse(format.format(current).toString());
- assertEquals(current.getDate(), date.getDate());
- assertEquals(current.getDay(), date.getDay());
- assertEquals(current.getMonth(), date.getMonth());
- assertEquals(current.getYear(), date.getYear());
- assertEquals(current.getHours(), date.getHours());
- assertEquals(current.getMinutes(), date.getMinutes());
- } catch(ParseException pe) {
- fail("ParseException was thrown for current Date.");
+ String formatPattern = ((SimpleDateFormat) format).toPattern();
+ String formattedCurrent = format.format(current);
+ Date date = format.parse(formattedCurrent);
+ // Date has millisecond accuracy, but humans don't use time formats that precise.
+ if (date.getTime() / 1000 != current.getTime() / 1000) {
+ fail(date.getTime() + " != " + current.getTime() +
+ "; " + formatPattern + "; " + formattedCurrent);
}
try {
format.parse("January 16, 1970 8:03:52 PM CET");
fail("ParseException was not thrown.");
- } catch(ParseException pe) {
- //expected
+ } catch (ParseException expected) {
}
}