-
Notifications
You must be signed in to change notification settings - Fork 264
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
[레거시 코드 리팩토링 미션 - 1단계] 우르(김현우) 미션 제출합니다. #493
Changes from 8 commits
c7c4d6c
02c1066
a05dab4
6e4ebec
370bb46
95f348a
adaa566
b63a63e
8fee873
9fcef58
54720f7
69d3a39
353aba8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE | |
spring.h2.console.enabled=true | ||
spring.jpa.properties.hibernate.format_sql=true | ||
spring.jpa.show-sql=true | ||
spring.flyway.enabled=false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gradle에 flyway 의존성이 추가되어 있었네요....! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
ALTER TABLE order_line_item ALTER COLUMN seq RESTART WITH 1; | ||
ALTER TABLE menu_product ALTER COLUMN seq RESTART WITH 1; | ||
ALTER TABLE orders ALTER COLUMN id RESTART WITH 1; | ||
ALTER TABLE menu ALTER COLUMN id RESTART WITH 1; | ||
ALTER TABLE product ALTER COLUMN id RESTART WITH 1; | ||
ALTER TABLE order_table ALTER COLUMN id RESTART WITH 1; | ||
ALTER TABLE table_group ALTER COLUMN id RESTART WITH 1; | ||
ALTER TABLE menu_group ALTER COLUMN id RESTART WITH 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 이렇게 하면 테스트마다 id 값을 일정하게 맞춰줄 수 있겠네요...! |
||
|
||
insert into product (name, price) | ||
values ('후라이드', 16000); | ||
insert into product (name, price) | ||
|
@@ -46,6 +55,9 @@ values (5, 5, 1); | |
insert into menu_product (menu_id, product_id, quantity) | ||
values (6, 6, 1); | ||
|
||
insert into table_group (id, created_date) | ||
values (1, now()); | ||
|
||
insert into order_table (number_of_guests, empty) | ||
values (0, true); | ||
insert into order_table (number_of_guests, empty) | ||
|
@@ -62,3 +74,17 @@ insert into order_table (number_of_guests, empty) | |
values (0, true); | ||
insert into order_table (number_of_guests, empty) | ||
values (0, true); | ||
insert into order_table (number_of_guests, empty) | ||
values (11, false); | ||
insert into order_table (id, number_of_guests, empty, table_group_id) | ||
values (333, 11, false, 1); | ||
insert into order_table (id, number_of_guests, empty, table_group_id) | ||
values (334, 11, false, 1); | ||
insert into order_table (id, number_of_guests, empty, table_group_id) | ||
values (335, 11, false, 1); | ||
|
||
insert into orders | ||
values (1, 'COMPLETION', now(), 1); | ||
insert into orders | ||
values (2, 'COOKING', now(), 2); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package kitchenpos.application; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
import kitchenpos.domain.MenuGroup; | ||
import kitchenpos.support.ServiceIntegrationTest; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
class MenuGroupServiceTest extends ServiceIntegrationTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍👍 |
||
|
||
@Autowired | ||
private MenuGroupService menuGroupService; | ||
|
||
@Test | ||
@DisplayName("create() : 메뉴 그룹을 생성할 수 있다.") | ||
void test_create() throws Exception { | ||
//given | ||
final MenuGroup menuGroup = new MenuGroup("menugroup"); | ||
|
||
//when | ||
final MenuGroup savedMenuGroup = menuGroupService.create(menuGroup); | ||
|
||
//then | ||
assertAll( | ||
() -> Assertions.assertNotNull(savedMenuGroup.getId()), | ||
() -> assertEquals(savedMenuGroup.getName(), menuGroup.getName()) | ||
); | ||
} | ||
|
||
@Test | ||
@DisplayName("list() : 모든 메뉴 그룹들을 조회할 수 있다.") | ||
void test_list() throws Exception { | ||
//when | ||
final List<MenuGroup> list = menuGroupService.list(); | ||
|
||
//then | ||
assertEquals(4, list.size()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package kitchenpos.application; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import kitchenpos.dao.MenuProductDao; | ||
import kitchenpos.domain.Menu; | ||
import kitchenpos.support.ServiceIntegrationTest; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
class MenuServiceTest extends ServiceIntegrationTest { | ||
|
||
@Autowired | ||
private MenuService menuService; | ||
|
||
@Autowired | ||
private MenuProductDao menuProductDao; | ||
|
||
@Test | ||
@DisplayName("create() : 메뉴를 생성할 수 있다.") | ||
void test_create() throws Exception { | ||
//given | ||
final Menu menu = new Menu(); | ||
menu.setMenuGroupId(3L); | ||
menu.setName("menu1MenuGroup3"); | ||
menu.setPrice(BigDecimal.valueOf(13000)); | ||
menu.setMenuProducts(menuProductDao.findAll()); | ||
|
||
//when | ||
final Menu savedMenu = menuService.create(menu); | ||
|
||
//then | ||
assertAll( | ||
() -> assertNotNull(savedMenu.getId()), | ||
() -> assertEquals(menu.getName(), savedMenu.getName()), | ||
() -> assertEquals(menu.getMenuGroupId(), savedMenu.getMenuGroupId()), | ||
() -> assertEquals(0, menu.getPrice().compareTo(savedMenu.getPrice())) | ||
); | ||
} | ||
|
||
@Test | ||
@DisplayName("create() : 메뉴 가격은 메뉴 상품들의 합보다 크거나 같으면 IllegalArgumentException이 발생할 수 있다.") | ||
void test_create_IllegalArgumentException() throws Exception { | ||
//given | ||
final Menu menu = new Menu(); | ||
menu.setMenuGroupId(3L); | ||
menu.setName("menu1MenuGroup3"); | ||
menu.setPrice(BigDecimal.valueOf(100000000)); | ||
menu.setMenuProducts(menuProductDao.findAll()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정상 케이스의 Menu 객체를 필드 혹은 Fixture로 만들고 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 따로 메서드 분리하였습니다 ! |
||
|
||
//when & then | ||
Assertions.assertThatThrownBy(() -> menuService.create(menu)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메뉴의 가격이 0원 미만인 경우와 잘못된 상품 id를 입력 받은 경우도 검증할 수 있으면 좋을 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 모든 제약조건에 대한 테스트가 존재해야할까 라는 생각입니다. |
||
@Test | ||
@DisplayName("list() : 모든 메뉴들을 조회할 수 있다.") | ||
void test_list() throws Exception { | ||
//when | ||
final List<Menu> menus = menuService.list(); | ||
|
||
//then | ||
assertEquals(6, menus.size()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package kitchenpos.application; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.util.List; | ||
import kitchenpos.dao.OrderDao; | ||
import kitchenpos.dao.OrderLineItemDao; | ||
import kitchenpos.domain.Order; | ||
import kitchenpos.domain.OrderLineItem; | ||
import kitchenpos.domain.OrderStatus; | ||
import kitchenpos.support.ServiceIntegrationTest; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
class OrderServiceTest extends ServiceIntegrationTest { | ||
|
||
@Autowired | ||
private OrderService orderService; | ||
|
||
@Autowired | ||
private OrderLineItemDao orderLineItemDao; | ||
|
||
@Autowired | ||
private OrderDao orderDao; | ||
|
||
@Test | ||
@DisplayName("create() : 주문을 생성할 수 있다.") | ||
void test_create() throws Exception { | ||
//given | ||
final Order order = createSuccessfulOrder(); | ||
|
||
//when | ||
final Order savedOrder = orderService.create(order); | ||
|
||
//then | ||
assertAll( | ||
() -> assertNotNull(savedOrder.getId()), | ||
() -> assertEquals(savedOrder.getOrderStatus(), OrderStatus.COOKING.name()), | ||
() -> assertNotNull(savedOrder.getOrderedTime()) | ||
); | ||
} | ||
|
||
private Order createSuccessfulOrder() { | ||
final OrderLineItem orderLineItem1 = new OrderLineItem(); | ||
orderLineItem1.setQuantity(13); | ||
orderLineItem1.setMenuId(1L); | ||
final OrderLineItem orderLineItem2 = new OrderLineItem(); | ||
orderLineItem2.setQuantity(3); | ||
orderLineItem2.setMenuId(2L); | ||
|
||
final Order order = new Order(); | ||
final long orderTableId = 335L; | ||
order.setOrderTableId(orderTableId); | ||
order.setOrderLineItems(List.of(orderLineItem1, orderLineItem2)); | ||
return order; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 비어있는 테이블에서 주문을 한 경우(=OrderTable.isEmpty()==true), 주문 목록(OrderLineItems)이 비어있는 경우, 잘못된 메뉴&테이블이 포함되어 있는 경우에 대한 검증 테스트가 있으면 좋을 것 같아요~! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 비어있는 테이블에서 주문을 한 경우 테스트 추가했습니다 ! |
||
|
||
@Test | ||
@DisplayName("list() : 모든 주문들을 조회할 수 있다.") | ||
void test_list() throws Exception { | ||
//given | ||
final int beforeSize = orderService.list().size(); | ||
|
||
orderService.create(createSuccessfulOrder()); | ||
|
||
//when | ||
final List<Order> savedOrders = orderService.list(); | ||
|
||
//then | ||
assertEquals(savedOrders.size(), beforeSize + 1); | ||
} | ||
|
||
@Test | ||
@DisplayName("changeOrderStatus() : 주문 상태를 변경할 수 있다.") | ||
void test_changeOrderStatus() throws Exception { | ||
//given | ||
final long savedOrderId = 3333L; | ||
|
||
final Order order = new Order(); | ||
order.setOrderStatus(OrderStatus.COMPLETION.name()); | ||
|
||
//when | ||
final Order updatedOrder = orderService.changeOrderStatus(savedOrderId, order); | ||
|
||
//then | ||
assertEquals(order.getOrderStatus(), updatedOrder.getOrderStatus()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이미 계산이 완료된 주문의 주문상태는 수정할 수 없게 구현이 되어 있어서 이부분에 대해서도 검증 테스트가 있으면 좋을 것 같습니다! |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package kitchenpos.application; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import kitchenpos.dao.ProductDao; | ||
import kitchenpos.domain.Product; | ||
import kitchenpos.support.ServiceIntegrationTest; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
class ProductServiceTest extends ServiceIntegrationTest { | ||
|
||
@Autowired | ||
private ProductService productService; | ||
|
||
@Autowired | ||
private ProductDao productDao; | ||
|
||
@Test | ||
@DisplayName("create() : 물품을 생성할 수 있다.") | ||
void test_create() throws Exception { | ||
//given | ||
final Product product = new Product(); | ||
product.setName("product"); | ||
product.setPrice(BigDecimal.valueOf(10000)); | ||
|
||
//when | ||
final Product savedProduct = productService.create(product); | ||
|
||
//then | ||
assertAll( | ||
() -> assertNotNull(savedProduct.getId()), | ||
() -> assertEquals(0, savedProduct.getPrice().compareTo(product.getPrice())), | ||
() -> assertEquals(savedProduct.getName(), product.getName()) | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 상품 가격이 0원 미만인 경우에 대한 검증 테스트도 있으면 좋을 것 같아요! |
||
|
||
@Test | ||
@DisplayName("list() : 모든 물품을 조회할 수 있다.") | ||
void test_list() throws Exception { | ||
//given | ||
final Product product = new Product(); | ||
product.setName("product"); | ||
product.setPrice(BigDecimal.valueOf(10000)); | ||
|
||
final int beforeSize = productService.list().size(); | ||
|
||
productDao.save(product); | ||
|
||
//when | ||
final List<Product> products = productService.list(); | ||
|
||
//then | ||
assertEquals(products.size(), beforeSize + 1); | ||
} | ||
} |
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.
요구사항에 예외 케이스에 대한 내용은 없네요...!
저의 경우 서비스의 요구사항엔 예측 가능한 예외 상황에 대한 제약 사항도 포함된다고 생각하는 편인데, 우르는 예외 케이스에 대한 요구사항을 작성하는 것에 대해 어떻게 생각하시나요??
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.
필요하다 생각이 들어서 작성했습니다!!