// TODO add a feature you would like to see in the subscriptionPeriod class and write a test for // it here. @Test public void testTotalYears() { SubscriptionPeriod subscriptionPeriod = new SubscriptionPeriod(now.getTime(), twoYearsFromNow.getTime()); int totalYears = subscriptionPeriod.getTotalYears(); long differenceInYears = differenceInYears(now, twoYearsFromNow); assertEquals(totalYears, differenceInYears); }
/** TODO Currently, this test fails, it is your job to make it pass. */ @Test public void testTotalDays() { SubscriptionPeriod subscriptionPeriod = new SubscriptionPeriod(now.getTime(), sixthMonthsFromNow.getTime()); int totalDays = subscriptionPeriod.getTotalDays(); long differenceInDays = (sixthMonthsFromNow.getTime().getTime() - now.getTime().getTime()) / (1000 * 60 * 60 * 24); assertEquals(totalDays, differenceInDays); }
/** TODO Currently, this test fails, it is your job to make it pass. */ @Test public void testTotalMonths() { SubscriptionPeriod subscriptionPeriod = new SubscriptionPeriod(now.getTime(), sixthMonthsFromNow.getTime()); int totalMonths; totalMonths = subscriptionPeriod.getTotalMonths(); long differenceInMonth = differenceInMonths(now, sixthMonthsFromNow); assertEquals(totalMonths, differenceInMonth); }
@Test public void testConstruction() { // The basic anatomy of a test is this: // create a known state - this is done for us already in the setup method // change the state, in this case create a new object SubscriptionPeriod subscriptionPeriod = new SubscriptionPeriod(now.getTime(), sixthMonthsFromNow.getTime()); // verify (assert) the change did what we expect assertEquals("start date", now.getTime(), subscriptionPeriod.getStartDate()); assertEquals("end date", sixthMonthsFromNow.getTime(), subscriptionPeriod.getEndDate()); }