From 3e8684faef580df1e21e4b320dd0da39596a95fd Mon Sep 17 00:00:00 2001 From: Wim Deblauwe Date: Thu, 12 Sep 2024 08:29:08 +0200 Subject: [PATCH] fix: Adjust for Spring Boot using MethodArgumentNotValidException instead of BindException --- .../handler/BindApiExceptionHandlerTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/BindApiExceptionHandlerTest.java b/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/BindApiExceptionHandlerTest.java index 2226af6..cc6377b 100644 --- a/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/BindApiExceptionHandlerTest.java +++ b/src/test/java/io/github/wimdeblauwe/errorhandlingspringbootstarter/handler/BindApiExceptionHandlerTest.java @@ -129,11 +129,11 @@ void testObjectValidationWithMessageOverride(@Autowired ErrorHandlingProperties @Test @WithMockUser void testTopLevelCodeOverride(@Autowired ErrorHandlingProperties properties) throws Exception { - properties.getCodes().put("org.springframework.validation.BindException", "BIND_FAILED"); + properties.getCodes().put("org.springframework.web.bind.MethodArgumentNotValidException", "METHOD_ARG_NOT_VALID"); mockMvc.perform(MockMvcRequestBuilders.get("/test/field-validation") .queryParam("param1", "foo")) .andExpect(status().isBadRequest()) - .andExpect(jsonPath("code").value("BIND_FAILED")) + .andExpect(jsonPath("code").value("METHOD_ARG_NOT_VALID")) .andExpect(jsonPath("fieldErrors", hasSize(1))) .andExpect(jsonPath("fieldErrors[0].code").value("REQUIRED_NOT_NULL")) .andExpect(jsonPath("fieldErrors[0].message").value("must not be null")) @@ -146,12 +146,12 @@ void testTopLevelCodeOverride(@Autowired ErrorHandlingProperties properties) thr @Test @WithMockUser void testDisableAddingPath(@Autowired ErrorHandlingProperties properties) throws Exception { - properties.getCodes().put("org.springframework.validation.BindException", "BIND_FAILED"); + properties.getCodes().put("org.springframework.web.bind.MethodArgumentNotValidException", "METHOD_ARG_NOT_VALID"); properties.setAddPathToError(false); mockMvc.perform(MockMvcRequestBuilders.get("/test/field-validation") .queryParam("param1", "foo")) .andExpect(status().isBadRequest()) - .andExpect(jsonPath("code").value("BIND_FAILED")) + .andExpect(jsonPath("code").value("METHOD_ARG_NOT_VALID")) .andExpect(jsonPath("fieldErrors", hasSize(1))) .andExpect(jsonPath("fieldErrors[0].code").value("REQUIRED_NOT_NULL")) .andExpect(jsonPath("fieldErrors[0].message").value("must not be null"))