diff --git a/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java b/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java index a7e2171..965e33e 100644 --- a/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java +++ b/src/main/java/slvtwn/khu/toyouserver/common/SessionUserService.java @@ -1,7 +1,6 @@ package slvtwn.khu.toyouserver.common; import org.springframework.stereotype.Service; -import slvtwn.khu.toyouserver.application.UserService; import slvtwn.khu.toyouserver.domain.SessionUser; import slvtwn.khu.toyouserver.domain.User; import slvtwn.khu.toyouserver.exception.ToyouException; @@ -11,19 +10,17 @@ @Service public class SessionUserService { - private final SessionUserRepository sessionUserRepository; + private final SessionUserRepository sessionUserRepository; + private final UserRepository userRepository; - private final UserRepository userRepository; + public SessionUserService(SessionUserRepository sessionUserRepository, UserRepository userRepository) { + this.sessionUserRepository = sessionUserRepository; + this.userRepository = userRepository; + } - public SessionUserService(SessionUserRepository sessionUserRepository, UserRepository userRepository, - UserService userService) { - this.sessionUserRepository = sessionUserRepository; - this.userRepository = userRepository; - } - - public User findUserBySessionId(String sessionId) { - SessionUser bySessionId = sessionUserRepository.findBySessionId(sessionId); - return userRepository.findById(bySessionId.getUserId()) - .orElseThrow(() -> new ToyouException(ErrorType.USER_NOT_FOUND)); - } + public User findUserBySessionId(String sessionId) { + SessionUser bySessionId = sessionUserRepository.findBySessionId(sessionId); + return userRepository.findById(bySessionId.getUserId()) + .orElseThrow(() -> new ToyouException(ErrorType.USER_NOT_FOUND)); + } } diff --git a/src/test/java/slvtwn/khu/toyouserver/response/PageableDto.java b/src/test/java/slvtwn/khu/toyouserver/response/PageableDto.java deleted file mode 100644 index cff7b70..0000000 --- a/src/test/java/slvtwn/khu/toyouserver/response/PageableDto.java +++ /dev/null @@ -1,9 +0,0 @@ -package slvtwn.khu.toyouserver.response; - -import slvtwn.khu.toyouserver.common.PageInfoResponse; - -public record PageableDto( - Long id, - String name, - PageInfoResponse pageInfo) { -} diff --git a/src/test/java/slvtwn/khu/toyouserver/response/ResponseController.java b/src/test/java/slvtwn/khu/toyouserver/response/ResponseController.java deleted file mode 100644 index 57aeca2..0000000 --- a/src/test/java/slvtwn/khu/toyouserver/response/ResponseController.java +++ /dev/null @@ -1,19 +0,0 @@ -package slvtwn.khu.toyouserver.response; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RequestMapping("/test") -@RestController -public class ResponseController { - - private final ResponseService responseService; - - public ResponseController(ResponseService responseService) {this.responseService = responseService;} - - @GetMapping - public PageableDto health() { - return responseService.health(); - } -} diff --git a/src/test/java/slvtwn/khu/toyouserver/response/ResponseControllerTest.java b/src/test/java/slvtwn/khu/toyouserver/response/ResponseControllerTest.java deleted file mode 100644 index 86d09f7..0000000 --- a/src/test/java/slvtwn/khu/toyouserver/response/ResponseControllerTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package slvtwn.khu.toyouserver.response; - -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.web.servlet.MockMvc; -import slvtwn.khu.toyouserver.common.PageInfoResponse; - -@AutoConfigureMockMvc -@SpringBootTest -public class ResponseControllerTest { - - @Autowired - private MockMvc mockMvc; - - @MockBean - private ResponseService responseService; - - @DisplayName("서버 응답 테스트를 실행한다.") - @Test - public void 응답_테스트() throws Exception { - PageableDto expect = new PageableDto(1L, "test", PageInfoResponse.of(1, 1, 1)); - given(responseService.health()) - .willReturn(expect); - mockMvc.perform(get("/test")) - .andExpect(status().isOk()) - .andExpect(result -> { - String contentAsString = result.getResponse().getContentAsString(); - System.out.println(contentAsString); - }); - } -} \ No newline at end of file diff --git a/src/test/java/slvtwn/khu/toyouserver/response/ResponseService.java b/src/test/java/slvtwn/khu/toyouserver/response/ResponseService.java deleted file mode 100644 index e57fc07..0000000 --- a/src/test/java/slvtwn/khu/toyouserver/response/ResponseService.java +++ /dev/null @@ -1,13 +0,0 @@ -package slvtwn.khu.toyouserver.response; - -import org.springframework.stereotype.Service; -import slvtwn.khu.toyouserver.common.PageInfoResponse; - -@Service -public class ResponseService { - - public PageableDto health() { - PageInfoResponse pageInfo = PageInfoResponse.of(1, 1, 1); - return new PageableDto(1L, "health", pageInfo); - } -} diff --git a/src/test/java/slvtwn/khu/toyouserver/user/service/UserServiceTest.java b/src/test/java/slvtwn/khu/toyouserver/user/service/UserServiceTest.java deleted file mode 100644 index e3ec23a..0000000 --- a/src/test/java/slvtwn/khu/toyouserver/user/service/UserServiceTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package slvtwn.khu.toyouserver.user.service; - -import java.time.LocalDate; -import org.assertj.core.api.SoftAssertions; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; -import slvtwn.khu.toyouserver.application.UserService; -import slvtwn.khu.toyouserver.domain.User; -import slvtwn.khu.toyouserver.dto.UserResponse; -import slvtwn.khu.toyouserver.persistance.UserRepository; - -@SuppressWarnings("NonAsciiCharacters") -@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -@SpringBootTest -@Transactional -class UserServiceTest { - - @Autowired - private UserRepository userRepository; - @Autowired - private UserService userService; - - @Test - void 유저를_조회할_수_있다() { - // given - User user = new User("teo", LocalDate.now(), "introduction", "www.profile-picture.com"); - userRepository.save(user); - - // when - UserResponse found = userService.findUser(user.getId()); - - // then - SoftAssertions.assertSoftly(softly -> { - softly.assertThat(user.getId()).isEqualTo(found.id()); - softly.assertThat(user.getName()).isEqualTo(found.name()); - softly.assertThat(user.getProfilePicture()).isEqualTo(found.imageUrl()); - }); - } -}