-
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 #56 from endless-horses/feature#44-color-test
color test code 구현 close #44
- Loading branch information
Showing
2 changed files
with
59 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
57 changes: 57 additions & 0 deletions
57
src/test/java/com/endlesshorses/oot/custom/color/controller/ColorControllerTest.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,57 @@ | ||
package com.endlesshorses.oot.custom.color.controller; | ||
|
||
import com.endlesshorses.oot.custom.color.dto.ColorListResponseDto; | ||
import com.endlesshorses.oot.custom.color.entity.Color; | ||
import com.endlesshorses.oot.custom.color.service.ColorService; | ||
import com.endlesshorses.oot.custom.font.dto.FontListResponseDto; | ||
import com.endlesshorses.oot.custom.font.entity.Font; | ||
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 ColorControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
@MockBean | ||
private ColorService colorService; | ||
private List<ColorListResponseDto> colorList; | ||
|
||
@Test | ||
@DisplayName("색상 데이터 가져오기 테스트") | ||
void getFontResponse() throws Exception { | ||
Color color1 = new Color(); | ||
color1.setId(1004L); | ||
color1.setName("색상 이름"); | ||
color1.setRgb("FFFFFF"); | ||
color1.setImageUrl("http://~"); | ||
|
||
ColorListResponseDto colorDto = new ColorListResponseDto(color1); | ||
colorList = Arrays.asList(colorDto); | ||
Mockito.when(colorService.list()).thenReturn(colorList); | ||
|
||
|
||
mockMvc.perform(get("/api/colors") | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$[0].name").value(colorList.get(0).getName())) | ||
.andExpect(status().isOk()) | ||
.andDo(print()); | ||
} | ||
|
||
} |