UserServiceImpl implements UserService { @Transactional(readOnly = true) public UserDepartment getUserDepartment(Integer departmentId) throws ObjectNotFoundException { UserDepartment userDepartment = userDepartmentDAO.findById(departmentId); if (userDepartment == null) { throw new ObjectNotFoundException("Department not found"); } userDepartment.setDeletable(userDepartment.isWithoutUsers()); return userDepartment; }  @Transactional(readOnly = true) User getUser(Integer userId); @Transactional(readOnly = true) User getUserAndCheckDeletability(Integer userId); @Transactional(readOnly = true) User getUser(String username); @Transactional(readOnly = true) List<UserDepartment> getUserDepartments(); @Transactional UserDepartment persistUserDepartment(UserDepartment department); @Transactional(readOnly = true) UserDepartment getUserDepartment(Integer departmentId); @Transactional(readOnly = true) List<User> getUsers(); @Transactional(readOnly = true) List<User> getActiveUsers(); @Transactional(readOnly = true) List<UserRole> getUserRoles(); @Transactional User persistEditedUser(User user); @Override @Transactional void persistNewUser(User user, String password); @Override @Transactional void changePassword(String username, String currentPassword, String newUnencryptedPassword); @Override @Transactional void changePassword(String username, String newUnencryptedPassword); List<User> getUsersWithEmailSet(); @Override @Transactional User validateProjectManagementRoles(Integer userId); @Override @Transactional(readOnly = true) List<User> getUsers(UserRole userRole); @Transactional void deleteUser(Integer userId); @Transactional void deleteDepartment(Integer departmentId); void setPasswordEncoder(MessageDigestPasswordEncoder passwordEncoder); void setProjectAssignmentManagementService(ProjectAssignmentManagementService projectAssignmentManagementService); void setUserDAO(UserDao dao); void setUserDepartmentDAO(UserDepartmentDao dao); void setUserRoleDAO(UserRoleDao dao);  }
@Test public void testGetUserDepartment() throws ObjectNotFoundException { UserDepartment ud; when(userDepartmentDAO.findById(1)) .thenReturn(new UserDepartment(1, "bla", "ble")); ud = userService.getUserDepartment(1); verify(userDepartmentDAO).findById(1); assertEquals("bla", ud.getName()); }