This commit is contained in:
Phillip Webb
2015-10-14 12:18:23 -07:00
parent 81f876aac5
commit 143536f72d
4 changed files with 23 additions and 20 deletions

View File

@@ -172,14 +172,16 @@ public class BasicErrorControllerIntegrationTests {
@SuppressWarnings("rawtypes")
public void testRequestBodyValidationForMachineClient() throws Exception {
load();
RequestEntity request = RequestEntity.post(URI.create(createUrl("/bodyValidation")))
RequestEntity request = RequestEntity
.post(URI.create(createUrl("/bodyValidation")))
.contentType(MediaType.APPLICATION_JSON).body("{}");
ResponseEntity<Map> entity = new TestRestTemplate().exchange(request, Map.class);
String resp = entity.getBody().toString();
assertThat(resp, containsString("Error count: 1"));
assertThat(resp, containsString("errors=[{"));
assertThat(resp, containsString("codes=["));
assertThat(resp, containsString("org.springframework.web.bind.MethodArgumentNotValidException"));
assertThat(resp, containsString(
"org.springframework.web.bind.MethodArgumentNotValidException"));
}
private void assertErrorAttributes(Map<?, ?> content, String status, String error,
@@ -278,7 +280,7 @@ public class BasicErrorControllerIntegrationTests {
}
private static class DummyBody {
static class DummyBody {
@NotNull
private String content;
@@ -290,6 +292,7 @@ public class BasicErrorControllerIntegrationTests {
public void setContent(String content) {
this.content = content;
}
}
}

View File

@@ -168,7 +168,8 @@ public class DefaultErrorAttributesTests {
}
@Test
public void extractMethodArgumentNotValidExceptionBindingResultErrors() throws Exception {
public void extractMethodArgumentNotValidExceptionBindingResultErrors()
throws Exception {
BindingResult bindingResult = new MapBindingResult(
Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));