-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Order API TDD] Move Inner class for test to Upper level
- Loading branch information
1 parent
cd9618b
commit 77f7c48
Showing
8 changed files
with
104 additions
and
89 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...rder-service/src/main/java/com/example/productorderservice/product/AddProductRequest.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,15 @@ | ||
package com.example.productorderservice.product; | ||
|
||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* 03. Request 는 record 로 사용 가능 | ||
*/ | ||
record AddProductRequest(String name, int price, DiscountPolicy discountPolicy) { | ||
AddProductRequest { | ||
// 03-1. Assert 를 활용해서 파라미터 체크 | ||
Assert.hasText(name, "상품명은 필수입니다."); | ||
Assert.isTrue(price > 0, "상품 가격은 0보다 커야 합니다."); | ||
Assert.notNull(discountPolicy, "할인 정책은 필수입니다."); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...t-order-service/src/main/java/com/example/productorderservice/product/DiscountPolicy.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,5 @@ | ||
package com.example.productorderservice.product; | ||
|
||
enum DiscountPolicy { | ||
NONE | ||
} |
27 changes: 27 additions & 0 deletions
27
product-order-service/src/main/java/com/example/productorderservice/product/Product.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,27 @@ | ||
package com.example.productorderservice.product; | ||
|
||
import org.springframework.util.Assert; | ||
|
||
class Product { | ||
private Long id; | ||
private final String name; | ||
private final int price; | ||
private final DiscountPolicy discountPolicy; | ||
|
||
public Product(final String name, final int price, final DiscountPolicy discountPolicy) { | ||
Assert.hasText(name, "상품명은 필수입니다."); | ||
Assert.isTrue(price > 0, "상품 가격은 0보다 커야 합니다."); | ||
Assert.notNull(discountPolicy, "할인 정책은 필수입니다."); | ||
this.name = name; | ||
this.price = price; | ||
this.discountPolicy = discountPolicy; | ||
} | ||
|
||
public void assigId(final Long id) { | ||
this.id = id; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...t-order-service/src/main/java/com/example/productorderservice/product/ProductAdapter.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,14 @@ | ||
package com.example.productorderservice.product; | ||
|
||
class ProductAdapter implements ProductPort { | ||
private final ProductRepository productRepository; | ||
|
||
ProductAdapter(final ProductRepository productRepository) { | ||
this.productRepository = productRepository; | ||
} | ||
|
||
@Override | ||
public void save(final Product product) { | ||
productRepository.save(product); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
product-order-service/src/main/java/com/example/productorderservice/product/ProductPort.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,5 @@ | ||
package com.example.productorderservice.product; | ||
|
||
interface ProductPort { | ||
void save(final Product product); | ||
} |
14 changes: 14 additions & 0 deletions
14
...rder-service/src/main/java/com/example/productorderservice/product/ProductRepository.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,14 @@ | ||
package com.example.productorderservice.product; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
class ProductRepository { | ||
private Map<Long, Product> persistence = new HashMap<>(); | ||
private Long sequence = 0L; | ||
|
||
public void save(final Product product) { | ||
product.assigId(++sequence); | ||
persistence.put(product.getId(), product); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...t-order-service/src/main/java/com/example/productorderservice/product/ProductService.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,18 @@ | ||
package com.example.productorderservice.product; | ||
|
||
/** | ||
* 04. ProductService 메서드 구현 | ||
*/ | ||
class ProductService { | ||
private final ProductPort productPort; | ||
|
||
ProductService(final ProductPort productPort) { | ||
this.productPort = productPort; | ||
} | ||
|
||
public void addProduct(final AddProductRequest request) { | ||
final Product product = new Product(request.name(), request.price(), request.discountPolicy()); // 05. Product 클래스 생성 | ||
|
||
productPort.save(product); | ||
} | ||
} |
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