Configure checkstyle and update code to comply
This commit configures Checkstyle and updates the build to comply with that configuration. The Eclipse JDT metadata has also been updated so that the output of Eclipse’s code formatting and clean-up is compliant with Checkstyle. The use of the latest version (6.10.1) of Checkstyle has required an upgrade to Gradle 2.7. Gradle hardcode’s the name of the Checkstyle’s main class which has changed between version 5 (Gradle’s default) and version 6. Closes gh-119
This commit is contained in:
@@ -16,15 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.mockmvc;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
@@ -37,14 +28,22 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.restdocs.mockmvc.MockMvcOperationRequestFactory;
|
||||
import org.springframework.restdocs.operation.OperationRequest;
|
||||
import org.springframework.restdocs.operation.OperationRequestPart;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link MockMvcOperationRequestFactory}
|
||||
* Tests for {@link MockMvcOperationRequestFactory}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@@ -183,13 +182,13 @@ public class MockMvcOperationRequestFactoryTests {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo")
|
||||
.buildRequest(new MockServletContext());
|
||||
Part mockPart = mock(Part.class);
|
||||
when(mockPart.getHeaderNames()).thenReturn(Arrays.asList("a", "b"));
|
||||
when(mockPart.getHeaders("a")).thenReturn(Arrays.asList("alpha"));
|
||||
when(mockPart.getHeaders("b")).thenReturn(Arrays.asList("bravo", "banana"));
|
||||
when(mockPart.getInputStream()).thenReturn(
|
||||
given(mockPart.getHeaderNames()).willReturn(Arrays.asList("a", "b"));
|
||||
given(mockPart.getHeaders("a")).willReturn(Arrays.asList("alpha"));
|
||||
given(mockPart.getHeaders("b")).willReturn(Arrays.asList("bravo", "banana"));
|
||||
given(mockPart.getInputStream()).willReturn(
|
||||
new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }));
|
||||
when(mockPart.getName()).thenReturn("part-name");
|
||||
when(mockPart.getSubmittedFileName()).thenReturn("submitted.txt");
|
||||
given(mockPart.getName()).willReturn("part-name");
|
||||
given(mockPart.getSubmittedFileName()).willReturn("submitted.txt");
|
||||
mockRequest.addPart(mockPart);
|
||||
OperationRequest request = this.factory.createOperationRequest(mockRequest);
|
||||
assertThat(request.getParts().size(), is(1));
|
||||
@@ -207,14 +206,14 @@ public class MockMvcOperationRequestFactoryTests {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo")
|
||||
.buildRequest(new MockServletContext());
|
||||
Part mockPart = mock(Part.class);
|
||||
when(mockPart.getHeaderNames()).thenReturn(Arrays.asList("a", "b"));
|
||||
when(mockPart.getHeaders("a")).thenReturn(Arrays.asList("alpha"));
|
||||
when(mockPart.getHeaders("b")).thenReturn(Arrays.asList("bravo", "banana"));
|
||||
when(mockPart.getInputStream()).thenReturn(
|
||||
given(mockPart.getHeaderNames()).willReturn(Arrays.asList("a", "b"));
|
||||
given(mockPart.getHeaders("a")).willReturn(Arrays.asList("alpha"));
|
||||
given(mockPart.getHeaders("b")).willReturn(Arrays.asList("bravo", "banana"));
|
||||
given(mockPart.getInputStream()).willReturn(
|
||||
new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }));
|
||||
when(mockPart.getName()).thenReturn("part-name");
|
||||
when(mockPart.getSubmittedFileName()).thenReturn("submitted.png");
|
||||
when(mockPart.getContentType()).thenReturn("image/png");
|
||||
given(mockPart.getName()).willReturn("part-name");
|
||||
given(mockPart.getSubmittedFileName()).willReturn("submitted.png");
|
||||
given(mockPart.getContentType()).willReturn("image/png");
|
||||
mockRequest.addPart(mockPart);
|
||||
OperationRequest request = this.factory.createOperationRequest(mockRequest);
|
||||
assertThat(request.getParts().size(), is(1));
|
||||
|
||||
@@ -16,36 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.mockmvc;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.restdocs.curl.CurlDocumentation.curlRequest;
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.maskLinks;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.removeHeaders;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.replacePattern;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
|
||||
import static org.springframework.restdocs.snippet.Attributes.attributes;
|
||||
import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.codeBlock;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.httpRequest;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.httpResponse;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.snippet;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
@@ -80,11 +50,40 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.restdocs.curl.CurlDocumentation.curlRequest;
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
|
||||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.maskLinks;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.removeHeaders;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.replacePattern;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
|
||||
import static org.springframework.restdocs.snippet.Attributes.attributes;
|
||||
import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.codeBlock;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.httpRequest;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.httpResponse;
|
||||
import static org.springframework.restdocs.test.SnippetMatchers.snippet;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* Integration tests for Spring REST Docs
|
||||
*
|
||||
* Integration tests for using Spring REST Docs with Spring Test's Mock MVC.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Dewet Diener
|
||||
*/
|
||||
@@ -371,9 +370,12 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test configuration that enables Spring MVC.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
static class TestConfiguration extends WebMvcConfigurerAdapter {
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public TestController testController() {
|
||||
@@ -383,7 +385,7 @@ public class MockMvcRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@RestController
|
||||
static class TestController {
|
||||
private static class TestController {
|
||||
|
||||
@RequestMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Map<String, Object>> foo() {
|
||||
|
||||
@@ -16,12 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.mockmvc;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -33,6 +27,12 @@ import org.springframework.test.web.servlet.request.RequestPostProcessor;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link RestDocumentationMockMvcConfigurer}.
|
||||
*
|
||||
|
||||
@@ -16,6 +16,16 @@
|
||||
|
||||
package org.springframework.restdocs.mockmvc;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -29,20 +39,9 @@ import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuild
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.put;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.request;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
|
||||
/**
|
||||
* Tests for {@link RestDocumentationRequestBuilders}
|
||||
*
|
||||
* Tests for {@link RestDocumentationRequestBuilders}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014-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.restdocs.mockmvc.test;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.restdocs.snippet.RestDocumentationContextPlaceholderResolver;
|
||||
import org.springframework.restdocs.snippet.StandardWriterResolver;
|
||||
import org.springframework.restdocs.snippet.WriterResolver;
|
||||
import org.springframework.restdocs.templates.StandardTemplateResourceResolver;
|
||||
import org.springframework.restdocs.templates.TemplateEngine;
|
||||
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.RequestBuilder;
|
||||
import org.springframework.web.servlet.FlashMap;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* A minimal stub implementation of {@link MvcResult}
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*
|
||||
*/
|
||||
public class StubMvcResult implements MvcResult {
|
||||
|
||||
private final MockHttpServletRequest request;
|
||||
|
||||
private final MockHttpServletResponse response;
|
||||
|
||||
public static StubMvcResult result() {
|
||||
return new StubMvcResult();
|
||||
}
|
||||
|
||||
public static StubMvcResult result(RequestBuilder requestBuilder) {
|
||||
return new StubMvcResult(requestBuilder);
|
||||
}
|
||||
|
||||
public static StubMvcResult result(RequestBuilder requestBuilder,
|
||||
MockHttpServletResponse response) {
|
||||
return new StubMvcResult(requestBuilder, response);
|
||||
}
|
||||
|
||||
public static StubMvcResult result(MockHttpServletRequest request) {
|
||||
return new StubMvcResult(request);
|
||||
}
|
||||
|
||||
public static StubMvcResult result(MockHttpServletResponse response) {
|
||||
return new StubMvcResult(response);
|
||||
}
|
||||
|
||||
public static StubMvcResult result(MockHttpServletRequest request,
|
||||
MockHttpServletResponse response) {
|
||||
return new StubMvcResult(request, response);
|
||||
}
|
||||
|
||||
private StubMvcResult() {
|
||||
this(new MockHttpServletRequest(), new MockHttpServletResponse());
|
||||
}
|
||||
|
||||
private StubMvcResult(MockHttpServletRequest request) {
|
||||
this(request, new MockHttpServletResponse());
|
||||
}
|
||||
|
||||
private StubMvcResult(MockHttpServletResponse response) {
|
||||
this(new MockHttpServletRequest(), response);
|
||||
}
|
||||
|
||||
private StubMvcResult(RequestBuilder requestBuilder, MockHttpServletResponse response) {
|
||||
this(requestBuilder.buildRequest(new MockServletContext()), response);
|
||||
}
|
||||
|
||||
private StubMvcResult(MockHttpServletRequest request, MockHttpServletResponse response) {
|
||||
this.request = request;
|
||||
if (this.request.getAttribute(TemplateEngine.class.getName()) == null) {
|
||||
this.request.setAttribute(TemplateEngine.class.getName(),
|
||||
new MustacheTemplateEngine(new StandardTemplateResourceResolver()));
|
||||
}
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null, null);
|
||||
this.request.setAttribute(RestDocumentationContext.class.getName(), context);
|
||||
if (this.request.getAttribute(WriterResolver.class.getName()) == null) {
|
||||
this.request.setAttribute(WriterResolver.class.getName(),
|
||||
new StandardWriterResolver(
|
||||
new RestDocumentationContextPlaceholderResolver(context)));
|
||||
}
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
private StubMvcResult(RequestBuilder requestBuilder) {
|
||||
this(requestBuilder.buildRequest(new MockServletContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockHttpServletRequest getRequest() {
|
||||
return this.request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockHttpServletResponse getResponse() {
|
||||
return this.response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerInterceptor[] getInterceptors() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView getModelAndView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exception getResolvedException() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlashMap getFlashMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAsyncResult() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAsyncResult(long timeToWait) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014-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.restdocs.mockmvc.test;
|
||||
|
||||
import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
|
||||
public class TestRequestBuilders {
|
||||
|
||||
private TestRequestBuilders() {
|
||||
|
||||
}
|
||||
|
||||
public static MockHttpServletRequestBuilder get(String urlTemplate,
|
||||
Object... urlVariables) {
|
||||
return org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get(
|
||||
urlTemplate, urlVariables).requestAttr(
|
||||
RestDocumentationContext.class.getName(),
|
||||
new RestDocumentationContext(null, null, null));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user