-
Notifications
You must be signed in to change notification settings - Fork 1
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 #55 from endless-horses/feature#43-font-test
font test code 구현 close #43
- Loading branch information
Showing
2 changed files
with
60 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
58 changes: 58 additions & 0 deletions
58
src/test/java/com/endlesshorses/oot/custom/font/controller/FontControllerTest.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,58 @@ | ||
package com.endlesshorses.oot.custom.font.controller; | ||
|
||
import com.endlesshorses.oot.custom.font.dto.FontListResponseDto; | ||
|
||
import com.endlesshorses.oot.custom.font.entity.Font; | ||
import com.endlesshorses.oot.custom.font.service.FontService; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
class FontControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
@MockBean | ||
private FontService fontService; | ||
private List<FontListResponseDto> fontList; | ||
|
||
|
||
@Test | ||
@DisplayName("폰트 데이터 가져오기 테스트") | ||
void getFontResponse() throws Exception { | ||
|
||
Font font1 = new Font(); | ||
font1.setId(1004L); | ||
font1.setName("폰트 색상"); | ||
font1.setPrice(5000L); | ||
font1.setImageUrl("http://~"); | ||
|
||
FontListResponseDto fontDto = new FontListResponseDto(font1); | ||
fontList = Arrays.asList(fontDto); | ||
Mockito.when(fontService.list()).thenReturn(fontList); | ||
|
||
|
||
mockMvc.perform(get("/api/fonts") | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$[0].name").value(fontList.get(0).getName())) | ||
.andExpect(status().isOk()) | ||
.andDo(print()); | ||
} | ||
|
||
} |