Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,16 @@ public GroupModel setGroup(
final Group group = findGroup(directoryId, groupName);

if (group == null) {
if (groupModel == null) {
throw new GroupNotFoundException(groupName);
}
return createGroup(directoryId, groupModel);
}
Comment thread
pathob marked this conversation as resolved.

if (groupModel == null) {
return GroupModelUtil.toGroupModel(group);
}

return updateGroup(directoryId, groupName, groupModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,16 @@ UserModel setUser(
final User user = findUser(directoryId, username);

if (user == null) {
if (userModel == null) {
throw new UserNotFoundException(username);
}
return addUser(directoryId, username, userModel);
}
Comment thread
pathob marked this conversation as resolved.

if (userModel == null) {
return UserModelUtil.toUserModel(user);
}

return updateUser(directoryId, user.getName(), userModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@ public void testSetGroups() {
verify(spy, times(groupModels.size())).setGroup(anyLong(), any(), any());
}

@Test
public void testSetGroupNullModelAddNew() {
final Group group = getTestGroup();
assertThrows(GroupNotFoundException.class, () ->
groupsService.setGroup(group.getDirectoryId(), group.getName(), null));
}
Comment thread
pathob marked this conversation as resolved.

@Test
public void testSetGroupNullModelExisting() {
final Group group = getTestGroup();
final GroupsServiceImpl spy = spy(groupsService);
doReturn(group).when(spy).findGroup(group.getDirectoryId(), group.getName());

spy.setGroup(group.getDirectoryId(), group.getName(), null);
verify(spy, never()).createGroup(anyLong(), any());
verify(spy, never()).updateGroup(anyLong(), anyString(), any());
}

@Test
public void testSetGroupsNull() {
assertEquals(Collections.emptyMap(), groupsService.setGroups(0L, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ public void testSetUserWithMapKeyUsernameWhenModelUsernameIsNull() {
verify(spy).addUser(anyLong(), eq(user.getName()), any(UserModel.class));
}

@Test
public void testSetUserNullModelAddNew() {
final User user = getTestUser();
assertThrows(UserNotFoundException.class, () ->
usersService.setUser(user.getDirectoryId(), user.getName(), null));
}
Comment thread
pathob marked this conversation as resolved.

@Test
public void testSetUserNullModelExisting() throws CrowdException {
final User user = getTestUser();
final UsersServiceImpl spy = spy(usersService);
doReturn(user).when(spy).findUser(user.getDirectoryId(), user.getName());

spy.setUser(user.getDirectoryId(), user.getName(), null);
verify(spy, never()).addUser(anyLong(), anyString(), any());
verify(spy, never()).updateUser(anyLong(), anyString(), any());
}

@Test
public void testSetUsers() {
final User user = getTestUser();
Expand Down