Compute locale-specific expected date strings in test for JDK 9 compatibility

This commit is contained in:
Sean Owen 2016-05-23 07:18:48 -05:00
parent 2a5a62e373
commit c2eb20d976

View file

@ -22,6 +22,8 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
@ -212,25 +214,29 @@ public final class ParsedReaderResultTestCase extends Assert {
// UTC times
doTestResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
"DTEND:20080505T234555Z\r\nEND:VEVENT\r\nEND:VCALENDAR",
"foo\nMay 4, 2008 12:34:56 PM\nMay 5, 2008 11:45:55 PM",
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" + formatTime(2008, 5, 5, 23, 45, 55),
ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
"DTEND:20080505T234555Z\r\nEND:VEVENT", "foo\nMay 4, 2008 12:34:56 PM\nMay 5, 2008 11:45:55 PM",
"DTEND:20080505T234555Z\r\nEND:VEVENT", "foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" +
formatTime(2008, 5, 5, 23, 45, 55),
ParsedResultType.CALENDAR);
// Local times
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\n" +
"DTEND:20080505T234555\r\nEND:VEVENT", "foo\nMay 4, 2008 12:34:56 PM\nMay 5, 2008 11:45:55 PM",
"DTEND:20080505T234555\r\nEND:VEVENT", "foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" +
formatTime(2008, 5, 5, 23, 45, 55),
ParsedResultType.CALENDAR);
// Date only (all day event)
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\n" +
"DTEND:20080505\r\nEND:VEVENT", "foo\nMay 4, 2008\nMay 5, 2008", ParsedResultType.CALENDAR);
"DTEND:20080505\r\nEND:VEVENT", "foo\n" + formatDate(2008, 5, 4) + "\n" +
formatDate(2008, 5, 5),
ParsedResultType.CALENDAR);
// Start time only
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nEND:VEVENT",
"foo\nMay 4, 2008 12:34:56 PM", ParsedResultType.CALENDAR);
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\nEND:VEVENT",
"foo\nMay 4, 2008 12:34:56 PM", ParsedResultType.CALENDAR);
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\nEND:VEVENT",
"foo\nMay 4, 2008", ParsedResultType.CALENDAR);
"foo\n" + formatDate(2008, 5, 4), ParsedResultType.CALENDAR);
doTestResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT",
"BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedResultType.URI);
// Yeah, it's OK that this is thought of as maybe a URI as long as it's not CALENDAR
@ -241,6 +247,20 @@ public final class ParsedReaderResultTestCase extends Assert {
ParsedResultType.URI);
}
private static String formatDate(int year, int month, int day) {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, month - 1, day);
return DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).format(cal.getTime());
}
private static String formatTime(int year, int month, int day, int hour, int min, int sec) {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, month - 1, day, hour, min, sec);
return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US).format(cal.getTime());
}
@Test
public void testSMS() {
doTestResult("sms:+15551212", "+15551212", ParsedResultType.SMS);