Skip to content

Commit

Permalink
fix: Adjust for Spring Boot using MethodArgumentNotValidException ins…
Browse files Browse the repository at this point in the history
…tead of BindException
  • Loading branch information
wimdeblauwe committed Sep 12, 2024
1 parent 992abd9 commit 3e8684f
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down

0 comments on commit 3e8684f

Please sign in to comment.