mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 10:41:06 +01:00
Mob review
This commit is contained in:
@@ -9,13 +9,13 @@ import sonia.scm.group.Group;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class GroupDto2GroupMapperTest {
|
||||
public class GroupDtoToGroupMapperTest {
|
||||
|
||||
@Test
|
||||
public void shouldMapAttributes() {
|
||||
GroupDto dto = new GroupDto();
|
||||
dto.setName("group");
|
||||
Group group = Mappers.getMapper(GroupDto2GroupMapper.class).groupDtoToGroup(dto);
|
||||
Group group = Mappers.getMapper(GroupDtoToGroupMapper.class).map(dto);
|
||||
assertEquals("group", group.getName());
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class GroupDto2GroupMapperTest {
|
||||
|
||||
dto.withEmbedded("members", asList(member1, member2));
|
||||
|
||||
Group group = Mappers.getMapper(GroupDto2GroupMapper.class).groupDtoToGroup(dto);
|
||||
Group group = Mappers.getMapper(GroupDtoToGroupMapper.class).map(dto);
|
||||
|
||||
assertEquals(2, group.getMembers().size());
|
||||
assertEquals("member1", group.getMembers().get(0));
|
||||
@@ -20,9 +20,9 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class Group2GroupDtoMapperTest {
|
||||
public class GroupToGroupDtoMapperTest {
|
||||
|
||||
private final Group2GroupDtoMapper mapper = Mappers.getMapper(Group2GroupDtoMapper.class);
|
||||
private final GroupToGroupDtoMapper mapper = Mappers.getMapper(GroupToGroupDtoMapper.class);
|
||||
private final UriInfo uriInfo = mock(UriInfo.class);
|
||||
private final Subject subject = mock(Subject.class);
|
||||
private final ThreadState subjectThreadState = new SubjectThreadState(subject);
|
||||
@@ -47,7 +47,7 @@ public class Group2GroupDtoMapperTest {
|
||||
public void shouldMapAttributes() {
|
||||
Group group = createDefaultGroup();
|
||||
|
||||
GroupDto groupDto = mapper.groupToGroupDto(group, uriInfo);
|
||||
GroupDto groupDto = mapper.map(group, uriInfo);
|
||||
|
||||
assertEquals("abc", groupDto.getName());
|
||||
assertEquals("abc", groupDto.getName());
|
||||
@@ -57,7 +57,7 @@ public class Group2GroupDtoMapperTest {
|
||||
public void shouldMapSelfLink() {
|
||||
Group group = createDefaultGroup();
|
||||
|
||||
GroupDto groupDto = mapper.groupToGroupDto(group, uriInfo);
|
||||
GroupDto groupDto = mapper.map(group, uriInfo);
|
||||
|
||||
assertEquals("expected self link", expectedBaseUri.resolve("abc").toString(), groupDto.getLinks().getLinkBy("self").get().getHref());
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class Group2GroupDtoMapperTest {
|
||||
Group group = createDefaultGroup();
|
||||
when(subject.isPermitted("group:modify:abc")).thenReturn(true);
|
||||
|
||||
GroupDto groupDto = mapper.groupToGroupDto(group, uriInfo);
|
||||
GroupDto groupDto = mapper.map(group, uriInfo);
|
||||
|
||||
assertEquals("expected update link", expectedBaseUri.resolve("abc").toString(), groupDto.getLinks().getLinkBy("update").get().getHref());
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class Group2GroupDtoMapperTest {
|
||||
Group group = createDefaultGroup();
|
||||
group.setMembers(IntStream.range(0, 10).mapToObj(n -> "user" + n).collect(toList()));
|
||||
|
||||
GroupDto groupDto = mapper.groupToGroupDto(group, uriInfo);
|
||||
GroupDto groupDto = mapper.map(group, uriInfo);
|
||||
|
||||
assertEquals(10, groupDto.getEmbedded().getItemsBy("members").size());
|
||||
MemberDto actualMember = (MemberDto) groupDto.getEmbedded().getItemsBy("members").iterator().next();
|
||||
@@ -46,9 +46,9 @@ public class GroupV2ResourceTest {
|
||||
@Mock
|
||||
private GroupManager groupManager;
|
||||
@InjectMocks
|
||||
GroupDto2GroupMapperImpl dtoToGroupMapper;
|
||||
GroupDtoToGroupMapperImpl dtoToGroupMapper;
|
||||
@InjectMocks
|
||||
Group2GroupDtoMapperImpl groupToDtoMapper;
|
||||
GroupToGroupDtoMapperImpl groupToDtoMapper;
|
||||
|
||||
ArgumentCaptor<Group> groupCaptor = ArgumentCaptor.forClass(Group.class);
|
||||
|
||||
|
||||
@@ -25,14 +25,14 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class UserCollection2DtoMapperTest {
|
||||
public class UserCollectionToDtoMapperTest {
|
||||
|
||||
private final UriInfo uriInfo = mock(UriInfo.class);
|
||||
private final User2UserDtoMapper userToDtoMapper = mock(User2UserDtoMapper.class);
|
||||
private final UserToUserDtoMapper userToDtoMapper = mock(UserToUserDtoMapper.class);
|
||||
private final Subject subject = mock(Subject.class);
|
||||
private final ThreadState subjectThreadState = new SubjectThreadState(subject);
|
||||
|
||||
private final UserCollection2DtoMapper mapper = new UserCollection2DtoMapper(userToDtoMapper);
|
||||
private final UserCollectionToDtoMapper mapper = new UserCollectionToDtoMapper(userToDtoMapper);
|
||||
|
||||
private URI expectedBaseUri;
|
||||
|
||||
@@ -14,12 +14,12 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
public class UserDto2UserMapperTest {
|
||||
public class UserDtoToUserMapperTest {
|
||||
|
||||
@Mock
|
||||
private PasswordService passwordService;
|
||||
@InjectMocks
|
||||
private UserDto2UserMapperImpl mapper;
|
||||
private UserDtoToUserMapperImpl mapper;
|
||||
|
||||
@Test
|
||||
public void shouldMapFields() {
|
||||
@@ -21,9 +21,9 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class User2UserDtoMapperTest {
|
||||
public class UserToUserDtoMapperTest {
|
||||
|
||||
private final User2UserDtoMapper mapper = Mappers.getMapper(User2UserDtoMapper.class);
|
||||
private final UserToUserDtoMapper mapper = Mappers.getMapper(UserToUserDtoMapper.class);
|
||||
private final UriInfo uriInfo = mock(UriInfo.class);
|
||||
private final Subject subject = mock(Subject.class);
|
||||
private final ThreadState subjectThreadState = new SubjectThreadState(subject);
|
||||
@@ -53,9 +53,9 @@ public class UserV2ResourceTest {
|
||||
@Mock
|
||||
private UserManager userManager;
|
||||
@InjectMocks
|
||||
UserDto2UserMapperImpl dtoToUserMapper;
|
||||
UserDtoToUserMapperImpl dtoToUserMapper;
|
||||
@InjectMocks
|
||||
User2UserDtoMapperImpl userToDtoMapper;
|
||||
UserToUserDtoMapperImpl userToDtoMapper;
|
||||
|
||||
ArgumentCaptor<User> userCaptor = ArgumentCaptor.forClass(User.class);
|
||||
|
||||
@@ -134,6 +134,20 @@ public class UserV2ResourceTest {
|
||||
assertEquals("encrypted123", createdUser.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailForMissingContent() throws URISyntaxException {
|
||||
MockHttpRequest request = MockHttpRequest
|
||||
.post("/" + UserV2Resource.USERS_PATH_V2)
|
||||
.contentType(VndMediaType.USER)
|
||||
.content(new byte[] {});
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
when(passwordService.encryptPassword("pwd123")).thenReturn("encrypted123");
|
||||
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
}
|
||||
|
||||
private User createDummyUser() {
|
||||
User user = new User();
|
||||
user.setName("Neo");
|
||||
|
||||
Reference in New Issue
Block a user