From 949cfe87e77fc78a6e31d7b11368ab6fbff78637 Mon Sep 17 00:00:00 2001 From: Srltas Date: Sun, 27 Oct 2024 15:59:44 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EB=82=B4=20=EB=8F=99=EB=84=A4=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20Controller=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../in/UserNeighborhoodControllerTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/java/com/srltas/runtogether/adapter/in/UserNeighborhoodControllerTest.java diff --git a/src/test/java/com/srltas/runtogether/adapter/in/UserNeighborhoodControllerTest.java b/src/test/java/com/srltas/runtogether/adapter/in/UserNeighborhoodControllerTest.java new file mode 100644 index 0000000..6dea519 --- /dev/null +++ b/src/test/java/com/srltas/runtogether/adapter/in/UserNeighborhoodControllerTest.java @@ -0,0 +1,49 @@ +package com.srltas.runtogether.adapter.in; + +import static com.srltas.runtogether.adapter.in.web.common.SessionAttribute.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; +import static org.mockito.BDDMockito.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import com.srltas.runtogether.adapter.in.web.dto.AddUserNeighborhoodRequest; +import com.srltas.runtogether.adapter.out.session.UserSessionDTO; +import com.srltas.runtogether.application.port.in.AddUserNeighborhood; +import com.srltas.runtogether.application.port.in.AddUserNeighborhoodCommand; + +import jakarta.servlet.http.HttpSession; + +@ExtendWith(MockitoExtension.class) +class UserNeighborhoodControllerTest { + + @Mock + private AddUserNeighborhood addUserNeighborhood; + + @Mock + HttpSession session; + + @InjectMocks + private UserNeighborhoodController userNeighborhoodController; + + @Test + @DisplayName("내 동네 등록 성공") + void testAddUserNeighborhoodSuccess() { + AddUserNeighborhoodRequest request = new AddUserNeighborhoodRequest(100); + UserSessionDTO userSessionDTO = new UserSessionDTO(1L, "user1"); + given(session.getAttribute(USER_SESSION)).willReturn(userSessionDTO); + + ResponseEntity response = userNeighborhoodController.addUserNeighborhood(request, session); + + assertThat(response.getStatusCode(), is(HttpStatus.CREATED)); + verify(addUserNeighborhood).addNeighborhood( + new AddUserNeighborhoodCommand(userSessionDTO.userId(), request.neighborhoodId())); + } +}