-
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] 상품 수정 기능 POJO 구현 및 Stub 클래스를 활용한 테스트
- Loading branch information
1 parent
5a8cb1b
commit ef37e18
Showing
5 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
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
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
14 changes: 14 additions & 0 deletions
14
...r-service/src/main/java/com/example/productorderservice/product/UpdateProductRequest.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 org.springframework.util.Assert; | ||
|
||
record UpdateProductRequest( | ||
String name, | ||
int price, | ||
DiscountPolicy discountPolicy) { | ||
UpdateProductRequest { | ||
Assert.hasText(name, "상품명은 필수입니다."); | ||
Assert.isTrue(price > 0, "상품 가격은 0보다 커야 합니다."); | ||
Assert.notNull(discountPolicy, "할인 정책은 필수입니다."); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...der-service/src/test/java/com/example/productorderservice/product/ProductServiceTest.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,47 @@ | ||
package com.example.productorderservice.product; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ProductServiceTest { | ||
|
||
private ProductService productService; | ||
private StubProductPort productPort = new StubProductPort(); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
productService = new ProductService(productPort); | ||
} | ||
|
||
@Test | ||
void updateProduct() { | ||
final Long productId = 1L; | ||
final String name = "상품 수정"; | ||
int price = 2000; | ||
final DiscountPolicy discountPolicy = DiscountPolicy.NONE; | ||
final UpdateProductRequest request = new UpdateProductRequest(name, price, discountPolicy); | ||
final Product product = new Product("상품명", 1000, DiscountPolicy.NONE); | ||
productPort.getProduct_will_return = product; | ||
|
||
productService.updateProduct(productId, request); | ||
|
||
Assertions.assertEquals("상품 수정", product.getName()); | ||
Assertions.assertEquals(2000, product.getPrice()); | ||
} | ||
|
||
private class StubProductPort implements ProductPort { | ||
|
||
public Product getProduct_will_return; | ||
|
||
@Override | ||
public void save(final Product product) { | ||
throw new UnsupportedOperationException("StubProductPort#save not implemented yet !!"); | ||
} | ||
|
||
@Override | ||
public Product getProduct(final long productId) { | ||
return getProduct_will_return; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
product-order-service/src/test/java/com/example/productorderservice/product/ProductTest.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,17 @@ | ||
package com.example.productorderservice.product; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ProductTest { | ||
|
||
@Test | ||
void update() { | ||
final Product product = new Product("상품명", 1000, DiscountPolicy.NONE); | ||
|
||
product.update("상품 수정", 2000, DiscountPolicy.NONE); | ||
|
||
Assertions.assertEquals("상품 수정", product.getName()); | ||
Assertions.assertEquals(2000, product.getPrice()); | ||
} | ||
} |