Handle Benedikt Ritter's comments

Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/d9a2c69a
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/d9a2c69a
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/d9a2c69a

Branch: refs/heads/master
Commit: d9a2c69a9d1db6072e1d7b7ea4fcbd5c15d20b5d
Parents: ac5a216
Author: Kaiyuan Wang <wangkaiyua...@gmail.com>
Authored: Sat Sep 24 10:01:41 2016 -0500
Committer: Kaiyuan Wang <wangkaiyua...@gmail.com>
Committed: Sat Sep 24 10:01:41 2016 -0500

----------------------------------------------------------------------
 .../apache/commons/lang3/time/DateUtils.java    |  5 ++-
 .../commons/lang3/time/DateUtilsTest.java       | 40 ++++++++++++++------
 2 files changed, 31 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/d9a2c69a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java 
b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
index e9ae23f..8349c25 100644
--- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
@@ -670,8 +670,9 @@ public class DateUtils {
     /**
      * Converts a {@code Date} of a given {@code TimeZone} into a {@code 
Calendar}
      * @param date the date to convert to a Calendar
-     * @param timeZone the time zone of the @{code date}
-     * @return
+     * @param tz the time zone of the @{code date}
+     * @return the created Calendar
+     * @throws NullPointerException if {@code date} or {@code tz} is null
      */
     public static Calendar toCalendar(final Date date, final TimeZone tz) {
        final Calendar c = Calendar.getInstance(tz);

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/d9a2c69a/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 280d681..d4d1917 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
@@ -696,11 +696,16 @@ public class DateUtilsTest {
     
     //-----------------------------------------------------------------------
     @Test
-    public void testToCalendarWithDate() {
+    public void testToCalendarWithDateNotNull() {
         assertEquals("Convert Date and TimeZone to a Calendar, but failed to 
get the Date back", date1, DateUtils.toCalendar(date1, zone).getTime());
+    }
+    
+    //-----------------------------------------------------------------------
+    @Test
+    public void testToCalendarWithDateNull() {
         try {
             DateUtils.toCalendar(null, zone);
-            fail("Expected NullPointerException to be thrown");
+            fail("Expected NullPointerException to be thrown when Date is 
null");
         } catch(final NullPointerException npe) {
             // expected
         }
@@ -708,26 +713,37 @@ public class DateUtilsTest {
     
     //-----------------------------------------------------------------------
     @Test
-    public void testToCalendarWithTimeZone() {
+    public void testToCalendarWithTimeZoneNotNull() {
        assertEquals("Convert Date and TimeZone to a Calendar, but failed to 
get the TimeZone back", zone, DateUtils.toCalendar(date1, zone).getTimeZone());
+    }
+    
+    //-----------------------------------------------------------------------
+    @Test
+    public void testToCalendarWithTimeZoneNull() {
         try {
             DateUtils.toCalendar(date1, null);
-            fail("Expected NullPointerException to be thrown");
+            fail("Expected NullPointerException to be thrown when TimeZone is 
null");
         } 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
+    public void testToCalendarWithDateAndTimeZoneNotNull() {
+       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());
+    }
+    
+    //-----------------------------------------------------------------------
+    @Test
+    public void testToCalendarWithDateAndTimeZoneNull() {
+       try {
+               DateUtils.toCalendar(null, null);
+            fail("Expected NullPointerException to be thrown when both Date 
and TimeZone are null");
         } catch(final NullPointerException npe) {
-               fail("Expected NullPointerException to be thrown");
+            // expected
         }
     }
 

Reply via email to