From 076b1423b3f73d6068f511463c205ad71189ccde Mon Sep 17 00:00:00 2001 From: Subi Hwang Date: Tue, 20 Feb 2024 01:21:53 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20font=20test=20code=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=20#43?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oot/custom/font/entity/Font.java | 2 + .../font/controller/FontControllerTest.java | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/test/java/com/endlesshorses/oot/custom/font/controller/FontControllerTest.java diff --git a/src/main/java/com/endlesshorses/oot/custom/font/entity/Font.java b/src/main/java/com/endlesshorses/oot/custom/font/entity/Font.java index 0b6e438..966a3eb 100644 --- a/src/main/java/com/endlesshorses/oot/custom/font/entity/Font.java +++ b/src/main/java/com/endlesshorses/oot/custom/font/entity/Font.java @@ -4,12 +4,14 @@ import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import java.util.ArrayList; import java.util.List; @Entity @Getter +@Setter @NoArgsConstructor public class Font { @Id diff --git a/src/test/java/com/endlesshorses/oot/custom/font/controller/FontControllerTest.java b/src/test/java/com/endlesshorses/oot/custom/font/controller/FontControllerTest.java new file mode 100644 index 0000000..9581c73 --- /dev/null +++ b/src/test/java/com/endlesshorses/oot/custom/font/controller/FontControllerTest.java @@ -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 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()); + } + +} \ No newline at end of file