Skip to content

Commit

Permalink
test: 친구 요청 목록 조회 Controller 테스트 코드 추가 (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeong-hyeok committed Sep 21, 2023
1 parent a47cd84 commit 0dfa5d0
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.project.mapdagu.domain.friendRequest.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.project.mapdagu.domain.friendRequest.dto.response.FriendRequestsGetResponseDto;
import com.project.mapdagu.domain.friendRequest.service.FriendRequestService;
import com.project.mapdagu.utils.TestUserArgumentResolver;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -9,18 +10,23 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.filter.CharacterEncodingFilter;

import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import java.util.ArrayList;
import java.util.List;

import static org.mockito.ArgumentMatchers.*;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -71,4 +77,23 @@ void setUp() {
verify(friendRequestService, times(1)).deleteFriendRequest(anyString(), anyLong());
}

@Test
void 친구_요청_목록_조회() throws Exception {
//given
PageRequest pageable = PageRequest.of(0, 2);
List<FriendRequestsGetResponseDto> dtos = new ArrayList<>();
dtos.add(new FriendRequestsGetResponseDto(1L, "테스트1", 3, 1));
dtos.add(new FriendRequestsGetResponseDto(2L, "테스트2", 5, 2));
Slice<FriendRequestsGetResponseDto> response = new SliceImpl<>(dtos, pageable, false);

//when
given(friendRequestService.getAllFriendRequest(anyString(), any())).willReturn(response);
ResultActions result = mockMvc.perform(
get("/api/friends/request")
);

//then
result.andExpect(status().isOk());
verify(friendRequestService, times(1)).getAllFriendRequest(anyString(), any());
}
}

0 comments on commit 0dfa5d0

Please sign in to comment.