@Test public void testCalcRemainingDaysOfRental() { Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(2008, 10, 05); Date today = new Date(cal.getTimeInMillis()); cal.clear(); cal.set(2008, 10, 06); Date tomorrow = new Date(cal.getTimeInMillis()); Rental r = new Rental(u1, m1, 1); r.setRentalDate(today); int remaining = r.calcRemainingDaysOfRental(tomorrow); assertEquals(0, remaining); try { r.calcRemainingDaysOfRental(null); fail(); } catch (NullPointerException npe) { assertEquals("given date is not set!", npe.getMessage()); } }
public int calcRemainingDaysOfRental(Date date) { if (date == null) { throw new NullPointerException("given date is not set!"); } Long diff = ((rentalDate.getTime() - date.getTime()) / 86400000) + rentalDays; setRentalDays(Math.abs(diff.intValue())); return diff.intValue(); }
Rental { public int calcRemainingDaysOfRental(Date date) { if (date == null) { throw new NullPointerException("given date is not set!"); } Long diff = ((rentalDate.getTime() - date.getTime()) / 86400000) + rentalDays; setRentalDays(Math.abs(diff.intValue())); return diff.intValue(); } }
Rental { public int calcRemainingDaysOfRental(Date date) { if (date == null) { throw new NullPointerException("given date is not set!"); } Long diff = ((rentalDate.getTime() - date.getTime()) / 86400000) + rentalDays; setRentalDays(Math.abs(diff.intValue())); return diff.intValue(); } Rental(IUser aUser, Movie aMovie, int nofRentalDays); private  Rental(IUser aUser, Movie aMovie, int nofRentalDays, Date rentaldate); }
Rental { public int calcRemainingDaysOfRental(Date date) { if (date == null) { throw new NullPointerException("given date is not set!"); } Long diff = ((rentalDate.getTime() - date.getTime()) / 86400000) + rentalDays; setRentalDays(Math.abs(diff.intValue())); return diff.intValue(); } Rental(IUser aUser, Movie aMovie, int nofRentalDays); private  Rental(IUser aUser, Movie aMovie, int nofRentalDays, Date rentaldate); static Rental createRentalFromDb(IUser aUser, Movie aMovie, int nofRentalDays, Date rentalDate); int calcRemainingDaysOfRental(Date date); double getRentalFee(); int getId(); Movie getMovie(); IUser getUser(); Date getRentalDate(); int getRentalDays(); void setId(int anId); void setRentalDays(int nofRentalDays); @Override boolean equals(Object o); @Override int hashCode(); }
Rental { public int calcRemainingDaysOfRental(Date date) { if (date == null) { throw new NullPointerException("given date is not set!"); } Long diff = ((rentalDate.getTime() - date.getTime()) / 86400000) + rentalDays; setRentalDays(Math.abs(diff.intValue())); return diff.intValue(); } Rental(IUser aUser, Movie aMovie, int nofRentalDays); private  Rental(IUser aUser, Movie aMovie, int nofRentalDays, Date rentaldate); static Rental createRentalFromDb(IUser aUser, Movie aMovie, int nofRentalDays, Date rentalDate); int calcRemainingDaysOfRental(Date date); double getRentalFee(); int getId(); Movie getMovie(); IUser getUser(); Date getRentalDate(); int getRentalDays(); void setId(int anId); void setRentalDays(int nofRentalDays); @Override boolean equals(Object o); @Override int hashCode();  }