### Question:
ValidatorHibernateDao implements ValidatorDao<String> { @Override public boolean isExists(Class<? extends Entity> entity, String field, String param, boolean ignoreCase) { List<?> resultSet = getResultSet(entity, field, param, ignoreCase); if (resultSet.isEmpty()) { return false; } else if (resultSet.size() == 1 || !ignoreCase) { return true; } else { return !sessionFactory .getCurrentSession() .createCriteria(entity) .add(Restrictions.eq(field, param)) .setCacheable(true) .list() .isEmpty(); } } ValidatorHibernateDao(SessionFactory sessionFactory); @Override boolean isResultSetEmpty(Class<? extends Entity> entity, String field, 
            String param, boolean ignoreCase); @Override boolean isExists(Class<? extends Entity> entity, String field, 
            String param, boolean ignoreCase);  }### Answer:
@Test public void testIsExistsNoField() { assertFalse(dao.isExists(JCUser.class, "username", "lol", false)); }
@Test public void testIsExistsDifferentCases() { String realname = ObjectsFactory.getDefaultUser().getUsername().toUpperCase(); sessionFactory.getCurrentSession().saveOrUpdate(ObjectsFactory.getDefaultUser()); assertFalse(dao.isExists(JCUser.class, "username", realname, false)); }
@Test public void testIsExistsExistCaseSensitive() { String realname = ObjectsFactory.getDefaultUser().getUsername(); sessionFactory.getCurrentSession().saveOrUpdate(ObjectsFactory.getDefaultUser()); assertTrue(dao.isExists(JCUser.class, "username", realname, false)); }
@Test public void testIsExistsExistIgnoreCase() { String realname = ObjectsFactory.getDefaultUser().getUsername().toUpperCase(); sessionFactory.getCurrentSession().saveOrUpdate(ObjectsFactory.getDefaultUser()); assertTrue(dao.isExists(JCUser.class, "username", realname, true)); }
@Test public void testIsExistsSameIgnoreCaseValuesNotExists() { sessionFactory.getCurrentSession().saveOrUpdate(ObjectsFactory.getUser("Username", "Username@mail.com")); sessionFactory.getCurrentSession().saveOrUpdate(ObjectsFactory.getUser("uSername", "uSername@mail.com")); assertFalse(dao.isExists(JCUser.class, "username", "USERNAME", true)); }
@Test public void testIsExistsSameIgnoreCaseValuesExists() { JCUser expectedUser = ObjectsFactory.getUser("Username", "Username@mail.com"); String expectedUsername = expectedUser.getUsername(); sessionFactory.getCurrentSession().saveOrUpdate(expectedUser); sessionFactory.getCurrentSession().saveOrUpdate(ObjectsFactory.getUser("uSername", "uSername@mail.com")); assertTrue(dao.isExists(JCUser.class, "username", expectedUsername, true)); }