ChatAlyticsDAOImpl extends AbstractIdleService implements IChatAlyticsDAO { @Override public DateTime getLastMessagePullTime() { String query = String.format("FROM %s", LastPullTime.class.getSimpleName()); EntityManager entityManager = entityManagerFactory.createEntityManager(); try { List<LastPullTime> result = entityManager.createQuery(query, LastPullTime.class) .getResultList(); if (result == null || result.size() == 0) { return new DateTime(0).withZone(DateTimeZone.UTC); } return result.get(0).getTime(); } finally { entityManager.close(); } } ChatAlyticsDAOImpl(EntityManagerFactory entityManagerFactory); @Override DateTime getLastMessagePullTime(); @Override void setLastMessagePullTime(DateTime time);  }
@Test public void testGetLastMessagePullTime() { DateTime expectedDate = new DateTime(0).withZone(DateTimeZone.UTC); assertEquals(expectedDate, underTest.getLastMessagePullTime()); expectedDate = expectedDate.plusHours(1); underTest.setLastMessagePullTime(expectedDate); assertEquals(expectedDate, underTest.getLastMessagePullTime()); }