### Question:
TopicHibernateDao extends GenericDao<Topic> implements TopicDao { @Override public Topic getLastUpdatedTopicInBranch(Branch branch) { String modificationDateProperty = "modificationDate"; DetachedCriteria topicMaxModificationDateCriteria = DetachedCriteria.forClass(Topic.class) .setProjection(Projections.max(modificationDateProperty)) .add(Restrictions.eq(BRANCH, branch)); @SuppressWarnings(UNCHECKED) List<Topic> topics = (List<Topic>) session() .createCriteria(Topic.class) .add(Restrictions.eq(BRANCH, branch)) .add(Property.forName(modificationDateProperty).eq(topicMaxModificationDateCriteria)) .list(); return topics.isEmpty() ? null : topics.get(0); } TopicHibernateDao(SessionFactory sessionFactory); @Override Page<Topic> getTopicsUpdatedSince(DateTime timeStamp, PageRequest pageRequest, JCUser user); @Override Page<Topic> getUnansweredTopics(PageRequest pageRequest, JCUser user); @Override Topic getLastUpdatedTopicInBranch(Branch branch); @Override Page<Topic> getTopics(Branch branch, PageRequest pageRequest); @Override int countTopics(Branch branch); @Override Collection<JCUser> getAllowedSubscribers(SubscriptionAwareEntity entity); @Override List<Long> getForbiddenBranchesIds(JCUser user); @Override List<Long> getAllowedBranchesIds(JCUser user);  }### Answer:
@Test public void testGetLastUpdatedTopicInBranch() { Topic firstTopic = PersistedObjectsFactory.getDefaultTopic(); Branch branch = firstTopic.getBranch(); Topic secondTopic = new Topic(firstTopic.getTopicStarter(), "Second topic", "Discussion"); branch.addTopic(secondTopic); Topic expectedLastUpdatedTopic = firstTopic; ReflectionTestUtils.setField( expectedLastUpdatedTopic, "modificationDate", new DateTime(2100, 12, 25, 0, 0, 0, 0)); session.save(branch); Topic actualLastUpdatedTopic = dao.getLastUpdatedTopicInBranch(branch); assertNotNull(actualLastUpdatedTopic, "Last updated topic is not found"); assertEquals(actualLastUpdatedTopic.getId(), expectedLastUpdatedTopic.getId(), "Found incorrect last updated topic"); }
@Test public void testGetLastUpdatedTopicInEmptyBranch() { Branch branch = ObjectsFactory.getDefaultBranch(); session.save(branch); assertNull(dao.getLastUpdatedTopicInBranch(branch), "The branch is empty, so the topic should not be found"); }