diff options
author | Jay Shrauner <shrauner@google.com> | 2014-04-29 15:14:09 -0700 |
---|---|---|
committer | Jay Shrauner <shrauner@google.com> | 2014-04-30 12:25:42 -0700 |
commit | 2f369a47e14916a34f49c79c0a246a2e3ac3072f (patch) | |
tree | 1da786be374041fcdacc79eb3c0b2308a514097d /tests | |
parent | 8fbd758a9872b9ee9d1d978013cbec7efbe12d0c (diff) | |
download | android_packages_apps_Exchange-2f369a47e14916a34f49c79c0a246a2e3ac3072f.tar.gz android_packages_apps_Exchange-2f369a47e14916a34f49c79c0a246a2e3ac3072f.tar.bz2 android_packages_apps_Exchange-2f369a47e14916a34f49c79c0a246a2e3ac3072f.zip |
Date parser utility helpers throw parse exceptions
Update to reflect API change to parseDateTimeToMillis and
parseEmailDateTimeToMillis, which now throw ParseExceptions on
malformed date strings.
Bug:14279251
Change-Id: I74e015b81079b127ddba15f34c8b7e555099bd1e
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java index 4501bff1..68e57e0f 100644 --- a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java +++ b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java @@ -42,6 +42,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.StringReader; import java.text.DateFormat; +import java.text.ParseException; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -203,7 +204,7 @@ public class CalendarUtilitiesTests extends AndroidTestCase { assertNull(CalendarUtilities.tokenFromRrule(rrule, "UNTIL=")); } - public void testRecurrenceUntilToEasUntil() { + public void testRecurrenceUntilToEasUntil() throws ParseException { TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); // Case where local time crosses into next day in GMT assertEquals("20110730T000000Z", @@ -211,9 +212,18 @@ public class CalendarUtilitiesTests extends AndroidTestCase { // Case where local time does not cross into next day in GMT assertEquals("20110730T000000Z", CalendarUtilities.recurrenceUntilToEasUntil("20110730T235959Z")); + // Abbreviated date format + assertEquals("20110729T000000Z", + CalendarUtilities.recurrenceUntilToEasUntil("20110730")); + try { + CalendarUtilities.recurrenceUntilToEasUntil("201107"); + fail("Expected ParseException"); + } catch (ParseException e) { + // expected + } } - public void testParseEmailDateTimeToMillis(String date) { + public void testParseEmailDateTimeToMillis(String date) throws ParseException { // Format for email date strings is 2010-02-23T16:00:00.000Z String dateString = "2010-02-23T15:16:17.000Z"; long dateTime = Utility.parseEmailDateTimeToMillis(dateString); @@ -228,7 +238,7 @@ public class CalendarUtilitiesTests extends AndroidTestCase { assertEquals(cal.get(Calendar.SECOND), 17); } - public void testParseDateTimeToMillis(String date) { + public void testParseDateTimeToMillis(String date) throws ParseException { // Format for calendar date strings is 20100223T160000000Z String dateString = "20100223T151617000Z"; long dateTime = Utility.parseDateTimeToMillis(dateString); @@ -254,10 +264,14 @@ public class CalendarUtilitiesTests extends AndroidTestCase { // Fill in times, location, title, and organizer entityValues.put("DTSTAMP", CalendarUtilities.convertEmailDateTimeToCalendarDateTime("2010-04-05T14:30:51Z")); - entityValues.put(Events.DTSTART, - Utility.parseEmailDateTimeToMillis("2010-04-12T18:30:00Z")); - entityValues.put(Events.DTEND, - Utility.parseEmailDateTimeToMillis("2010-04-12T19:30:00Z")); + try { + entityValues.put(Events.DTSTART, + Utility.parseEmailDateTimeToMillis("2010-04-12T18:30:00Z")); + entityValues.put(Events.DTEND, + Utility.parseEmailDateTimeToMillis("2010-04-12T19:30:00Z")); + } catch (ParseException e) { + // ignore + } entityValues.put(Events.EVENT_LOCATION, location); entityValues.put(Events.TITLE, title); entityValues.put(Events.ORGANIZER, organizer); @@ -282,8 +296,12 @@ public class CalendarUtilitiesTests extends AndroidTestCase { ContentValues entityValues = entity.getEntityValues(); entityValues.put(Events.ORIGINAL_SYNC_ID, 69); // The exception will be on April 26th - entityValues.put(Events.ORIGINAL_INSTANCE_TIME, - Utility.parseEmailDateTimeToMillis("2010-04-26T18:30:00Z")); + try { + entityValues.put(Events.ORIGINAL_INSTANCE_TIME, + Utility.parseEmailDateTimeToMillis("2010-04-26T18:30:00Z")); + } catch (ParseException e) { + // ignore + } return entity; } @@ -540,7 +558,7 @@ public class CalendarUtilitiesTests extends AndroidTestCase { // Set up the "exception"... String title = "Discuss Unit Tests"; Entity entity = setupTestExceptionEntity(ORGANIZER, ATTENDEE, title); - + ContentValues entityValues = entity.getEntityValues(); // Mark the Exception as dirty entityValues.put(Events.DIRTY, 1); |