forked from codesquad-members-2022/sidedish
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: 특정 Products의 meal type 조회 기능의 서비스 구현
- 테스트 작성
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
BE/src/main/java/sidedish/com/repository/ProductsRepository.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,11 @@ | ||
package sidedish.com.repository; | ||
|
||
import java.util.List; | ||
import org.springframework.stereotype.Repository; | ||
import sidedish.com.domain.Product; | ||
|
||
@Repository | ||
public interface ProductsRepository { | ||
|
||
List<Product> findByMealType(String meal); | ||
} |
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
49 changes: 49 additions & 0 deletions
49
BE/src/test/java/sidedish/com/service/ProductsServiceTest.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,49 @@ | ||
package sidedish.com.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import sidedish.com.domain.DisCountPolicy; | ||
import sidedish.com.domain.Image; | ||
import sidedish.com.domain.Product; | ||
import sidedish.com.repository.ProductsRepository; | ||
|
||
@DisplayName("ProductsServiceTest 클래스") | ||
class ProductsServiceTest { | ||
|
||
private ProductsService productsService; | ||
private ProductsRepository productsRepository; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
productsRepository = mock(ProductsRepository.class); | ||
productsService = new ProductsService(productsRepository); | ||
} | ||
|
||
@Test | ||
void 만약_meal_type이_soup인_경우_soup음식_타입_조회_성공() throws Exception { | ||
given(productsRepository.findByMealType("soup")) | ||
.willReturn(createListProducts()); | ||
|
||
List<Product> result = productsService.findByMealType("soup"); | ||
|
||
assertThat(result.size()).isEqualTo(2); | ||
} | ||
|
||
private List<Product> createListProducts() { | ||
List<Product> products = new ArrayList<>(); | ||
|
||
products.add(new Product(5L, List.of(new Image("http://kukukukukukukukuku.com/test.jpg")), | ||
"한돈 돼지 김치찌개", "김치찌개에는 역시 돼지고기", 8370, 9300, new DisCountPolicy("이벤트특가"))); | ||
products.add(new Product(6L, List.of(new Image("http://kukukukukukukukuku.com/test2.jpg")), | ||
"하하하 테스트 음식", "맛있어요", 8370, 9300, new DisCountPolicy("이벤트특가"))); | ||
|
||
return products; | ||
} | ||
} |