diff --git a/src/test/java/com/runtimematrix/exception/GlobalExceptionHandlerTest.java b/src/test/java/com/runtimematrix/exception/GlobalExceptionHandlerTest.java new file mode 100644 index 0000000..0da51bf --- /dev/null +++ b/src/test/java/com/runtimematrix/exception/GlobalExceptionHandlerTest.java @@ -0,0 +1,26 @@ +package com.runtimematrix.exception; + +import com.runtimematrix.dto.ErrorResponse; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@WebMvcTest +class GlobalExceptionHandlerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + void businessException_returnsConsistentErrorFormat() throws Exception { + mockMvc.perform(get("/api/v1/roles/999")) + .andExpect(status().isNotFound()) + .andExpect(jsonPath("$.code").value("ERR_ROLE_NOT_FOUND")) + .andExpect(jsonPath("$.timestamp").exists()) + .andExpect(jsonPath("$.path").value("/api/v1/roles/999")); + } +}