public void testSave() throws SQLException { List<Day> daysBefore = dayManager.getAll(); Assert.assertEquals(daysBefore.size(), 1); Day day = new Day(); day.setId(100L); day.setName("Lunedì"); Calendar calendar = GregorianCalendar.getInstance(); calendar.set(Calendar.YEAR, 2014); calendar.set(Calendar.MONTH, Calendar.OCTOBER); calendar.set(Calendar.DAY_OF_MONTH, 27); calendar.set(Calendar.HOUR_OF_DAY, 9); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); day.setDayDate(calendar.getTime()); dayManager.save(day); List<Day> daysAfter = dayManager.getAll(); Assert.assertEquals(daysAfter.size(), 2); Day savedDay = dayManager.get(day.getId()); Assert.assertEquals(savedDay.getId(), day.getId()); Assert.assertEquals(savedDay.getName(), day.getName()); boolean areDatesEqual = DateUtils.truncatedEquals(savedDay.getDayDate(), calendar.getTime(), Calendar.SECOND); Assert.assertTrue(areDatesEqual); }
public void testGet() { long dayId = 101L; Day day = dayManager.get(dayId); Assert.assertNotNull(day); Assert.assertEquals(Long.valueOf(dayId), day.getId()); Assert.assertEquals("Sabato", day.getName()); Calendar calendar = GregorianCalendar.getInstance(); calendar.set(Calendar.YEAR, 2014); calendar.set(Calendar.MONTH, Calendar.OCTOBER); calendar.set(Calendar.DAY_OF_MONTH, 25); calendar.set(Calendar.HOUR_OF_DAY, 9); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); boolean areDatesEqual = DateUtils.truncatedEquals(day.getDayDate(), calendar.getTime(), Calendar.SECOND); Assert.assertTrue(areDatesEqual); }
private void doBeforeChecks() { List<Day> daysBefore = dayManager.getAll(); Assert.assertEquals(daysBefore.size(), 1); Day dayBefore = daysBefore.get(0); Assert.assertEquals(Long.valueOf(101L), dayBefore.getId()); Assert.assertEquals("Sabato", dayBefore.getName()); Calendar calendar = GregorianCalendar.getInstance(); calendar.set(Calendar.YEAR, 2014); calendar.set(Calendar.MONTH, Calendar.OCTOBER); calendar.set(Calendar.DAY_OF_MONTH, 25); calendar.set(Calendar.HOUR_OF_DAY, 9); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); boolean areDatesEqual = DateUtils.truncatedEquals(dayBefore.getDayDate(), calendar.getTime(), Calendar.SECOND); Assert.assertTrue(areDatesEqual); }