public void testTruncate() throws SQLException { dayManager.truncate(); List<Day> days = dayManager.getAll(); Assert.assertNotNull(days); Assert.assertEquals(days.size(), 0); }
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 testDelete() throws SQLException { long dayId = 101L; Day day = new Day(); day.setId(dayId); dayManager.delete(day); Day dayAfterDelete = dayManager.get(dayId); Assert.assertNull(dayAfterDelete); }
public void testGetCachedDays() throws NoSuchFieldException, IllegalAccessException { Field cachedDaysField = DayManagerImpl.class.getDeclaredField("cachedDays"); cachedDaysField.setAccessible(true); cachedDaysField.set(dayManager, null); Assert.assertNull(dayManager.getCachedDays()); List<Day> days = dayManager.getAll(); List<Day> cachedDays = dayManager.getCachedDays(); Assert.assertNotNull(cachedDays); Assert.assertEquals(days.size(), cachedDays.size()); cachedDaysField.setAccessible(false); }
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); }
public void testGetAll() { List<Day> days = dayManager.getAll(); Assert.assertNotNull(days); Assert.assertEquals(days.size(), 1); }
public void testNotExists() throws SQLException { boolean dayExists = dayManager.exists(110L); Assert.assertFalse(dayExists); }
public void testExists() throws SQLException { boolean dayExists = dayManager.exists(101L); Assert.assertTrue(dayExists); }