Allow responses with non-standard status codes to be documented
Fixes gh-639
This commit is contained in:
@@ -19,7 +19,6 @@ package org.springframework.restdocs.mockmvc;
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.restdocs.operation.OperationResponse;
|
||||
import org.springframework.restdocs.operation.OperationResponseFactory;
|
||||
@@ -36,8 +35,8 @@ class MockMvcResponseConverter implements ResponseConverter<MockHttpServletRespo
|
||||
|
||||
@Override
|
||||
public OperationResponse convert(MockHttpServletResponse mockResponse) {
|
||||
return new OperationResponseFactory().create(HttpStatus.valueOf(mockResponse.getStatus()),
|
||||
extractHeaders(mockResponse), mockResponse.getContentAsByteArray());
|
||||
return new OperationResponseFactory().create(mockResponse.getStatus(), extractHeaders(mockResponse),
|
||||
mockResponse.getContentAsByteArray());
|
||||
}
|
||||
|
||||
private HttpHeaders extractHeaders(MockHttpServletResponse response) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -61,4 +61,13 @@ public class MockMvcResponseConverterTests {
|
||||
Collections.singletonList("name=value; Domain=localhost; HttpOnly"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseWithCustomStatus() {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.setStatus(600);
|
||||
OperationResponse operationResponse = this.factory.convert(response);
|
||||
assertThat(operationResponse.getStatus()).isNull();
|
||||
assertThat(operationResponse.getStatusCode()).isEqualTo(600);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user