DateUtil { public Date getDateFromNow(int days) { return getDateFromNow(days, 0, 0); }  Date getDateFromNow(int days); Date getDateFromNow(int days, int hours, int minutes); static String dateToString(Date date, String dateFromat); Date getDateFromGivenDate(Date date, int days, int hours,int minutes, int second); Date addTimeOffset(Date date, int mins); static Date getUTCDate(); static Date getUTCDate(long epoh); static Date getLocalDateForUTCDate(Date date); static Date stringToDate(String dateString, String dateFromat);  }
@Test @Ignore public void testGetDateFromNow() { int days = 1; Date dateCheck= dateUtil.getDateFromNow(days); int minutes=dateCheck.getMinutes(); int hourse=dateCheck.getHours(); Assert.assertEquals(dateCheck.getDay(),days+2); Assert.assertEquals(dateCheck.getMinutes(), minutes); Assert.assertEquals(dateCheck.getHours(), hourse); }
@Test public void testDateFromNow(){ int days = 2; int hours = 3; int minutes = 50; Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, days); cal.add(Calendar.HOUR, hours); cal.add(Calendar.MINUTE, minutes); Date expectedDate = cal.getTime(); Date actualDate = dateUtil.getDateFromNow(days, hours, minutes); Assert.assertEquals(expectedDate.getYear(), actualDate.getYear()); Assert.assertEquals(expectedDate.getDay(), actualDate.getDay()); Assert.assertEquals(expectedDate.getMonth(), actualDate.getMonth()); }