-
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.
- parameterized를 이용해 성공 케이스만 추가
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/test/java/com/srltas/runtogether/adapter/in/NeighborhoodVerificationControllerTest.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,65 @@ | ||
package com.srltas.runtogether.adapter.in; | ||
|
||
import static org.hamcrest.MatcherAssert.*; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.BDDMockito.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
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.NeighborhoodVerificationRequest; | ||
import com.srltas.runtogether.application.port.in.NeighborhoodVerificationCommand; | ||
import com.srltas.runtogether.application.port.in.NeighborhoodVerificationResponse; | ||
import com.srltas.runtogether.application.port.in.NeighborhoodVerificationUseCase; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class NeighborhoodVerificationControllerTest { | ||
|
||
@Mock | ||
private NeighborhoodVerificationUseCase neighborhoodVerificationUseCase; | ||
|
||
@InjectMocks | ||
private NeighborhoodVerificationController neighborhoodVerificationController; | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideNeighborhoodVerificationRequests") | ||
@DisplayName("verifyNeighborhood 메서드에 대한 Parameterized 테스트") | ||
void verifyNeighborhood_ShouldReturnOkResponse(NeighborhoodVerificationRequest request, Long userId) { | ||
// given | ||
NeighborhoodVerificationCommand command = new NeighborhoodVerificationCommand(request.latitude(), | ||
request.longitude(), request.neighborhoodId()); | ||
NeighborhoodVerificationResponse expectedResponse = new NeighborhoodVerificationResponse( | ||
UUID.randomUUID().toString(), true, LocalDateTime.now().toString()); | ||
|
||
given(neighborhoodVerificationUseCase.verifyAndRegisterNeighborhood(userId, command)).willReturn( | ||
expectedResponse); | ||
|
||
// when | ||
ResponseEntity<NeighborhoodVerificationResponse> response = neighborhoodVerificationController.verifyNeighborhood( | ||
request, userId); | ||
|
||
// then | ||
verify(neighborhoodVerificationUseCase).verifyAndRegisterNeighborhood(userId, command); | ||
assertThat(response.getStatusCode(), is(HttpStatus.OK)); | ||
assertThat(response.getBody(), is(expectedResponse)); | ||
} | ||
|
||
static Stream<Arguments> provideNeighborhoodVerificationRequests() { | ||
return Stream.of( | ||
Arguments.of(new NeighborhoodVerificationRequest(37.579617, 126.977041, 1), 100L), | ||
Arguments.of(new NeighborhoodVerificationRequest(37.556201, 126.972286, 2), 101L), | ||
Arguments.of(new NeighborhoodVerificationRequest(37.497911, 127.027618, 3), 102L)); | ||
} | ||
} |