|
1 | 1 | package com.somemore.location.service.query; |
2 | 2 |
|
| 3 | +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_LOCATION; |
3 | 4 | import static org.assertj.core.api.Assertions.assertThat; |
| 5 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
4 | 6 |
|
5 | 7 | import com.somemore.IntegrationTestSupport; |
| 8 | +import com.somemore.global.exception.BadRequestException; |
6 | 9 | import com.somemore.location.domain.Location; |
7 | 10 | import com.somemore.location.repository.LocationRepository; |
8 | 11 | import java.math.BigDecimal; |
9 | | -import java.util.Optional; |
10 | 12 | import org.junit.jupiter.api.AfterEach; |
11 | 13 | import org.junit.jupiter.api.BeforeEach; |
12 | 14 | import org.junit.jupiter.api.DisplayName; |
@@ -45,23 +47,24 @@ void findByIdWithExistsId() { |
45 | 47 | Long id = location.getId(); |
46 | 48 |
|
47 | 49 | // when |
48 | | - Optional<Location> findLocation = locationQueryService.findById(id); |
| 50 | + Location findLocation = locationQueryService.getById(id); |
49 | 51 |
|
50 | 52 | // then |
51 | | - assertThat(findLocation).isPresent(); |
| 53 | + assertThat(findLocation.getId()).isEqualTo(id); |
52 | 54 | } |
53 | 55 |
|
54 | | - @DisplayName("존재하지 않는 ID가 주어지면 빈 Optional 반환한다.") |
| 56 | + @DisplayName("존재하지 않는 ID가 주어지면 에러가 발생한다.") |
55 | 57 | @Test |
56 | 58 | void findByIdWithDoesNotExistId() { |
57 | 59 | // given |
58 | 60 | Long wrongId = 999L; |
59 | 61 |
|
60 | 62 | // when |
61 | | - Optional<Location> findLocation = locationQueryService.findById(wrongId); |
62 | | - |
63 | 63 | // then |
64 | | - assertThat(findLocation).isEmpty(); |
| 64 | + assertThatThrownBy( |
| 65 | + () -> locationQueryService.getById(wrongId) |
| 66 | + ).isInstanceOf(BadRequestException.class) |
| 67 | + .hasMessage(NOT_EXISTS_LOCATION.getMessage()); |
65 | 68 | } |
66 | 69 |
|
67 | 70 | } |
0 commit comments