Add unit tests for DateUtils.toCalendar(Date, TimeZone)
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/ac5a216f Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/ac5a216f Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/ac5a216f Branch: refs/heads/master Commit: ac5a216f767c6defa4da720c6ecb3baa05e30254 Parents: 1eecfc9 Author: Kaiyuan Wang <wangkaiyua...@gmail.com> Authored: Tue Sep 20 23:59:04 2016 -0500 Committer: Kaiyuan Wang <wangkaiyua...@gmail.com> Committed: Tue Sep 20 23:59:04 2016 -0500 ---------------------------------------------------------------------- .../commons/lang3/time/DateUtilsTest.java | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/ac5a216f/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java index 0b80ab6..280d681 100644 --- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java @@ -693,6 +693,43 @@ public class DateUtilsTest { // expected } } + + //----------------------------------------------------------------------- + @Test + public void testToCalendarWithDate() { + assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date1, DateUtils.toCalendar(date1, zone).getTime()); + try { + DateUtils.toCalendar(null, zone); + fail("Expected NullPointerException to be thrown"); + } catch(final NullPointerException npe) { + // expected + } + } + + //----------------------------------------------------------------------- + @Test + public void testToCalendarWithTimeZone() { + assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", zone, DateUtils.toCalendar(date1, zone).getTimeZone()); + try { + DateUtils.toCalendar(date1, null); + fail("Expected NullPointerException to be thrown"); + } catch(final NullPointerException npe) { + // expected + } + } + + //----------------------------------------------------------------------- + @Test + public void testToCalendarWithDateAndTimeZone() { + try { + Calendar c = DateUtils.toCalendar(date2, defaultZone); + assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date2, c.getTime()); + assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", defaultZone, c.getTimeZone()); + // expected + } catch(final NullPointerException npe) { + fail("Expected NullPointerException to be thrown"); + } + } //----------------------------------------------------------------------- /**