tdd : picking system - order detail vaildation

This commit is contained in:
haerong22
2021-08-04 22:56:41 +09:00
parent 900ff41f10
commit 396111104f
3 changed files with 42 additions and 3 deletions

View File

@@ -6,7 +6,25 @@ import org.springframework.stereotype.Service;
@Service
public class OrderDetailServiceImpl implements OrderDetailService {
@Override
public OrderDetail createOrderDetail(OrderDetail orderDetail) {
return orderDetail;
public OrderDetail createOrderDetail(OrderDetail orderDetail) throws Exception {
if (orderDetailValidation(orderDetail)) {
// do Something
return orderDetail;
} else {
throw new Exception("orderDetail validation fail");
}
}
private boolean orderDetailValidation(OrderDetail orderDetail) {
if (orderDetail.getOrderId() == null) {
return false;
}
if (orderDetail.getSku() == null) {
return false;
}
if (orderDetail.getAmount() < 1) {
return false;
}
return true;
}
}

View File

@@ -1,6 +1,7 @@
package com.example.pickingtdd.service;
import com.example.pickingtdd.entity.OrderDetail;
import com.example.pickingtdd.entity.OrderStateEnum;
import com.example.pickingtdd.entity.Sku;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -46,4 +47,24 @@ public class OrderDetailServiceTests {
assertEquals(10, orderDetail.getAmount());
}
@Test
void orderDetailValidation_success() {
OrderDetail orderDetail = new OrderDetail();
try {
orderDetail = orderDetailService.createOrderDetail(orderDetailSuccess);
} catch (Exception e) {
fail("should not throw exception");
}
assertEquals(1L, orderDetail.getOrderDetailId());
}
@Test
void orderValidation_fail() {
Exception e = assertThrows(Exception.class, () -> {
orderDetailService.createOrderDetail(orderDetailFail);
});
assertEquals("orderDetail validation fail", e.getMessage());
}
}

View File

@@ -9,8 +9,8 @@ SKU
------- TO-DO -------
[] Order validation 에 OrderDetail 검증 추가
[] OrderDetail validation 추가
[v] OrderDetail validation 추가
[v] OrderDetail 생성
[v] Order.state => enum 변경
[v] ORDER 검증