-
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.
Merge pull request #227 from RandomJusicool/feature/226-stock-info-te…
…st-code 🔀 :: 주식 상세보기 테스트 코드 추가
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/test/java/com/juicycool/backend/stock/GetInfoStockServiceImplTest.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,60 @@ | ||
package com.juicycool.backend.stock; | ||
|
||
import com.juicycool.backend.domain.stock.Stock; | ||
import com.juicycool.backend.domain.stock.converter.StockConverter; | ||
import com.juicycool.backend.domain.stock.exception.NotFoundStockException; | ||
import com.juicycool.backend.domain.stock.repository.StockRepository; | ||
import com.juicycool.backend.domain.stock.service.impl.GetInfoStockServiceImpl; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class GetInfoStockServiceImplTest { | ||
|
||
@Mock | ||
private StockRepository stockRepository; | ||
|
||
@Mock | ||
private StockConverter stockConverter; | ||
|
||
@InjectMocks | ||
private GetInfoStockServiceImpl getInfoStockService; | ||
|
||
private Stock stock; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
|
||
stock = Stock.builder() | ||
.code("1111") | ||
.presentPrice(11111L) | ||
.build(); | ||
} | ||
|
||
@Test | ||
@DisplayName("만약 주식 코드로 주식을 찾지 못한 경우") | ||
void If_not_found_stock_by_stock_code() { | ||
when(stockRepository.findByCode(anyString())).thenReturn(Optional.empty()); | ||
|
||
assertThrows(NotFoundStockException.class, () -> getInfoStockService.execute(anyString())); | ||
} | ||
|
||
@Test | ||
@DisplayName("만약 정상적으로 주식의 정보를 가져온 경우") | ||
void If_info_of_stock_normally_imported() { | ||
when(stockRepository.findByCode(anyString())).thenReturn(Optional.of(stock)); | ||
|
||
getInfoStockService.execute(anyString()); | ||
|
||
verify(stockRepository, times(1)).findByCode(anyString()); | ||
} | ||
} |