Skip to content

Commit

Permalink
[Order API TDD] Move Inner class for test to Upper leve
Browse files Browse the repository at this point in the history
  • Loading branch information
jihunparkme committed Feb 27, 2024
1 parent 7db7c50 commit d6f496f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
6 changes: 6 additions & 0 deletions product-order-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ final UpdateProductRequest request = new UpdateProductRequest(name, price, disco

**POJO**

> [POJO 상품 주문 기능 구현하기]()
>
> [Move Inner class for test to Upper leve]()
**스프링부트 테스트로 전환하기**

> [스프링부트 테스트로 전환하기]()
**API 테스트로 전환하기**

**JPA 적용**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.example.productorderservice.product.Product;
import com.example.productorderservice.product.ProductRepository;
import org.springframework.stereotype.Component;

@Component
class OrderAdapter implements OrderPort {

private final ProductRepository productRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.example.productorderservice.order;

import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

@Repository
class OrderRepository {
private Map<Long, Order> persistence = new HashMap<>();
private Long sequance = 0L;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.productorderservice.order;

import com.example.productorderservice.product.Product;
import org.springframework.stereotype.Component;

@Component
class OrderService {
private final OrderPort orderPort;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@RestController
@RequestMapping("/products")
public
class ProductService {
private final ProductPort productPort;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
package com.example.productorderservice.order;

import com.example.productorderservice.product.DiscountPolicy;
import com.example.productorderservice.product.Product;
import org.junit.jupiter.api.BeforeEach;
import com.example.productorderservice.product.ProductService;
import com.example.productorderservice.product.ProductSteps;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class OrderServiceTest {

@Autowired
private OrderService orderService;
private OrderPort orderPort;
private OrderRepository orderRepository;

@BeforeEach
void setUp() {
orderRepository = new OrderRepository();
orderPort = new OrderPort() {
@Override
public Product getProductById(final long productId) {
return new Product("상품명", 1000, DiscountPolicy.NONE);
}

@Override
public void save(final Order order) {
orderRepository.save(order);
}
};
orderService = new OrderService(orderPort);
}
@Autowired
private ProductService productService;

@Test
void 상품주문() {
productService.addProduct(ProductSteps.getAddProductRequest());
final CreateOrderRequest request = getCreateOrderRequest();

orderService.createOrder(request);
Expand Down

0 comments on commit d6f496f

Please sign in to comment.