diff options
author | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-10-11 00:37:48 -0700 |
---|---|---|
committer | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-10-11 00:37:48 -0700 |
commit | 43c3bb921682277d87d672f2af8264c4914e6d87 (patch) | |
tree | c9b6d1b39bd734287cbf2a0cd21ee475a047f596 | |
parent | 91f8bc6379bf5535710a9adea9a2faf061e1b401 (diff) | |
parent | d33874dcc620cc3a51beb6d3130d239706b27b09 (diff) |
Merge pull request #289 from Selvasundaram/master
DateUtilTest Junit test failures fixed
2 files changed, 17 insertions, 26 deletions
diff --git a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/DateUtilTest.java b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/DateUtilTest.java index 8b2fa2a1..c19b75d2 100644 --- a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/DateUtilTest.java +++ b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/DateUtilTest.java @@ -19,6 +19,9 @@ import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; * @version $Revision: 1.0 $ */ public class DateUtilTest { + + private Date date = DateUtil.getDate(2011, 9, 29, 11, 17, 38, 10); + /** * Run the String dateToString(Date) method test. * @@ -29,7 +32,6 @@ public class DateUtilTest { @Test public void testDateToString_1() throws Exception { - Date date = new Date(1317275258795L); String result = DateUtil.dateToString(date); assertEquals("09/29/2011 11:17:38", result); @@ -45,7 +47,6 @@ public class DateUtilTest { @Test public void testDateToString_2() throws Exception { - Date date = new Date(1317275258795L); String dateFormat = ""; String result = DateUtil.dateToString(date, dateFormat); @@ -62,7 +63,6 @@ public class DateUtilTest { @Test public void testDateToString_3() throws Exception { - Date date = new Date(1317275258795L); String dateFormat = CoreConstants.PURE_DATE_FORMAT; String result = DateUtil.dateToString(date, dateFormat); @@ -79,7 +79,7 @@ public class DateUtilTest { @Test public void testFormatDate_1() throws Exception { - String result = DateUtil.formatDate(new Date(1317275258795L)); + String result = DateUtil.formatDate(date); assertEquals("09/29/2011", result); } @@ -94,24 +94,9 @@ public class DateUtilTest { @Test public void testFormatDate_2() throws Exception { - String result = DateUtil.formatDate(new Date(0L)); - assertEquals("01/01/1970", result); - } - - /** - * Run the String formatDate(Date) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 9/27/11 12:31 PM - */ - @Test - public void testFormatDate_3() - throws Exception { - - String result = DateUtil.formatDate(new Date(-156784523000L)); + Date date1 = DateUtil.getDate(1965, 1, 12, 0, 0, 0, 0); + String result = DateUtil.formatDate(date1); assertEquals("01/12/1965", result); - } /** @@ -124,12 +109,10 @@ public class DateUtilTest { @Test public void testFormatTime_1() throws Exception { - Date inputDate = new Date(1317275258795L); - - String result = DateUtil.formatTime(inputDate); + String result = DateUtil.formatTime(date); // add additional test code here - assertEquals("11:17:38.795", result); + assertEquals("11:17:38.010", result); } /** @@ -171,7 +154,7 @@ public class DateUtilTest { throws Exception { String dateFormat = "MM/dd/yyyy"; String input = "09/29/2011"; // MM/dd/yyyy HH:mm:ss - Date expectedDate = new Date(1317234600000L); + Date expectedDate = DateUtil.getDate(2011, 9, 29, 0, 0, 0, 0); Date result = DateUtil.stringToDate(input, dateFormat); assertEquals(expectedDate, result); diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/DateUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/DateUtil.java index 8677fecd..5fd9ae8b 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/DateUtil.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/DateUtil.java @@ -20,6 +20,7 @@ package com.gluster.storage.management.core.utils; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import com.gluster.storage.management.core.constants.CoreConstants; @@ -108,4 +109,11 @@ public class DateUtil { public static final Date stringToDate(String input) { return stringToDate(input, CoreConstants.DATE_WITH_TIME_FORMAT); } + + public static final Date getDate(int year, int month, int day, int hour, int min, int sec, int msec) { + Calendar calendar = Calendar.getInstance(); + calendar.set(year, month-1, day, hour, min, sec); + calendar.set(Calendar.MILLISECOND, msec); + return calendar.getTime(); + } } |