-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[레거시 코드 리팩터링 - 1단계] 오찌(오지훈) 미션 제출합니다. (#204)
* docs: 요구 사항 정리 * test: 상품에 대한 서비스 테스트 코드 작성 * test: 테스트 환경에서 flyway disable * test: 상품에 대한 Dao 테스트 코드 작성 * test: 서비스와 Dao에 대한 테스트 설정을 어노테이션으로 분리 * test: ProductDao의 누락 테스트 추가 * test: 메뉴 그룹에 대한 Dao 테스트 코드 작성 * test: 메뉴 그룹에 대한 서비스 테스트 코드 작성 * test: 메뉴에 대한 Dao 테스트 코드 작성 * test: 메뉴에 대한 서비스 테스트 코드 작성 * chore: 자바 11로 마이그레이션 * test: 메뉴 상품에 대한 Dao 테스트 코드 작성 * test: 단체 지정에 대한 Dao 테스트 코드 작성 * test: 주문 테이블에 대한 Dao 테스트 코드 작성 * test: 단체 지정 픽스처 생성 구조 변경 * test: 외래키 null 가능 테스트 추가 * test: 주문에 대한 Dao 테스트 코드 작성 * test: 주문 항목에 대한 Dao 테스트 코드 작성 * test: 주문 테이블에 대한 서비스 테스트 코드 작성 * test: 단체 지정에 대한 서비스 테스트 코드 작성 * test: 주문에 대한 서비스 테스트 코드 작성 * test: 서비스 테스트가 테스트 대상 서비스만 의존하고 나머지는 DAO를 의존하도록 수정
- Loading branch information
Showing
23 changed files
with
1,669 additions
and
14 deletions.
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
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
43 changes: 43 additions & 0 deletions
43
src/test/java/kitchenpos/application/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,43 @@ | ||
package kitchenpos.application; | ||
|
||
import static kitchenpos.support.TestFixtureFactory.메뉴_그룹을_생성한다; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import java.util.List; | ||
import kitchenpos.domain.MenuGroup; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
@ServiceTest | ||
class MenuGroupServiceTest { | ||
|
||
@Autowired | ||
private MenuGroupService menuGroupService; | ||
|
||
@Test | ||
void 메뉴_그룹을_생성할_수_있다() { | ||
MenuGroup menuGroup = 메뉴_그룹을_생성한다("메뉴 그룹"); | ||
|
||
MenuGroup savedMenuGroup = menuGroupService.create(menuGroup); | ||
|
||
assertAll( | ||
() -> assertThat(savedMenuGroup.getId()).isNotNull(), | ||
() -> assertThat(savedMenuGroup).usingRecursiveComparison() | ||
.ignoringFields("id") | ||
.isEqualTo(menuGroup) | ||
); | ||
} | ||
|
||
@Test | ||
void 메뉴_그룹의_목록을_조회할_수_있다() { | ||
MenuGroup menuGroup1 = menuGroupService.create(메뉴_그룹을_생성한다("메뉴 그룹1")); | ||
MenuGroup menuGroup2 = menuGroupService.create(메뉴_그룹을_생성한다("메뉴 그룹2")); | ||
|
||
List<MenuGroup> actual = menuGroupService.list(); | ||
|
||
assertThat(actual).hasSize(2) | ||
.usingFieldByFieldElementComparator() | ||
.containsExactly(menuGroup1, menuGroup2); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
src/test/java/kitchenpos/application/MenuServiceTest.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,107 @@ | ||
package kitchenpos.application; | ||
|
||
import static kitchenpos.support.TestFixtureFactory.메뉴_그룹을_생성한다; | ||
import static kitchenpos.support.TestFixtureFactory.메뉴_상품을_생성한다; | ||
import static kitchenpos.support.TestFixtureFactory.메뉴를_생성한다; | ||
import static kitchenpos.support.TestFixtureFactory.상품을_생성한다; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import kitchenpos.dao.MenuGroupDao; | ||
import kitchenpos.dao.ProductDao; | ||
import kitchenpos.domain.Menu; | ||
import kitchenpos.domain.MenuProduct; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
@ServiceTest | ||
class MenuServiceTest { | ||
|
||
@Autowired | ||
private ProductDao productDao; | ||
@Autowired | ||
private MenuGroupDao menuGroupDao; | ||
@Autowired | ||
private MenuService menuService; | ||
|
||
@Test | ||
void 메뉴를_생성할_수_있다() { | ||
Long menuGroupId = menuGroupDao.save(메뉴_그룹을_생성한다("메뉴 그룹")) | ||
.getId(); | ||
Long productId = productDao.save(상품을_생성한다("상품", new BigDecimal(1_000))) | ||
.getId(); | ||
MenuProduct menuProduct = 메뉴_상품을_생성한다(null, productId, 1); | ||
Menu menu = 메뉴를_생성한다("메뉴", new BigDecimal(0), menuGroupId, List.of(menuProduct)); | ||
|
||
Menu savedMenu = menuService.create(menu); | ||
|
||
assertAll( | ||
() -> assertThat(savedMenu.getId()).isNotNull(), | ||
() -> assertThat(savedMenu.getPrice().compareTo(menu.getPrice())).isZero(), | ||
() -> assertThat(savedMenu).usingRecursiveComparison() | ||
.ignoringFields("id", "price", "menuProducts") | ||
.isEqualTo(savedMenu), | ||
() -> assertThat(savedMenu.getMenuProducts()).hasSize(1) | ||
.usingElementComparatorIgnoringFields("seq") | ||
.containsOnly(menuProduct) | ||
); | ||
} | ||
|
||
@Test | ||
void 메뉴_가격이_0원_미만이면_예외를_반환한다() { | ||
Menu menu = 메뉴를_생성한다("메뉴", new BigDecimal(-1), null, null); | ||
|
||
assertThatThrownBy(() -> menuService.create(menu)).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void 메뉴_그룹이_존재하지_않으면_예외를_반환한다() { | ||
Menu menu = 메뉴를_생성한다("메뉴", new BigDecimal(0), 0L, null); | ||
|
||
assertThatThrownBy(() -> menuService.create(menu)).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void 존재하지_않는_상품이_메뉴에_포함되어_있으면_예외를_반환한다() { | ||
Long menuGroupId = menuGroupDao.save(메뉴_그룹을_생성한다("메뉴 그룹")) | ||
.getId(); | ||
MenuProduct menuProduct = 메뉴_상품을_생성한다(null, 0L, 1); | ||
Menu menu = 메뉴를_생성한다("메뉴", new BigDecimal(2_000), menuGroupId, List.of(menuProduct)); | ||
|
||
assertThatThrownBy(() -> menuService.create(menu)).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void 메뉴_가격이_메뉴_상품_가격의_합보다_크면_예외를_반환한다() { | ||
Long menuGroupId = menuGroupDao.save(메뉴_그룹을_생성한다("메뉴 그룹")) | ||
.getId(); | ||
Long productId = productDao.save(상품을_생성한다("상품", new BigDecimal(1_000))) | ||
.getId(); | ||
MenuProduct menuProduct = 메뉴_상품을_생성한다(null, productId, 1); | ||
Menu menu = 메뉴를_생성한다("메뉴", new BigDecimal(2_000), menuGroupId, List.of(menuProduct)); | ||
|
||
assertThatThrownBy(() -> menuService.create(menu)).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void 모든_메뉴를_조회할_수_있다() { | ||
Long menuGroupId = menuGroupDao.save(메뉴_그룹을_생성한다("메뉴 그룹")) | ||
.getId(); | ||
Long productId = productDao.save(상품을_생성한다("상품", new BigDecimal(1_000))) | ||
.getId(); | ||
MenuProduct menuProduct = 메뉴_상품을_생성한다(null, productId, 1); | ||
Menu menu1 = menuService.create( | ||
메뉴를_생성한다("메뉴1", new BigDecimal(0), menuGroupId, List.of(menuProduct))); | ||
Menu menu2 = menuService.create( | ||
메뉴를_생성한다("메뉴2", new BigDecimal(0), menuGroupId, List.of(menuProduct))); | ||
|
||
List<Menu> actual = menuService.list(); | ||
|
||
assertThat(actual).hasSize(2) | ||
.usingElementComparatorIgnoringFields("price", "menuProducts") | ||
.containsExactly(menu1, menu2); | ||
} | ||
} |
Oops, something went wrong.