From c99839d75b2bec3ab3f56171f33bc64bb0841bd9 Mon Sep 17 00:00:00 2001 From: Tim <135014430+nagisa77@users.noreply.github.com> Date: Mon, 4 Aug 2025 21:29:03 +0800 Subject: [PATCH] Mock repository and mapper dependencies for TagControllerTest --- .../com/openisle/controller/TagControllerTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/src/test/java/com/openisle/controller/TagControllerTest.java b/backend/src/test/java/com/openisle/controller/TagControllerTest.java index 53bcf8f29..69c8be30b 100644 --- a/backend/src/test/java/com/openisle/controller/TagControllerTest.java +++ b/backend/src/test/java/com/openisle/controller/TagControllerTest.java @@ -1,6 +1,9 @@ package com.openisle.controller; +import com.openisle.mapper.TagMapper; +import com.openisle.mapper.PostMapper; import com.openisle.model.Tag; +import com.openisle.repository.UserRepository; import com.openisle.service.TagService; import com.openisle.service.PostService; import org.junit.jupiter.api.Test; @@ -9,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; @@ -21,6 +25,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @WebMvcTest(TagController.class) @AutoConfigureMockMvc(addFilters = false) +@Import(TagMapper.class) class TagControllerTest { @Autowired private MockMvc mockMvc; @@ -31,6 +36,12 @@ class TagControllerTest { @MockBean private PostService postService; + @MockBean + private UserRepository userRepository; + + @MockBean + private PostMapper postMapper; + @Test void createAndGetTag() throws Exception { Tag t = new Tag(); @@ -64,7 +75,7 @@ class TagControllerTest { t.setDescription("d2"); t.setIcon("i2"); t.setSmallIcon("s2"); - Mockito.when(tagService.listTags()).thenReturn(List.of(t)); + Mockito.when(tagService.searchTags(null)).thenReturn(List.of(t)); mockMvc.perform(get("/api/tags")) .andExpect(status().isOk())