DATAREST-427 - Fixed NullPointerException in RepositoryRestExceptionHandler.
Handling HttpMessageNotReadableException in RepositoryRestExceptionHandler previously handed null to the badRequest(…) method resulting in an assertion failure in response(…) eventually. This is now fixed by handing in an HttpHeaders instance.
This commit is contained in:
@@ -159,7 +159,7 @@ public class RepositoryRestExceptionHandler {
|
||||
}
|
||||
|
||||
private <T extends Exception> ResponseEntity<ExceptionMessage> badRequest(T throwable) {
|
||||
return badRequest(null, throwable);
|
||||
return badRequest(new HttpHeaders(), throwable);
|
||||
}
|
||||
|
||||
private <T extends Exception> ResponseEntity<ExceptionMessage> badRequest(HttpHeaders headers, T throwable) {
|
||||
|
||||
@@ -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<ExceptionMessage> result = HANDLER
|
||||
.handleNotReadable(new HttpMessageNotReadableException("Message!"));
|
||||
|
||||
assertThat(result.getStatusCode(), is(org.springframework.http.HttpStatus.BAD_REQUEST));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user