public UserGroupDto addMembership(String groupUuid, String userUuid) {
    try (DbSession dbSession = dbClient.openSession(false)) {
      UserDto userDto = findUserOrThrow(userUuid, dbSession);
      GroupDto groupDto = findNonDefaultGroupOrThrow(groupUuid, dbSession);
      UserGroupDto userGroupDto = new UserGroupDto().setGroupUuid(groupUuid).setUserUuid(userUuid);
      checkArgument(isNotInGroup(dbSession, groupUuid, userUuid), "User '%s' is already a member of group '%s'", userDto.getLogin(), groupDto.getName());
      userGroupDao.insert(dbSession, userGroupDto, groupDto.getName(), userDto.getLogin());
      dbSession.commit();
      return userGroupDto;
    }
  }
@Test
  public void addMembership_ifGroupAndUserFound_shouldAddMemberToGroup() {
    GroupDto groupDto = mockGroupDto();
    UserDto userDto = mockUserDto();

    UserGroupDto userGroupDto = groupMembershipService.addMembership(GROUP_A, USER_1);

    assertThat(userGroupDto.getGroupUuid()).isEqualTo(groupDto.getUuid());
    assertThat(userGroupDto.getUserUuid()).isEqualTo(userDto.getUuid());

    verify(userGroupDao).insert(dbSession, new UserGroupDto().setGroupUuid(GROUP_A).setUserUuid(USER_1), groupDto.getName(), userDto.getLogin());
    verify(dbSession).commit();
  }