-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3단계 - 테스트를 통한 코드 보호 #661
Open
pawoo0211
wants to merge
25
commits into
next-step:pawoo0211
Choose a base branch
from
pawoo0211:step3
base: pawoo0211
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
3단계 - 테스트를 통한 코드 보호 #661
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
fc12ec3
docs: 요구사항 마지막 피드백 반영
pawoo0211 443c866
test: 메뉴 그룹 테스트 코드 작성
pawoo0211 06db615
test: 상품 뼈대 테스트 코드 작성
pawoo0211 004ae26
docs: 요구사항 Slot box 추가
pawoo0211 7aa384a
test: 상품 요구 사항 예외 케이스 테스트 코드 작성
pawoo0211 5597328
test: 메뉴 관련 Fixture 및 Helper 테스트 코드 작성
pawoo0211 46bc806
test: 메뉴 추가 기능 테스트 코드 작성
pawoo0211 c289b0c
test: 메뉴 추가 기능 예외 케이스 테스트 코드 작성
pawoo0211 07dccc1
test: 메뉴 가격 변경 테스트 코드 작성
pawoo0211 8559f86
test: 메뉴 활성화 및 비활성화 테스트 코드 작성
pawoo0211 61da7d8
test: 상품 가격 변경 테스트 코드 작성
pawoo0211 06ca73d
test: 테이블 테스트 코드 작성
pawoo0211 c61164d
test: 식당 주문 테스트 코드 작성
pawoo0211 3b57eb1
test: Static -> Non-Static fixture 변경
pawoo0211 d3e68c2
test: 음식 주문 기본 테스트 코드 작성
pawoo0211 a093058
test: static -> non-static 변수 변경
pawoo0211 e942cde
test: 상품 가격 변경 테스트 코드 수정
pawoo0211 d164baf
test: 사용하지 않는 import 제거
pawoo0211 e953f44
test: id 값 유무 판단으로의 객체 생성 검증 로직 변경
pawoo0211 55798de
test: 반목문 안에 있는 단언문 -> assertAll 메서드 사용으로 변경
pawoo0211 da7979c
test: 중첩 클래스를 이용한 테스트 분류
pawoo0211 649074f
test: Fixture 네이밍 구분 값 추가
pawoo0211 c4d18ed
test: 메뉴 생성 시 기존 상품 수량 확인 테스트 코드 작성
pawoo0211 41502de
test: 매장 주인 테이블 정리 테스트 코드 작성
pawoo0211 a74f453
test: 메뉴 예외 케이스 테스트 코드 추가
pawoo0211 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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,93 @@ | ||
package kitchenpos.menu.fixture; | ||
|
||
import kitchenpos.domain.Menu; | ||
import kitchenpos.domain.MenuGroup; | ||
import kitchenpos.domain.MenuProduct; | ||
import kitchenpos.domain.Product; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
public class MenuFixture { | ||
private MenuGroupFixture menuGroupFixture = new MenuGroupFixture(); | ||
private MenuProductFixture menuProductFixture = new MenuProductFixture(); | ||
|
||
public Menu 메뉴 = create( | ||
"메뉴_A", new BigDecimal(10000), menuGroupFixture.메뉴_그룹_A, | ||
true, List.of(menuProductFixture.메뉴_상품) | ||
); | ||
public Menu 메뉴_A = create( | ||
"메뉴_A", new BigDecimal(10000), menuGroupFixture.메뉴_그룹_A, | ||
true, List.of(menuProductFixture.메뉴_상품_A) | ||
); | ||
public Menu 메뉴_B = create( | ||
"메뉴_B", new BigDecimal(5000), menuGroupFixture.메뉴_그룹_A, | ||
true, List.of(menuProductFixture.메뉴_상품_B) | ||
); | ||
public Menu 메뉴_C = create( | ||
"메뉴_C", new BigDecimal(100000), menuGroupFixture.메뉴_그룹_A, | ||
false, List.of(menuProductFixture.메뉴_상품_C) | ||
); | ||
public Menu 메뉴_그룹_없는_메뉴 = create( | ||
"메뉴", new BigDecimal(10000), null, | ||
true, List.of(menuProductFixture.메뉴_상품_A) | ||
); | ||
public Menu 가격_없는_메뉴 = create( | ||
"메뉴", null, null, | ||
true, List.of(menuProductFixture.메뉴_상품_A) | ||
); | ||
public Menu 상품_없는_메뉴 = create( | ||
"메뉴", new BigDecimal(10000), menuGroupFixture.메뉴_그룹_A, | ||
true, null | ||
); | ||
public Menu 이름_없는_메뉴 = create( | ||
null, new BigDecimal(10000), menuGroupFixture.메뉴_그룹_A, | ||
true, List.of(menuProductFixture.메뉴_상품_A) | ||
); | ||
public Menu 부적절한_이름_메뉴 = create( | ||
"fuck", new BigDecimal(10000), menuGroupFixture.메뉴_그룹_A, | ||
true, List.of(menuProductFixture.메뉴_상품_A) | ||
); | ||
public Menu 상품_가격보다_큰_메뉴 = create( | ||
"메뉴", new BigDecimal(11000), menuGroupFixture.메뉴_그룹_A, | ||
true, List.of(menuProductFixture.메뉴_상품_A) | ||
); | ||
|
||
public static Menu create(String name, BigDecimal price, MenuGroup menuGroup, | ||
boolean isDisplayed, List<MenuProduct> menuProducts) { | ||
return create(UUID.randomUUID(), name, price, menuGroup, isDisplayed, menuProducts); | ||
} | ||
|
||
public static Menu create(UUID id, String name, BigDecimal price, MenuGroup menuGroup, | ||
boolean isDisplayed, List<MenuProduct> menuProducts) { | ||
Menu menu = new Menu(); | ||
menu.setId(id); | ||
menu.setName(name); | ||
menu.setPrice(price); | ||
menu.setMenuGroup(menuGroup); | ||
menu.setDisplayed(isDisplayed); | ||
menu.setMenuProducts(menuProducts); | ||
|
||
return menu; | ||
} | ||
|
||
public static MenuGroup extractMenuGroupFrom(Menu menu) { | ||
return menu.getMenuGroup(); | ||
} | ||
|
||
public static List<Product> extractProductsFrom(Menu menu) { | ||
List<Product> products = menu.getMenuProducts() | ||
.stream() | ||
.map(menuProduct -> menuProduct.getProduct()) | ||
.collect(Collectors.toList()); | ||
|
||
return products; | ||
} | ||
|
||
public static Product extractProductFrom(Menu menu) { | ||
MenuProduct menuProduct = menu.getMenuProducts().get(0); | ||
return menuProduct.getProduct(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/kitchenpos/menu/fixture/MenuGroupFixture.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,21 @@ | ||
package kitchenpos.menu.fixture; | ||
|
||
import kitchenpos.domain.MenuGroup; | ||
|
||
import java.util.UUID; | ||
|
||
public class MenuGroupFixture { | ||
public MenuGroup 메뉴_그룹_A = MenuGroupFixture.create(UUID.randomUUID(), "그룹A"); | ||
|
||
public static MenuGroup create(String name) { | ||
return create(UUID.randomUUID(), name); | ||
} | ||
|
||
public static MenuGroup create(UUID id, String name) { | ||
MenuGroup menuGroup = new MenuGroup(); | ||
menuGroup.setId(id); | ||
menuGroup.setName(name); | ||
|
||
return menuGroup; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/kitchenpos/menu/fixture/MenuProductFixture.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,21 @@ | ||
package kitchenpos.menu.fixture; | ||
|
||
import kitchenpos.domain.MenuProduct; | ||
import kitchenpos.domain.Product; | ||
|
||
public class MenuProductFixture { | ||
private kitchenpos.menu.fixture.productFixture productFixture = new productFixture(); | ||
|
||
public MenuProduct 메뉴_상품 = create(productFixture.상품, 10); | ||
public MenuProduct 메뉴_상품_A = create(productFixture.상품_A,10); | ||
public MenuProduct 메뉴_상품_B = create(productFixture.상품_B, 10); | ||
public MenuProduct 메뉴_상품_C = create(productFixture.상품_C, 10); | ||
|
||
public static MenuProduct create(Product product, long quantity) { | ||
MenuProduct menuProduct = new MenuProduct(); | ||
menuProduct.setProduct(product); | ||
menuProduct.setQuantity(quantity); | ||
|
||
return menuProduct; | ||
} | ||
} |
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,29 @@ | ||
package kitchenpos.menu.fixture; | ||
|
||
import kitchenpos.domain.Product; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.UUID; | ||
|
||
public class productFixture { | ||
public Product 상품 = create( "상품", new BigDecimal(1000)); | ||
public Product 상품_A = create( "상품A", new BigDecimal(1000)); | ||
public Product 상품_B = create("상품B", new BigDecimal(500)); | ||
public Product 상품_C = create("상품C", new BigDecimal(10000)); | ||
public Product 가격_없는_상품 = create(UUID.randomUUID(), "상품", null); | ||
public Product 가격_음수_상품 = create(UUID.randomUUID(), "상품", new BigDecimal(-1)); | ||
public Product 부적절한_이름_상품 = create(UUID.randomUUID(), "fuck", new BigDecimal(-1)); | ||
|
||
public static Product create(String name, BigDecimal price) { | ||
return create(UUID.randomUUID(), name, price); | ||
} | ||
|
||
public static Product create(UUID id, String name, BigDecimal price) { | ||
Product product = new Product(); | ||
product.setId(id); | ||
product.setName(name); | ||
product.setPrice(price); | ||
|
||
return product; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/kitchenpos/menu/service/MenuGroupServiceTest.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,55 @@ | ||
package kitchenpos.menu.service; | ||
|
||
import kitchenpos.application.MenuGroupService; | ||
import kitchenpos.domain.MenuGroup; | ||
import kitchenpos.domain.MenuGroupRepository; | ||
import kitchenpos.menu.fixture.MenuGroupFixture; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@DisplayName("메뉴 그룹 서비스 테스트") | ||
@ExtendWith(MockitoExtension.class) | ||
public class MenuGroupServiceTest { | ||
@Mock | ||
private MenuGroupRepository menuGroupRepository; | ||
@InjectMocks | ||
private MenuGroupService menuGroupService; | ||
|
||
private MenuGroupFixture menuGroupFixture; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
menuGroupFixture = new MenuGroupFixture(); | ||
} | ||
|
||
@Test | ||
@DisplayName("새로운 메뉴 그룹을 추가할 수 있다.") | ||
void create() { | ||
MenuGroup 한식 = menuGroupFixture.메뉴_그룹_A; | ||
|
||
Mockito.when(menuGroupRepository.save(Mockito.any())) | ||
.thenReturn(한식); | ||
|
||
MenuGroup result = menuGroupService.create(한식); | ||
|
||
Assertions.assertThat(result.getName()).isEqualTo(한식.getName()); | ||
} | ||
|
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
@DisplayName("메뉴 그룹 추가 시 이름이 반드시 존재해야 한다.") | ||
void test(String name) { | ||
Assertions.assertThatThrownBy( | ||
() -> menuGroupService.create(MenuGroupFixture.create(name)) | ||
).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생성이 정상적으로 되었다면 UUID를 가진 객체가 리턴되었는지 검증하는것도 좋아보이네요 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
피드백 감사합니다!