Skip to content

Commit 38795fb

Browse files
committed
test(location): Location 조회 수정 기능 리팩토링 테스트
1 parent 8609f23 commit 38795fb

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/test/java/com/somemore/location/service/query/LocationQueryServiceTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.somemore.location.service.query;
22

3+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_LOCATION;
34
import static org.assertj.core.api.Assertions.assertThat;
5+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
46

57
import com.somemore.IntegrationTestSupport;
8+
import com.somemore.global.exception.BadRequestException;
69
import com.somemore.location.domain.Location;
710
import com.somemore.location.repository.LocationRepository;
811
import java.math.BigDecimal;
9-
import java.util.Optional;
1012
import org.junit.jupiter.api.AfterEach;
1113
import org.junit.jupiter.api.BeforeEach;
1214
import org.junit.jupiter.api.DisplayName;
@@ -45,23 +47,24 @@ void findByIdWithExistsId() {
4547
Long id = location.getId();
4648

4749
// when
48-
Optional<Location> findLocation = locationQueryService.findById(id);
50+
Location findLocation = locationQueryService.getById(id);
4951

5052
// then
51-
assertThat(findLocation).isPresent();
53+
assertThat(findLocation.getId()).isEqualTo(id);
5254
}
5355

54-
@DisplayName("존재하지 않는 ID가 주어지면 빈 Optional 반환한다.")
56+
@DisplayName("존재하지 않는 ID가 주어지면 에러가 발생한다.")
5557
@Test
5658
void findByIdWithDoesNotExistId() {
5759
// given
5860
Long wrongId = 999L;
5961

6062
// when
61-
Optional<Location> findLocation = locationQueryService.findById(wrongId);
62-
6363
// then
64-
assertThat(findLocation).isEmpty();
64+
assertThatThrownBy(
65+
() -> locationQueryService.getById(wrongId)
66+
).isInstanceOf(BadRequestException.class)
67+
.hasMessage(NOT_EXISTS_LOCATION.getMessage());
6568
}
6669

6770
}

0 commit comments

Comments
 (0)