Skip to content

Instantly share code, notes, and snippets.

@samuelowino
Created December 2, 2020 19:35
Show Gist options
  • Select an option

  • Save samuelowino/722109ccc833dd1d2482b2258882c38f to your computer and use it in GitHub Desktop.

Select an option

Save samuelowino/722109ccc833dd1d2482b2258882c38f to your computer and use it in GitHub Desktop.
Unit Test for a Function that determines the date after a change in days. For instance 12 days from today or 14 days from now
@Test
public void rollTimeByDaysTest(){
//==================================
//TEST CASE 1
//==================================
System.out.println("Test case I");
DateTime dateTime = new DateTime(2020,12,14,0,0);
DateTime newDate = DateTimeUtils.rollBackByDayOfMonth(dateTime, 7);
System.out.println(" newDate " + DateTimeUtils.convertDateToString(newDate));
Assertions.assertEquals(8,newDate.dayOfMonth().get());
Assertions.assertEquals(12, newDate.monthOfYear().get());
//==================================
//TEST CASE 2
//==================================
System.out.println("Test case II");
DateTime dateTime2 = new DateTime(2020,12,2,0,0);
System.out.println("Date Time 2 " + DateTimeUtils.convertDateToString(dateTime2));
DateTime newDate2 = DateTimeUtils.rollBackByDayOfMonth(dateTime2, 7);
System.out.println(" newDate " + DateTimeUtils.convertDateToString(newDate2));
Assertions.assertEquals(26,newDate2.dayOfMonth().get());
Assertions.assertEquals(11, newDate2.monthOfYear().get());
//==================================
//TEST CASE 3
//==================================
System.out.println("Test case III");
DateTime dateTime3 = new DateTime(2020,12,7,0,0);
DateTime newDate3 = DateTimeUtils.rollBackByDayOfMonth(dateTime3, 7);
System.out.println(" newDate " + DateTimeUtils.convertDateToString(newDate3));
Assertions.assertEquals(1,newDate3.dayOfMonth().get());
Assertions.assertEquals(12, newDate3.monthOfYear().get());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment