Skip to content

Commit ffcc67a

Browse files
committed
refactor: 테스트 검증 로직 변경
1 parent ef1e316 commit ffcc67a

File tree

12 files changed

+104
-99
lines changed

12 files changed

+104
-99
lines changed

src/test/java/timeeat/domain/bookmark/BookmarkTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package timeeat.domain.bookmark;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
54
import static org.junit.jupiter.api.Assertions.assertAll;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
66

77
import java.time.LocalTime;
88

@@ -60,18 +60,18 @@ class CreateBookmark {
6060
null,
6161
"강남구");
6262

63-
assertThatThrownBy(() -> new Bookmark(null, store))
64-
.isInstanceOf(BusinessException.class)
65-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.BOOKMARK_MEMBER_REQUIRED);
63+
BusinessException exception = assertThrows(BusinessException.class, () -> new Bookmark(null, store));
64+
65+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.BOOKMARK_MEMBER_REQUIRED);
6666
}
6767

6868
@Test
6969
void 가게가_null이면_예외를_던진다() {
7070
Member member = new Member("socialId123");
7171

72-
assertThatThrownBy(() -> new Bookmark(member, null))
73-
.isInstanceOf(BusinessException.class)
74-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.BOOKMARK_STORE_REQUIRED);
72+
BusinessException exception = assertThrows(BusinessException.class, () -> new Bookmark(member, null));
73+
74+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.BOOKMARK_STORE_REQUIRED);
7575
}
7676
}
7777
}

src/test/java/timeeat/domain/member/MemberTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package timeeat.domain.member;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
54
import static org.junit.jupiter.api.Assertions.assertAll;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
66

77
import org.junit.jupiter.api.DisplayName;
88
import org.junit.jupiter.api.Nested;
@@ -37,9 +37,9 @@ class CreateOauthMember {
3737
void socialId가_null이면_예외가_발생한다() {
3838
String socialId = null;
3939

40-
assertThatThrownBy(() -> new Member(socialId))
41-
.isInstanceOf(BusinessException.class)
42-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_SOCIAL_ID);
40+
BusinessException exception = assertThrows(BusinessException.class, () -> new Member(socialId));
41+
42+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_SOCIAL_ID);
4343
}
4444
}
4545

@@ -91,9 +91,9 @@ class CreateMemberTest {
9191
String interestArea = "강남구";
9292
Boolean optInMarketing = null;
9393

94-
assertThatThrownBy(() -> new Member(socialId, nickname, mobilePhoneNumber, interestArea, optInMarketing))
95-
.isInstanceOf(BusinessException.class)
96-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MARKETING_CONSENT);
94+
BusinessException exception = assertThrows(BusinessException.class, () -> new Member(socialId, nickname, mobilePhoneNumber, interestArea, optInMarketing));
95+
96+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MARKETING_CONSENT);
9797
}
9898

9999
@Test
@@ -104,9 +104,9 @@ class CreateMemberTest {
104104
String interestArea = "부산";
105105
Boolean optInMarketing = true;
106106

107-
assertThatThrownBy(() -> new Member(socialId, nickname, mobilePhoneNumber, interestArea, optInMarketing))
108-
.isInstanceOf(BusinessException.class)
109-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_INTEREST_AREA);
107+
BusinessException exception = assertThrows(BusinessException.class, () -> new Member(socialId, nickname, mobilePhoneNumber, interestArea, optInMarketing));
108+
109+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_INTEREST_AREA);
110110
}
111111
}
112112
}

src/test/java/timeeat/domain/member/MobilePhoneNumberTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package timeeat.domain.member;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
55

66
import org.junit.jupiter.api.DisplayName;
77
import org.junit.jupiter.api.Nested;
@@ -39,9 +39,9 @@ class CreateMobilePhoneNumberTest {
3939
@ParameterizedTest
4040
@ValueSource(strings = {"0101234567", "010123456789", "010-1234-5678", "abcdefghijk"})
4141
void 번호_형식이_올바르지_않으면_예외를_던진다(String invalidNumber) {
42-
assertThatThrownBy(() -> new MobilePhoneNumber(invalidNumber))
43-
.isInstanceOf(BusinessException.class)
44-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MOBILE_PHONE_NUMBER);
42+
BusinessException exception = assertThrows(BusinessException.class, () -> new MobilePhoneNumber(invalidNumber));
43+
44+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MOBILE_PHONE_NUMBER);
4545
}
4646
}
4747
}

src/test/java/timeeat/domain/menu/DiscountTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package timeeat.domain.menu;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
55

66
import java.time.LocalDateTime;
77

@@ -52,37 +52,37 @@ class CreateDiscount {
5252
void 할인_가격이_원가보다_비싸면_예외를_던진다() {
5353
Integer invalidDiscountPrice = 12000;
5454

55-
assertThatThrownBy(() -> new Discount(originalPrice, invalidDiscountPrice, null, null))
56-
.isInstanceOf(BusinessException.class)
57-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MENU_DISCOUNT_PRICE);
55+
BusinessException exception = assertThrows(BusinessException.class, () -> new Discount(originalPrice, invalidDiscountPrice, null, null));
56+
57+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MENU_DISCOUNT_PRICE);
5858
}
5959

6060
@Test
6161
void 할인_가격이_원가와_같으면_예외를_던진다() {
6262
Integer sameDiscountPrice = 10000;
6363

64-
assertThatThrownBy(() -> new Discount(originalPrice, sameDiscountPrice, null, null))
65-
.isInstanceOf(BusinessException.class)
66-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MENU_DISCOUNT_PRICE);
64+
BusinessException exception = assertThrows(BusinessException.class, () -> new Discount(originalPrice, sameDiscountPrice, null, null));
65+
66+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MENU_DISCOUNT_PRICE);
6767
}
6868

6969
@Test
7070
void 할인_가격이_0원이면_예외를_던진다() {
7171
Integer zeroDiscountPrice = 0;
7272

73-
assertThatThrownBy(() -> new Discount(originalPrice, zeroDiscountPrice, null, null))
74-
.isInstanceOf(BusinessException.class)
75-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MENU_DISCOUNT_PRICE);
73+
BusinessException exception = assertThrows(BusinessException.class, () -> new Discount(originalPrice, zeroDiscountPrice, null, null));
74+
75+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MENU_DISCOUNT_PRICE);
7676
}
7777

7878
@Test
7979
void 시작_시간이_종료_시간보다_늦으면_예외를_던진다() {
8080
LocalDateTime startTime = LocalDateTime.now();
8181
LocalDateTime endTime = startTime.minusHours(2);
8282

83-
assertThatThrownBy(() -> new Discount(originalPrice, 8000, startTime, endTime))
84-
.isInstanceOf(BusinessException.class)
85-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MENU_DISCOUNT_TIME);
83+
BusinessException exception = assertThrows(BusinessException.class, () -> new Discount(originalPrice, 8000, startTime, endTime));
84+
85+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MENU_DISCOUNT_TIME);
8686
}
8787
}
8888
}

src/test/java/timeeat/domain/menu/MenuTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package timeeat.domain.menu;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
54
import static org.junit.jupiter.api.Assertions.assertAll;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
66

77
import java.time.LocalDateTime;
88

@@ -37,28 +37,31 @@ class CreateMenu {
3737

3838
@Test
3939
void 이름이_null이면_예외를_던진다() {
40-
assertThatThrownBy(() -> new Menu(null, "설명", 10000, "url", null, null, null))
41-
.isInstanceOf(BusinessException.class)
42-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MENU_NAME);
40+
BusinessException exception = assertThrows(BusinessException.class,
41+
() -> new Menu(null, "설명", 10000, "url", null, null, null));
42+
43+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MENU_NAME);
4344
}
4445

4546
@Test
4647
void 할인_가격이_원가보다_비싸면_예외를_던진다() {
4748
Integer price = 10000;
4849
Integer invalidDiscountPrice = 12000;
4950

50-
assertThatThrownBy(() -> new Menu("이름", "설명", price, "url", invalidDiscountPrice, null, null))
51-
.isInstanceOf(BusinessException.class)
52-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MENU_DISCOUNT_PRICE);
51+
BusinessException exception = assertThrows(BusinessException.class,
52+
() -> new Menu("이름", "설명", price, "url", invalidDiscountPrice, null, null));
53+
54+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MENU_DISCOUNT_PRICE);
5355
}
5456

5557
@Test
5658
void 이름이_최대_길이를_초과하면_예외를_던진다() {
5759
String overflowName = "t".repeat(255 + 1);
5860

59-
assertThatThrownBy(() -> new Menu(overflowName, "설명", 10000, "url", null, null, null))
60-
.isInstanceOf(BusinessException.class)
61-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MENU_LENGTH);
61+
BusinessException exception = assertThrows(BusinessException.class,
62+
() -> new Menu(overflowName, "설명", 10000, "url", null, null, null));
63+
64+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MENU_LENGTH);
6265
}
6366
}
6467
}

src/test/java/timeeat/domain/menu/PriceTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package timeeat.domain.menu;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
55

66
import org.junit.jupiter.api.DisplayName;
77
import org.junit.jupiter.api.Nested;
@@ -27,16 +27,14 @@ class CreatePrice {
2727

2828
@Test
2929
void 가격이_null이면_예외를_던진다() {
30-
assertThatThrownBy(() -> new Price(null))
31-
.isInstanceOf(BusinessException.class)
32-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MENU_PRICE);
30+
BusinessException exception = assertThrows(BusinessException.class, () -> new Price(null));
31+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MENU_PRICE);
3332
}
3433

3534
@Test
3635
void 가격이_0원_이하이면_예외를_던진다() {
37-
assertThatThrownBy(() -> new Price(0))
38-
.isInstanceOf(BusinessException.class)
39-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_MENU_PRICE);
36+
BusinessException exception = assertThrows(BusinessException.class, () -> new Price(0));
37+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_MENU_PRICE);
4038
}
4139
}
4240
}

src/test/java/timeeat/domain/store/CoordinatesTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package timeeat.domain.store;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
54
import static org.junit.jupiter.api.Assertions.assertThrows;
65

76
import org.junit.jupiter.api.DisplayName;
@@ -33,19 +32,19 @@ class CreateCoordinates {
3332
Double nullLatitude = null;
3433
Double longitude = 126.9780;
3534

36-
assertThatThrownBy(() -> new Coordinates(nullLatitude, longitude))
37-
.isInstanceOf(BusinessException.class)
38-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_STORE_COORDINATES_NULL);
35+
BusinessException exception = assertThrows(BusinessException.class, () -> new Coordinates(nullLatitude, longitude));
36+
37+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_STORE_COORDINATES_NULL);
3938
}
4039

4140
@Test
4241
void 경도_값이_null이면_예외를_던진다() {
4342
Double latitude = 37.5665;
4443
Double nullLongitude = null;
4544

46-
assertThatThrownBy(() -> new Coordinates(latitude, nullLongitude))
47-
.isInstanceOf(BusinessException.class)
48-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_STORE_COORDINATES_NULL);
45+
BusinessException exception = assertThrows(BusinessException.class, () -> new Coordinates(latitude, nullLongitude));
46+
47+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_STORE_COORDINATES_NULL);
4948
}
5049

5150
@Test

src/test/java/timeeat/domain/store/StoreHoursTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package timeeat.domain.store;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
55

66
import java.time.LocalTime;
77

@@ -33,28 +33,28 @@ class CreateStoreHours {
3333
void openTime이_null이면_예외를_던진다() {
3434
LocalTime close = LocalTime.of(18, 0);
3535

36-
assertThatThrownBy(() -> new StoreHours(null, close))
37-
.isInstanceOf(BusinessException.class)
38-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_STORE_TIME_NULL);
36+
BusinessException exception = assertThrows(BusinessException.class, () -> new StoreHours(null, close));
37+
38+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_STORE_TIME_NULL);
3939
}
4040

4141
@Test
4242
void closeTime이_null이면_예외를_던진다() {
4343
LocalTime open = LocalTime.of(9, 0);
4444

45-
assertThatThrownBy(() -> new StoreHours(open, null))
46-
.isInstanceOf(BusinessException.class)
47-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_STORE_TIME_NULL);
45+
BusinessException exception = assertThrows(BusinessException.class, () -> new StoreHours(open, null));
46+
47+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_STORE_TIME_NULL);
4848
}
4949

5050
@Test
5151
void openTime이_closeTime보다_늦으면_예외를_던진다() {
5252
LocalTime open = LocalTime.of(20, 0);
5353
LocalTime close = LocalTime.of(9, 0);
5454

55-
assertThatThrownBy(() -> new StoreHours(open, close))
56-
.isInstanceOf(BusinessException.class)
57-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_STORE_TIME_ORDER);
55+
BusinessException exception = assertThrows(BusinessException.class, () -> new StoreHours(open, close));
56+
57+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_STORE_TIME_ORDER);
5858
}
5959
}
6060
}

src/test/java/timeeat/domain/store/StorePhoneNumberTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package timeeat.domain.store;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
55

66
import org.junit.jupiter.api.DisplayName;
77
import org.junit.jupiter.api.Nested;
@@ -38,9 +38,8 @@ class CreateStorePhoneNumber {
3838
@ParameterizedTest
3939
@ValueSource(strings = {"1234567", "1234567890123", "02-1234-5678", "abcdefghij"})
4040
void 번호_형식이_올바르지_않으면_예외를_던진다(String invalidNumber) {
41-
assertThatThrownBy(() -> new StorePhoneNumber(invalidNumber))
42-
.isInstanceOf(BusinessException.class)
43-
.hasFieldOrPropertyWithValue("errorCode", BusinessErrorCode.INVALID_STORE_PHONE_NUMBER);
41+
BusinessException exception = assertThrows(BusinessException.class, () -> new StorePhoneNumber(invalidNumber));
42+
assertThat(exception.getErrorCode()).isEqualTo(BusinessErrorCode.INVALID_STORE_PHONE_NUMBER);
4443
}
4544
}
4645
}

0 commit comments

Comments
 (0)