### Question:
GenericHibernateDao { public E findById(ID id) { logger.trace("Finding " + entityClass.getSimpleName() + " with ID " + id); return getSession().get(entityClass, id); } @SuppressWarnings("unchecked")  GenericHibernateDao(); protected  GenericHibernateDao(Class<E> clazz); E findById(ID id); @SuppressWarnings("unchecked") List<E> findAllWhereFieldEquals(String fieldName, Object fieldEntity,
                                           Criterion... criterion); @SuppressWarnings("unchecked") List<E> findAllWithCollectionContaining(String fieldName, PersistentObject subElement,
                                                   Criterion... criterion); E loadById(ID id); List<E> findAll(); void saveOrUpdate(E e); void delete(E e); @SuppressWarnings("unchecked") E unproxy(E e); void evict(E e); @SuppressWarnings("unchecked") List<E> findByCriteria(Criterion... criterion); @SuppressWarnings("unchecked") List<E> findByCriteriaRestricted(List<String> restrictFieldNames, Criterion... criterion); @SuppressWarnings("unchecked") E findByUniqueCriteria(Criterion... criterion); @SuppressWarnings("unchecked") PagingResult<E> findByCriteriaWithSortingAndPaging(Integer firstResult,
                                                              Integer maxResults, List<Order> sorters, Criterion... criterion); @SuppressWarnings({"unchecked"}) Map<PersistentObject, PermissionCollection> findAllUserPermissionsOfUser(User user); @SuppressWarnings({"unchecked"}) Map<PersistentObject, PermissionCollection> findAllUserGroupPermissionsOfUserGroup(UserGroup userGroup); Number getTotalCount(Criterion... criterion); Class<E> getEntityClass();  }### Answer:
@Test public void findById_shouldReturnNullForNonExistingId() { Application app = appDao.findById(-90210); assertNull(app); }
@Test public void findById_shouldRetrieveApplication() { Application app = getRandomSavedMockApp(); Integer id = app.getId(); Application queriedApp = appDao.findById(id); assertNotNull(queriedApp); assertEquals(app, queriedApp); }
@Test public void findById_shouldRetrieveCorrectResults() { Application firstApp = getRandomSavedMockApp(); Application secondApp = getRandomSavedMockApp(); assertNotEquals(firstApp, secondApp); Integer firstId = firstApp.getId(); Integer secondId = secondApp.getId(); Application queriedFirst = appDao.findById(firstId); Application queriedSecond = appDao.findById(secondId); assertEquals(firstApp, queriedFirst); assertEquals(secondApp, queriedSecond); }