diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandler.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandler.java index 1d7ce7206..c37e7092c 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandler.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandler.java @@ -159,7 +159,7 @@ public class RepositoryRestExceptionHandler { } private ResponseEntity badRequest(T throwable) { - return badRequest(null, throwable); + return badRequest(new HttpHeaders(), throwable); } private ResponseEntity badRequest(HttpHeaders headers, T throwable) { diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandlerUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandlerUnitTests.java new file mode 100644 index 000000000..b21f2a237 --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandlerUnitTests.java @@ -0,0 +1,47 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.rest.webmvc; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.junit.Test; +import org.springframework.context.support.StaticMessageSource; +import org.springframework.data.rest.webmvc.support.ExceptionMessage; +import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; + +/** + * Unit tests for {@link RepositoryRestExceptionHandler}. + * + * @author Oliver Gierke + */ +public class RepositoryRestExceptionHandlerUnitTests { + + static final RepositoryRestExceptionHandler HANDLER = new RepositoryRestExceptionHandler(new StaticMessageSource()); + + /** + * @see DATAREST-427 + */ + @Test + public void handlesHttpMessageNotReadableException() { + + ResponseEntity result = HANDLER + .handleNotReadable(new HttpMessageNotReadableException("Message!")); + + assertThat(result.getStatusCode(), is(org.springframework.http.HttpStatus.BAD_REQUEST)); + } +}