-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/test/java/com/srltas/runtogether/adapter/in/UserNeighborhoodControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Void> response = userNeighborhoodController.addUserNeighborhood(request, session); | ||
|
||
assertThat(response.getStatusCode(), is(HttpStatus.CREATED)); | ||
verify(addUserNeighborhood).addNeighborhood( | ||
new AddUserNeighborhoodCommand(userSessionDTO.userId(), request.neighborhoodId())); | ||
} | ||
} |