### Question:
SqlWorkspaceRepository extends WorkspaceRepository { @Override public void updateUserOnWorkspace(Workspace workspace, String userId, WorkspaceAccess workspaceAccess, User user) { checkNotNull(userId); if (!hasWritePermissions(workspace.getWorkspaceId(), user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have write access to workspace " + workspace.getWorkspaceId(), user, workspace.getWorkspaceId()); } SqlUser userToUpdate = (SqlUser) userRepository.findById(userId); Session session = sessionManager.getSession(); Transaction transaction = null; try { transaction = session.beginTransaction(); SqlWorkspace sqlWorkspace = (SqlWorkspace) session.byId(SqlWorkspace.class).load(workspace.getWorkspaceId()); List<SqlWorkspaceUser> sqlWorkspaceUsers = sqlWorkspace.getSqlWorkspaceUserList(); boolean updateUser = false; for (SqlWorkspaceUser sqlWorkspaceUser : sqlWorkspaceUsers) { if (sqlWorkspaceUser.getUser().getUserId().equals(userId)) { updateUser = true; sqlWorkspaceUser.setWorkspaceAccess(workspaceAccess); } } if (!updateUser) { SqlWorkspaceUser sqlWorkspaceUser = new SqlWorkspaceUser(); sqlWorkspaceUser.setWorkspaceAccess(WorkspaceAccess.WRITE); sqlWorkspaceUser.setUser(userToUpdate); sqlWorkspaceUser.setWorkspace(sqlWorkspace); sqlWorkspaceUsers.add(sqlWorkspaceUser); } session.update(sqlWorkspace); transaction.commit(); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } throw new RuntimeException(e); } } @Inject  SqlWorkspaceRepository(final SqlUserRepository userRepository, final HibernateSessionManager sessionManager,
                                  final Graph graph); @Override void delete(Workspace workspace, User user); @Override Workspace findById(String workspaceId, boolean includeHidden, User user); @Override Workspace add(String workspaceId, String title, User user); @Override Iterable<Workspace> findAllForUser(User user); @Override void setTitle(Workspace workspace, String title, User user); @Override List<WorkspaceUser> findUsersWithAccess(String workspaceId, User user); @Override List<WorkspaceEntity> findEntities(Workspace workspace, User user); @Override void softDeleteEntitiesFromWorkspace(Workspace workspace, List<String> entityIdsToDelete, User authUser); @Override void updateEntitiesOnWorkspace(Workspace workspace, Iterable<Update> updates, User user); @Override void deleteUserFromWorkspace(Workspace workspace, String userId, User user); @Override void updateUserOnWorkspace(Workspace workspace, String userId, WorkspaceAccess workspaceAccess, User user); @Override ClientApiWorkspaceDiff getDiff(Workspace workspace, User user, Locale locale, String timeZone); @Override boolean hasCommentPermissions(String workspaceId, User user); @Override boolean hasWritePermissions(String workspaceId, User user); @Override boolean hasReadPermissions(String workspaceId, User user);  }### Answer:
@Test(expected = LumifyAccessDeniedException.class) public void testUpdateUserOnWorkspace() throws Exception { SqlWorkspace sqlWorkspace = (SqlWorkspace) sqlWorkspaceRepository.add("test", testUser); sqlWorkspaceRepository.updateUserOnWorkspace(sqlWorkspace, testUser.getUserId(), WorkspaceAccess.WRITE, testUser); List<WorkspaceUser> workspaceUsers = sqlWorkspaceRepository.findUsersWithAccess(sqlWorkspace.getWorkspaceId(), testUser); assertTrue(workspaceUsers.size() == 1); assertEquals(workspaceUsers.get(0).getWorkspaceAccess(), WorkspaceAccess.WRITE); SqlUser testUser2 = (SqlUser) sqlUserRepository.addUser("456", "qwe", null, "", new String[0]); sqlWorkspaceRepository.updateUserOnWorkspace(sqlWorkspace, "2", WorkspaceAccess.READ, testUser2); workspaceUsers = sqlWorkspaceRepository.findUsersWithAccess(sqlWorkspace.getWorkspaceId(), testUser2); assertTrue(workspaceUsers.size() == 2); assertEquals(workspaceUsers.get(1).getWorkspaceAccess(), WorkspaceAccess.READ); sqlWorkspaceRepository.updateUserOnWorkspace(sqlWorkspace, "1", WorkspaceAccess.NONE, testUser); workspaceUsers = sqlWorkspaceRepository.findUsersWithAccess(sqlWorkspace.getWorkspaceId(), testUser); assertEquals(workspaceUsers.get(0).getWorkspaceAccess(), WorkspaceAccess.NONE); }