UserDaoImpl implements UserDao { @Override @Transactional public void deleteUser(User user) { getSession().delete(user); }  @Autowired void setSessionFactory(SessionFactory sessionFactory); @Override @Transactional int getNumberOfUsers(); @SuppressWarnings("unchecked") @Override @Transactional List<Integer> getAllUserIds(); @Override @Transactional List<Integer> getAllUserIdsInRange(final int firstResult,
      final int maxResults); @Override @Transactional long getNumberOfStaleUsers(Date lastAccessTime); @Override @Transactional List<Integer> getStaleUserIdsInRange(final Date lastAccessTime, final int firstResult, final int maxResults); @Override @Transactional User getUserForId(int id); @Transactional @Override void saveOrUpdateUser(User user); @Override void saveOrUpdateUsers(User... users); @Override @Transactional void deleteUser(User user); @Override @Transactional int getNumberOfUserRoles(); @Override @Transactional int getNumberOfUsersWithRole(UserRole role); @Override @Transactional UserRole getUserRoleForName(String name); @Override @Transactional void saveOrUpdateUserRole(UserRole userRole); @SuppressWarnings("unchecked") @Override @Transactional List<String> getUserIndexKeyValuesForKeyType(String keyType); @Override @Transactional Integer getUserKeyCount(final String keyType); @Override @Transactional List<User> getUsersForKeyType(final int start, final int maxResults, final String keyType); @Transactional @Override UserIndex getUserIndexForId(UserIndexKey key); @Override void saveOrUpdateUserIndex(UserIndex userIndex); @Override @Transactional void deleteUserIndex(UserIndex index);  }
@Test @Transactional public void deleteUser() { UserRole userRole = new UserRole("user"); _dao.saveOrUpdateUserRole(userRole); User user = new User(); user.setCreationTime(new Date()); user.setProperties(new UserPropertiesV2()); user.getRoles().add(userRole); UserIndexKey key = new UserIndexKey("phone", "2065551234"); UserIndex index = new UserIndex(); index.setId(key); index.setUser(user); user.getUserIndices().add(index); _dao.saveOrUpdateUser(user); assertEquals(1, _dao.getNumberOfUsers()); UserIndex index2 = _dao.getUserIndexForId(key); assertEquals(key, index2.getId()); assertEquals(user, index2.getUser()); _dao.deleteUser(user); assertEquals(0, _dao.getNumberOfUsers()); index2 = _dao.getUserIndexForId(key); assertNull(index2); }