-
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 Test to SpringBoot Test
- Loading branch information
1 parent
2d27163
commit e52d969
Showing
1 changed file
with
11 additions
and
16 deletions.
There are no files selected for viewing
27 changes: 11 additions & 16 deletions
27
...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 |
---|---|---|
@@ -1,34 +1,29 @@ | ||
package com.example.productorderservice.product; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@SpringBootTest | ||
public class ProductServiceTest { | ||
|
||
@Autowired | ||
private ProductService productService; | ||
private ProductPort productPort; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
productPort = Mockito.mock(ProductPort.class); | ||
productService = new ProductService(productPort); | ||
} | ||
|
||
@Test | ||
void updateProduct() { | ||
productService.addProduct(ProductSteps.getAddProductRequest()); | ||
final Long productId = 1L; | ||
final UpdateProductRequest request = new UpdateProductRequest("상품 수정", 2000, DiscountPolicy.NONE); | ||
final Product product = new Product("상품명", 1000, DiscountPolicy.NONE); | ||
Mockito.when(productPort.getProduct(productId)).thenReturn(product); | ||
|
||
productService.updateProduct(productId, request); | ||
|
||
Assertions.assertEquals("상품 수정", product.getName()); | ||
Assertions.assertEquals(2000, product.getPrice()); | ||
final ResponseEntity<GetProductResponse> response = productService.getProduct(productId); | ||
final GetProductResponse productResponse = response.getBody(); | ||
|
||
Assertions.assertEquals("상품 수정", productResponse.name()); | ||
Assertions.assertEquals(2000, productResponse.price()); | ||
} | ||
} |