From ec74ca5a1002031735246401f7e03e7727c3d76e Mon Sep 17 00:00:00 2001 From: Jun Date: Fri, 31 Jan 2020 21:11:50 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/delfood/service/OrderService.java | 2 +- .../com/delfood/service/OrderServiceTest.java | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/delfood/service/OrderService.java b/src/main/java/com/delfood/service/OrderService.java index dd3d7d1..8b990ef 100644 --- a/src/main/java/com/delfood/service/OrderService.java +++ b/src/main/java/com/delfood/service/OrderService.java @@ -110,7 +110,7 @@ public OrderResponse order(String memberId, List items, long shopI * @return */ @Transactional(propagation = Propagation.NESTED) - private Long doOrder(String memberId, List items, Long shopId) { + public Long doOrder(String memberId, List items, Long shopId) { MemberDTO memberInfo = memberService.getMemberInfo(memberId); OrderDTO order = OrderDTO .builder() diff --git a/src/test/java/com/delfood/service/OrderServiceTest.java b/src/test/java/com/delfood/service/OrderServiceTest.java index eca3b73..51440a9 100644 --- a/src/test/java/com/delfood/service/OrderServiceTest.java +++ b/src/test/java/com/delfood/service/OrderServiceTest.java @@ -4,6 +4,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import static org.hamcrest.CoreMatchers.any; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.*; import org.assertj.core.util.Arrays; @@ -15,14 +16,17 @@ import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import org.springframework.boot.test.mock.mockito.MockBean; +import com.delfood.controller.response.OrderResponse; import com.delfood.dto.AddressDTO; import com.delfood.dto.ItemsBillDTO; import com.delfood.dto.ItemsBillDTO.MenuInfo; import com.delfood.dto.ItemsBillDTO.ShopInfo; import com.delfood.dto.MemberDTO; import com.delfood.dto.OrderDTO; +import com.delfood.dto.OrderDTO.OrderStatus; import com.delfood.dto.OrderItemDTO; import com.delfood.dto.OrderItemOptionDTO; +import com.delfood.dto.PaymentDTO; import com.delfood.dto.ShopDTO; import com.delfood.dto.ShopDTO.DeliveryType; import com.delfood.dto.ShopDTO.OrderType; @@ -31,6 +35,7 @@ import com.delfood.mapper.AddressMapper; import com.delfood.mapper.MemberMapper; import com.delfood.mapper.OrderMapper; +import com.delfood.mapper.PaymentMapper; import com.delfood.utils.OrderUtil; import com.delfood.utils.SHA256Util; @@ -51,6 +56,15 @@ public class OrderServiceTest { @Mock AddressService addressService; + + @Mock + PaymentService paymentService; + + @Mock + MockPayService mockPayService; + + @Mock + PushService pushService; public static String MEMBER_ID = "testMemberId"; @@ -126,7 +140,7 @@ public void testMockInit() { } @Test - public void getBillTest_계산서_검증() { + public void getBillTest_주문_테스트() { OrderItemDTO item = new OrderItemDTO(); item.setId(OrderUtil.generateOrderItemKey(MEMBER_ID, 0)); item.setMenuId(MENU_ID); @@ -143,12 +157,18 @@ public void testMockInit() { orderItems.add(item); given(orderMapper.findItemsBill(orderItems)).willReturn(menus); - + given(orderService.doOrder(MEMBER_ID, orderItems, SHOP_ID)).willReturn(ORDER_ID); + given(shopService.getShop(SHOP_ID)).willReturn(ShopDTO.builder().id(SHOP_ID).ownerId("testOwner").name("").build()); + + OrderResponse order = orderService.order(MEMBER_ID, orderItems, SHOP_ID, null); ItemsBillDTO bill = orderService.getBill(MEMBER_ID, orderItems, null); + assertThat(bill.getTotalPrice(), equalTo(13000L)); assertThat(bill.getDeliveryInfo().getDeliveryPrice(), equalTo(3000L)); assertThat(bill.getItemsPrice(), equalTo(10000L)); + assertThat(order.getBill().getMenus(), equalTo(menus)); + assertThat(order.getBill().getItemsPrice(), equalTo(10000L)); } }