From 95c4234c99b46a21eddbfb71fb7ad9b814dec3b9 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 27 Mar 2018 12:53:34 +0100 Subject: [PATCH] Format core code with Eclipse Oxygen's formatter --- config/eclipse/org.eclipse.jdt.core.prefs | 24 +++++- config/eclipse/org.eclipse.jdt.ui.prefs | 4 +- .../restdocs/cli/CurlRequestSnippetTests.java | 73 ++++++++----------- .../cli/HttpieRequestSnippetTests.java | 73 ++++++++----------- .../RestDocumentationConfigurerTests.java | 14 ++-- .../headers/RequestHeadersSnippetTests.java | 27 ++----- .../headers/ResponseHeadersSnippetTests.java | 23 +++--- .../http/HttpRequestSnippetTests.java | 53 ++++++-------- .../http/HttpResponseSnippetTests.java | 10 +-- .../hypermedia/LinksSnippetTests.java | 22 +++--- .../PrettyPrintingContentModifierTests.java | 4 +- .../payload/JsonFieldTypeResolverTests.java | 8 +- .../payload/RequestBodyPartSnippetTests.java | 20 ++--- .../payload/RequestBodySnippetTests.java | 18 ++--- .../RequestFieldsSnippetFailureTests.java | 4 +- .../payload/RequestFieldsSnippetTests.java | 24 +++--- .../RequestPartFieldsSnippetTests.java | 37 ++++------ .../payload/ResponseBodySnippetTests.java | 17 ++--- .../ResponseFieldsSnippetFailureTests.java | 6 +- .../payload/ResponseFieldsSnippetTests.java | 28 ++++--- .../request/PathParametersSnippetTests.java | 65 +++++++---------- .../RequestParametersSnippetTests.java | 29 +++----- .../request/RequestPartsSnippetTests.java | 29 +++----- .../snippet/TemplatedSnippetTests.java | 5 +- .../mockmvc/MockMvcRequestConverterTests.java | 7 +- ...kMvcRestDocumentationIntegrationTests.java | 67 +++++++---------- ...suredRestDocumentationConfigurerTests.java | 6 +- ...uredRestDocumentationIntegrationTests.java | 36 ++++----- ...suredRestDocumentationConfigurerTests.java | 6 +- ...uredRestDocumentationIntegrationTests.java | 36 ++++----- 30 files changed, 341 insertions(+), 434 deletions(-) diff --git a/config/eclipse/org.eclipse.jdt.core.prefs b/config/eclipse/org.eclipse.jdt.core.prefs index 62ded11b..9f047259 100644 --- a/config/eclipse/org.eclipse.jdt.core.prefs +++ b/config/eclipse/org.eclipse.jdt.core.prefs @@ -104,6 +104,7 @@ org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.processAnnotations=disabled org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 @@ -114,11 +115,14 @@ org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_e org.eclipse.jdt.core.formatter.alignment_for_assignment=0 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=16 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0 org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_module_statements=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 @@ -128,6 +132,8 @@ org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0 +org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0 org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 org.eclipse.jdt.core.formatter.blank_lines_after_package=1 @@ -154,6 +160,7 @@ org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=false org.eclipse.jdt.core.formatter.comment.format_block_comments=true org.eclipse.jdt.core.formatter.comment.format_header=false org.eclipse.jdt.core.formatter.comment.format_html=true @@ -186,6 +193,7 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert @@ -380,12 +388,24 @@ org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.tabulation.char=tab org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.use_on_off_tags=true org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true -org.eclipse.jdt.core.javaFormatter=org.springframework.ide.eclipse.jdt.formatter.javaformatter +org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter diff --git a/config/eclipse/org.eclipse.jdt.ui.prefs b/config/eclipse/org.eclipse.jdt.ui.prefs index d9bb135c..f794f2ab 100644 --- a/config/eclipse/org.eclipse.jdt.ui.prefs +++ b/config/eclipse/org.eclipse.jdt.ui.prefs @@ -60,7 +60,7 @@ cleanup_settings_version=2 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_Spring REST Docs Java Conventions -formatter_settings_version=12 +formatter_settings_version=13 org.eclipse.jdt.ui.exception.name=e org.eclipse.jdt.ui.gettersetter.use.is=true org.eclipse.jdt.ui.ignorelowercasenames=true @@ -70,7 +70,7 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=9999 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=9999 -org.eclipse.jdt.ui.text.custom_code_templates= +org.eclipse.jdt.ui.text.custom_code_templates= sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_missing_annotations=true diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java index 936a76b4..d0fe1f76 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -167,10 +167,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests { @Test public void postRequestWithMultipleParameters() throws IOException { - this.snippets.expectCurlRequest() - .withContents(codeBlock("bash") - .content("$ curl 'http://localhost/foo' -i -X POST" - + " -d 'k1=v1&k1=v1-bis&k2=v2'")); + this.snippets.expectCurlRequest().withContents( + codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X POST" + + " -d 'k1=v1&k1=v1-bis&k2=v2'")); new CurlRequestSnippet(this.commandFormatter).document( this.operationBuilder.request("http://localhost/foo").method("POST") .param("k1", "v1", "v1-bis").param("k2", "v2").build()); @@ -224,10 +223,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests { @Test public void putRequestWithMultipleParameters() throws IOException { - this.snippets.expectCurlRequest() - .withContents(codeBlock("bash") - .content("$ curl 'http://localhost/foo' -i -X PUT" - + " -d 'k1=v1&k1=v1-bis&k2=v2'")); + this.snippets.expectCurlRequest().withContents( + codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X PUT" + + " -d 'k1=v1&k1=v1-bis&k2=v2'")); new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder .request("http://localhost/foo").method("PUT").param("k1", "v1") .param("k1", "v1-bis").param("k2", "v2").build()); @@ -247,11 +245,10 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests { this.snippets.expectCurlRequest() .withContents(codeBlock("bash").content("$ curl 'http://localhost/foo' -i" + " -H 'Content-Type: application/json' -H 'a: alpha'")); - new CurlRequestSnippet(this.commandFormatter) - .document(this.operationBuilder.request("http://localhost/foo") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.APPLICATION_JSON_VALUE) - .header("a", "alpha").build()); + new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/foo") + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .header("a", "alpha").build()); } @Test @@ -285,10 +282,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests { + "'metadata={\"description\": \"foo\"}'"; this.snippets.expectCurlRequest() .withContents(codeBlock("bash").content(expectedContent)); - new CurlRequestSnippet(this.commandFormatter).document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("metadata", "{\"description\": \"foo\"}".getBytes()).build()); } @@ -299,10 +295,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests { + "'image=@documents/images/example.png;type=image/png'"; this.snippets.expectCurlRequest() .withContents(codeBlock("bash").content(expectedContent)); - new CurlRequestSnippet(this.commandFormatter).document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("image", new byte[0]) .header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE) .submittedFileName("documents/images/example.png").build()); @@ -315,10 +310,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests { + "'image=@documents/images/example.png'"; this.snippets.expectCurlRequest() .withContents(codeBlock("bash").content(expectedContent)); - new CurlRequestSnippet(this.commandFormatter).document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("image", new byte[0]) .submittedFileName("documents/images/example.png").build()); } @@ -331,10 +325,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests { + "-F 'b=banana'"; this.snippets.expectCurlRequest() .withContents(codeBlock("bash").content(expectedContent)); - new CurlRequestSnippet(this.commandFormatter).document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("image", new byte[0]) .submittedFileName("documents/images/example.png").and() .param("a", "apple", "avocado").param("b", "banana").build()); @@ -344,11 +337,10 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests { public void basicAuthCredentialsAreSuppliedUsingUserOption() throws IOException { this.snippets.expectCurlRequest().withContents(codeBlock("bash") .content("$ curl 'http://localhost/foo' -i -u 'user:secret'")); - new CurlRequestSnippet(this.commandFormatter) - .document(this.operationBuilder.request("http://localhost/foo") - .header(HttpHeaders.AUTHORIZATION, - "Basic " + Base64Utils - .encodeToString("user:secret".getBytes())) + new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/foo") + .header(HttpHeaders.AUTHORIZATION, + "Basic " + Base64Utils.encodeToString("user:secret".getBytes())) .build()); } @@ -375,12 +367,11 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests { .withContents(codeBlock("bash").content( "$ curl 'http://localhost/foo' -i" + " -H 'Host: api.example.com'" + " -H 'Content-Type: application/json' -H 'a: alpha'")); - new CurlRequestSnippet(this.commandFormatter) - .document(this.operationBuilder.request("http://localhost/foo") - .header(HttpHeaders.HOST, "api.example.com") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.APPLICATION_JSON_VALUE) - .header("a", "alpha").build()); + new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/foo") + .header(HttpHeaders.HOST, "api.example.com") + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .header("a", "alpha").build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java index d6ae022f..5b775002 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -168,10 +168,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests { @Test public void postRequestWithMultipleParameters() throws IOException { - this.snippets.expectHttpieRequest() - .withContents(codeBlock("bash") - .content("$ http --form POST 'http://localhost/foo'" - + " 'k1=v1' 'k1=v1-bis' 'k2=v2'")); + this.snippets.expectHttpieRequest().withContents( + codeBlock("bash").content("$ http --form POST 'http://localhost/foo'" + + " 'k1=v1' 'k1=v1-bis' 'k2=v2'")); new HttpieRequestSnippet(this.commandFormatter).document( this.operationBuilder.request("http://localhost/foo").method("POST") .param("k1", "v1", "v1-bis").param("k2", "v2").build()); @@ -225,10 +224,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests { @Test public void putRequestWithMultipleParameters() throws IOException { - this.snippets.expectHttpieRequest() - .withContents(codeBlock("bash") - .content("$ http --form PUT 'http://localhost/foo'" - + " 'k1=v1' 'k1=v1-bis' 'k2=v2'")); + this.snippets.expectHttpieRequest().withContents( + codeBlock("bash").content("$ http --form PUT 'http://localhost/foo'" + + " 'k1=v1' 'k1=v1-bis' 'k2=v2'")); new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder .request("http://localhost/foo").method("PUT").param("k1", "v1") .param("k1", "v1-bis").param("k2", "v2").build()); @@ -248,11 +246,10 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests { this.snippets.expectHttpieRequest().withContents( codeBlock("bash").content("$ http GET 'http://localhost/foo'" + " 'Content-Type:application/json' 'a:alpha'")); - new HttpieRequestSnippet(this.commandFormatter) - .document(this.operationBuilder.request("http://localhost/foo") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.APPLICATION_JSON_VALUE) - .header("a", "alpha").build()); + new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/foo") + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .header("a", "alpha").build()); } @Test @@ -283,10 +280,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests { + " 'metadata'@<(echo '{\"description\": \"foo\"}')"; this.snippets.expectHttpieRequest() .withContents(codeBlock("bash").content(expectedContent)); - new HttpieRequestSnippet(this.commandFormatter).document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("metadata", "{\"description\": \"foo\"}".getBytes()).build()); } @@ -297,10 +293,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests { + " 'image'@'documents/images/example.png'"; this.snippets.expectHttpieRequest() .withContents(codeBlock("bash").content(expectedContent)); - new HttpieRequestSnippet(this.commandFormatter).document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("image", new byte[0]) .header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE) .submittedFileName("documents/images/example.png").build()); @@ -312,10 +307,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests { + " 'image'@'documents/images/example.png'"; this.snippets.expectHttpieRequest() .withContents(codeBlock("bash").content(expectedContent)); - new HttpieRequestSnippet(this.commandFormatter).document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("image", new byte[0]) .submittedFileName("documents/images/example.png").build()); } @@ -327,10 +321,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests { + " 'b=banana'"; this.snippets.expectHttpieRequest() .withContents(codeBlock("bash").content(expectedContent)); - new HttpieRequestSnippet(this.commandFormatter).document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("image", new byte[0]) .submittedFileName("documents/images/example.png").and() .param("a", "apple", "avocado").param("b", "banana").build()); @@ -340,11 +333,10 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests { public void basicAuthCredentialsAreSuppliedUsingAuthOption() throws IOException { this.snippets.expectHttpieRequest().withContents(codeBlock("bash") .content("$ http --auth 'user:secret' GET 'http://localhost/foo'")); - new HttpieRequestSnippet(this.commandFormatter) - .document(this.operationBuilder.request("http://localhost/foo") - .header(HttpHeaders.AUTHORIZATION, - "Basic " + Base64Utils - .encodeToString("user:secret".getBytes())) + new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/foo") + .header(HttpHeaders.AUTHORIZATION, + "Basic " + Base64Utils.encodeToString("user:secret".getBytes())) .build()); } @@ -371,12 +363,11 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests { .withContents(codeBlock("bash").content( "$ http GET 'http://localhost/foo' 'Host:api.example.com'" + " 'Content-Type:application/json' 'a:alpha'")); - new HttpieRequestSnippet(this.commandFormatter) - .document(this.operationBuilder.request("http://localhost/foo") - .header(HttpHeaders.HOST, "api.example.com") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.APPLICATION_JSON_VALUE) - .header("a", "alpha").build()); + new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder + .request("http://localhost/foo") + .header(HttpHeaders.HOST, "api.example.com") + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .header("a", "alpha").build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/config/RestDocumentationConfigurerTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/config/RestDocumentationConfigurerTests.java index 4cc0b635..4701f996 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/config/RestDocumentationConfigurerTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/config/RestDocumentationConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -69,8 +69,8 @@ public class RestDocumentationConfigurerTests { assertThat(configuration, hasEntry(equalTo(WriterResolver.class.getName()), instanceOf(StandardWriterResolver.class))); assertThat(configuration, - hasEntry( - equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS), + hasEntry(equalTo( + RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS), instanceOf(List.class))); List defaultSnippets = (List) configuration .get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS); @@ -116,8 +116,8 @@ public class RestDocumentationConfigurerTests { this.configurer.snippets().withDefaults(CliDocumentation.curlRequest()) .apply(configuration, createContext()); assertThat(configuration, - hasEntry( - equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS), + hasEntry(equalTo( + RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS), instanceOf(List.class))); @SuppressWarnings("unchecked") List defaultSnippets = (List) configuration @@ -133,8 +133,8 @@ public class RestDocumentationConfigurerTests { this.configurer.snippets().withAdditionalDefaults(snippet).apply(configuration, createContext()); assertThat(configuration, - hasEntry( - equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS), + hasEntry(equalTo( + RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS), instanceOf(List.class))); List defaultSnippets = (List) configuration .get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS); diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetTests.java index 1f28ea11..8b9007bd 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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,17 +61,10 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests { headerWithName("Accept-Encoding").description("three"), headerWithName("Accept-Language").description("four"), headerWithName("Cache-Control").description("five"), - headerWithName( - "Connection") - .description("six"))) - .document( - this.operationBuilder - .request( - "http://localhost") - .header("X-Test", "test") - .header("Accept", "*/*") - .header("Accept-Encoding", - "gzip, deflate") + headerWithName("Connection").description("six"))).document( + this.operationBuilder.request("http://localhost") + .header("X-Test", "test").header("Accept", "*/*") + .header("Accept-Encoding", "gzip, deflate") .header("Accept-Language", "en-US,en;q=0.5") .header("Cache-Control", "max-age=0") .header("Connection", "keep-alive").build()); @@ -105,8 +98,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests { given(resolver.resolveTemplateResource("request-headers")) .willReturn(snippetResource("request-headers-with-title")); new RequestHeadersSnippet( - Arrays.asList(headerWithName("X-Test").description("one")), - attributes( + Arrays.asList(headerWithName("X-Test").description("one")), attributes( key("title").value("Custom title"))) .document( this.operationBuilder @@ -143,7 +135,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests { .header("X-Test", "test") .header("Accept-Encoding", "gzip, deflate") - .header("Accept", "*/*").build()); + .header("Accept", "*/*").build()); } @Test @@ -160,10 +152,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests { headerWithName("Accept-Encoding").description("three"), headerWithName("Accept-Language").description("four")) .and(headerWithName("Cache-Control").description("five"), - headerWithName( - "Connection") - .description( - "six")) + headerWithName("Connection").description("six")) .document(this.operationBuilder.request("http://localhost") .header("X-Test", "test").header("Accept", "*/*") .header("Accept-Encoding", "gzip, deflate") diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetTests.java index 7f5fe1d6..fbf5887b 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -58,15 +58,12 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests { headerWithName("Content-Type").description("two"), headerWithName("Etag").description("three"), headerWithName("Cache-Control").description("five"), - headerWithName("Vary").description("six"))) - .document( - this.operationBuilder.response() - .header("X-Test", "test") - .header("Content-Type", - "application/json") - .header("Etag", "lskjadldj3ii32l2ij23") - .header("Cache-Control", "max-age=0") - .header("Vary", "User-Agent").build()); + headerWithName("Vary").description("six"))).document( + this.operationBuilder.response().header("X-Test", "test") + .header("Content-Type", "application/json") + .header("Etag", "lskjadldj3ii32l2ij23") + .header("Cache-Control", "max-age=0") + .header("Vary", "User-Agent").build()); } @Test @@ -91,13 +88,13 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests { @Test public void responseHeadersWithCustomAttributes() throws IOException { - this.snippets.expectResponseHeaders().withContents(containsString("Custom title")); + this.snippets.expectResponseHeaders() + .withContents(containsString("Custom title")); TemplateResourceResolver resolver = mock(TemplateResourceResolver.class); given(resolver.resolveTemplateResource("response-headers")) .willReturn(snippetResource("response-headers-with-title")); new ResponseHeadersSnippet( - Arrays.asList(headerWithName("X-Test").description("one")), - attributes( + Arrays.asList(headerWithName("X-Test").description("one")), attributes( key("title").value("Custom title"))) .document( this.operationBuilder diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java index 32687d60..2a58ae97 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -278,10 +278,9 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests { .header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY) .header(HttpHeaders.HOST, "localhost").content(expectedContent)); - new HttpRequestSnippet().document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new HttpRequestSnippet().document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("image", "<< data >>".getBytes()).build()); } @@ -294,10 +293,9 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests { .header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY) .header(HttpHeaders.HOST, "localhost").content(expectedContent)); - new HttpRequestSnippet().document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new HttpRequestSnippet().document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("image", "<< data >>".getBytes()).submittedFileName("image.png") .build()); } @@ -321,10 +319,9 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests { .header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY) .header(HttpHeaders.HOST, "localhost").content(expectedContent)); - new HttpRequestSnippet().document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new HttpRequestSnippet().document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .param("a", "apple", "avocado").param("b", "banana") .part("image", "<< data >>".getBytes()).build()); } @@ -341,11 +338,10 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests { .header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY) .header(HttpHeaders.HOST, "localhost").content(expectedContent)); - new HttpRequestSnippet().document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) - .param("a").part("image", "<< data >>".getBytes()).build()); + new HttpRequestSnippet().document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) + .param("a").part("image", "<< data >>".getBytes()).build()); } @Test @@ -358,10 +354,9 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests { .header("Content-Type", "multipart/form-data; boundary=" + BOUNDARY) .header(HttpHeaders.HOST, "localhost").content(expectedContent)); - new HttpRequestSnippet().document( - this.operationBuilder.request("http://localhost/upload").method("POST") - .header(HttpHeaders.CONTENT_TYPE, - MediaType.MULTIPART_FORM_DATA_VALUE) + new HttpRequestSnippet().document(this.operationBuilder + .request("http://localhost/upload").method("POST") + .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE) .part("image", "<< data >>".getBytes()) .header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE).build()); } @@ -383,15 +378,11 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests { TemplateResourceResolver resolver = mock(TemplateResourceResolver.class); given(resolver.resolveTemplateResource("http-request")) .willReturn(snippetResource("http-request-with-title")); - new HttpRequestSnippet( - attributes( - key("title").value("Title for the request"))) - .document( - this.operationBuilder - .attribute(TemplateEngine.class.getName(), - new MustacheTemplateEngine( - resolver)) - .request("http://localhost/foo").build()); + new HttpRequestSnippet(attributes(key("title").value("Title for the request"))) + .document(this.operationBuilder + .attribute(TemplateEngine.class.getName(), + new MustacheTemplateEngine(resolver)) + .request("http://localhost/foo").build()); } private String createPart(String content) { diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java index bbfa255a..ef2a549b 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -65,11 +65,9 @@ public class HttpResponseSnippetTests extends AbstractSnippetTests { public void responseWithHeaders() throws IOException { this.snippets.expectHttpResponse().withContents(httpResponse(HttpStatus.OK) .header("Content-Type", "application/json").header("a", "alpha")); - new HttpResponseSnippet() - .document(this.operationBuilder.response() - .header(HttpHeaders.CONTENT_TYPE, - MediaType.APPLICATION_JSON_VALUE) - .header("a", "alpha").build()); + new HttpResponseSnippet().document(this.operationBuilder.response() + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .header("a", "alpha").build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java index 7f6f98d3..5797dda4 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -88,8 +88,9 @@ public class LinksSnippetTests extends AbstractSnippetTests { @Test public void documentedLinks() throws IOException { - this.snippets.expectLinks().withContents(tableWithHeader("Relation", "Description") - .row("`a`", "one").row("`b`", "two")); + this.snippets.expectLinks() + .withContents(tableWithHeader("Relation", "Description").row("`a`", "one") + .row("`b`", "two")); new LinksSnippet( new StubLinkExtractor().withLinks(new Link("a", "alpha"), new Link("b", "bravo")), @@ -100,8 +101,9 @@ public class LinksSnippetTests extends AbstractSnippetTests { @Test public void linkDescriptionFromTitleInPayload() throws IOException { - this.snippets.expectLinks().withContents(tableWithHeader("Relation", "Description") - .row("`a`", "one").row("`b`", "Link b")); + this.snippets.expectLinks() + .withContents(tableWithHeader("Relation", "Description").row("`a`", "one") + .row("`b`", "Link b")); new LinksSnippet( new StubLinkExtractor().withLinks(new Link("a", "alpha", "Link a"), new Link("b", "bravo", "Link b")), @@ -154,8 +156,9 @@ public class LinksSnippetTests extends AbstractSnippetTests { @Test public void additionalDescriptors() throws IOException { - this.snippets.expectLinks().withContents(tableWithHeader("Relation", "Description") - .row("`a`", "one").row("`b`", "two")); + this.snippets.expectLinks() + .withContents(tableWithHeader("Relation", "Description").row("`a`", "one") + .row("`b`", "two")); HypermediaDocumentation .links(new StubLinkExtractor().withLinks(new Link("a", "alpha"), new Link("b", "bravo")), @@ -166,8 +169,9 @@ public class LinksSnippetTests extends AbstractSnippetTests { @Test public void tableCellContentIsEscapedWhenNecessary() throws IOException { - this.snippets.expectLinks().withContents(tableWithHeader("Relation", "Description") - .row(escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two"))); + this.snippets.expectLinks() + .withContents(tableWithHeader("Relation", "Description").row( + escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two"))); new LinksSnippet(new StubLinkExtractor().withLinks(new Link("Foo|Bar", "foo")), Arrays.asList(new LinkDescriptor("Foo|Bar").description("one|two"))) .document(this.operationBuilder.build()); diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifierTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifierTests.java index 19bccefb..132b4c49 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifierTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifierTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -56,7 +56,7 @@ public class PrettyPrintingContentModifierTests { equalTo(String .format("%n" + "%n %n%n") - .getBytes())); + .getBytes())); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonFieldTypeResolverTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonFieldTypeResolverTests.java index 14ac262f..a95359ae 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonFieldTypeResolverTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonFieldTypeResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -262,10 +262,8 @@ public class JsonFieldTypeResolverTests { @Test public void intermediateWildcardWithVaryingType() throws IOException { - assertThat( - this.fieldTypeResolver.resolveFieldType(new FieldDescriptor("a.*.d"), - createPayload( - "{\"a\": {\"b\": {\"d\": 4}, \"c\": {\"d\": \"four\"}}}}")), + assertThat(this.fieldTypeResolver.resolveFieldType(new FieldDescriptor("a.*.d"), + createPayload("{\"a\": {\"b\": {\"d\": 4}, \"c\": {\"d\": \"four\"}}}}")), equalTo(JsonFieldType.VARIES)); } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestBodyPartSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestBodyPartSnippetTests.java index f19daee4..5ea5cd74 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestBodyPartSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestBodyPartSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -78,18 +78,12 @@ public class RequestBodyPartSnippetTests extends AbstractSnippetTests { TemplateResourceResolver resolver = mock(TemplateResourceResolver.class); given(resolver.resolveTemplateResource("request-part-body")) .willReturn(snippetResource("request-part-body-with-language")); - requestPartBody("one", - attributes( - key("language").value("json"))) - .document( - this.operationBuilder - .attribute(TemplateEngine.class.getName(), - new MustacheTemplateEngine( - resolver)) - .request("http://localhost") - .part("one", - "{\"a\":\"alpha\"}".getBytes()) - .build()); + requestPartBody("one", attributes(key("language").value("json"))) + .document(this.operationBuilder + .attribute(TemplateEngine.class.getName(), + new MustacheTemplateEngine(resolver)) + .request("http://localhost") + .part("one", "{\"a\":\"alpha\"}".getBytes()).build()); } } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestBodySnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestBodySnippetTests.java index e6bde76d..b9f66335 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestBodySnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestBodySnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -77,16 +77,12 @@ public class RequestBodySnippetTests extends AbstractSnippetTests { TemplateResourceResolver resolver = mock(TemplateResourceResolver.class); given(resolver.resolveTemplateResource("request-body")) .willReturn(snippetResource("request-body-with-language")); - requestBody( - attributes( - key("language").value("json"))) - .document( - this.operationBuilder - .attribute(TemplateEngine.class.getName(), - new MustacheTemplateEngine( - resolver)) - .request("http://localhost") - .content("{\"a\":\"alpha\"}").build()); + requestBody(attributes(key("language").value("json"))) + .document(this.operationBuilder + .attribute(TemplateEngine.class.getName(), + new MustacheTemplateEngine(resolver)) + .request("http://localhost").content("{\"a\":\"alpha\"}") + .build()); } } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetFailureTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetFailureTests.java index d4e83971..ee90a322 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetFailureTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetFailureTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -233,7 +233,7 @@ public class RequestFieldsSnippetFailureTests { this.operationBuilder.request("http://localhost") .content("{\"a\":[{\"b\": 1,\"c\": 2}, " + "{\"c\": 2}, {\"b\": 1,\"c\": 2}]}") - .build()); + .build()); } } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetTests.java index 923a0503..7fe022a2 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -118,7 +118,7 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests { .document(this.operationBuilder.request("http://localhost") .content("[{\"a\": {\"b\": 5, \"c\":\"charlie\"}}," + "{\"a\": {\"b\": 4, \"c\":\"chalk\"}}]") - .build()); + .build()); } @Test @@ -235,8 +235,8 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests { .willReturn(snippetResource("request-fields-with-title")); this.snippets.expectRequestFields().withContents(containsString("Custom title")); - new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")), - attributes( + new RequestFieldsSnippet( + Arrays.asList(fieldWithPath("a").description("one")), attributes( key("title").value("Custom title"))) .document( this.operationBuilder @@ -265,15 +265,13 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests { .attributes(key("foo").value("bravo")), fieldWithPath("a").description("three") .attributes(key("foo").value("charlie")))) - .document( - this.operationBuilder - .attribute(TemplateEngine.class.getName(), - new MustacheTemplateEngine( - resolver)) - .request("http://localhost") - .content( - "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}") - .build()); + .document(this.operationBuilder + .attribute(TemplateEngine.class.getName(), + new MustacheTemplateEngine(resolver)) + .request("http://localhost") + .content( + "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}") + .build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestPartFieldsSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestPartFieldsSnippetTests.java index 8a1334ee..f03b5cc1 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestPartFieldsSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestPartFieldsSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -48,17 +48,13 @@ public class RequestPartFieldsSnippetTests extends AbstractSnippetTests { .row("`a.b`", "`Number`", "one").row("`a.c`", "`String`", "two") .row("`a`", "`Object`", "three")); - new RequestPartFieldsSnippet("one", - Arrays.asList(fieldWithPath("a.b").description("one"), - fieldWithPath("a.c").description("two"), fieldWithPath("a") - .description("three"))) - .document( - this.operationBuilder - .request("http://localhost") - .part("one", - "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}" - .getBytes()) - .build()); + new RequestPartFieldsSnippet("one", Arrays.asList( + fieldWithPath("a.b").description("one"), + fieldWithPath("a.c").description("two"), + fieldWithPath("a").description("three"))).document(this.operationBuilder + .request("http://localhost") + .part("one", "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}".getBytes()) + .build()); } @Test @@ -67,17 +63,12 @@ public class RequestPartFieldsSnippetTests extends AbstractSnippetTests { .withContents(tableWithHeader("Path", "Type", "Description") .row("`b`", "`Number`", "one").row("`c`", "`String`", "two")); - new RequestPartFieldsSnippet("one", - beneathPath("a"), Arrays - .asList(fieldWithPath("b").description("one"), - fieldWithPath("c").description("two"))) - .document( - this.operationBuilder - .request("http://localhost") - .part("one", - "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}" - .getBytes()) - .build()); + new RequestPartFieldsSnippet("one", beneathPath("a"), Arrays.asList( + fieldWithPath("b").description("one"), + fieldWithPath("c").description("two"))).document(this.operationBuilder + .request("http://localhost") + .part("one", "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}".getBytes()) + .build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseBodySnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseBodySnippetTests.java index 2b42539c..d01bc396 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseBodySnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseBodySnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -77,16 +77,11 @@ public class ResponseBodySnippetTests extends AbstractSnippetTests { TemplateResourceResolver resolver = mock(TemplateResourceResolver.class); given(resolver.resolveTemplateResource("response-body")) .willReturn(snippetResource("response-body-with-language")); - responseBody( - attributes( - key("language").value("json"))) - .document( - this.operationBuilder - .attribute(TemplateEngine.class.getName(), - new MustacheTemplateEngine( - resolver)) - .response().content("{\"a\":\"alpha\"}") - .build()); + responseBody(attributes(key("language").value("json"))) + .document(this.operationBuilder + .attribute(TemplateEngine.class.getName(), + new MustacheTemplateEngine(resolver)) + .response().content("{\"a\":\"alpha\"}").build()); } } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetFailureTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetFailureTests.java index b88b25f2..3526a0ab 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetFailureTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetFailureTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -108,7 +108,7 @@ public class ResponseFieldsSnippetFailureTests { .content("foo") .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE) - .build()); + .build()); } @Test @@ -202,7 +202,7 @@ public class ResponseFieldsSnippetFailureTests { this.operationBuilder.response() .content("{\"a\":[{\"b\": 1,\"c\": 2}, " + "{\"c\": 2}, {\"b\": 1,\"c\": 2}]}") - .build()); + .build()); } } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java index 36d84aa2..43995020 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -121,7 +121,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests { Arrays.asList(fieldWithPath("[]a.b").description("one"))) .document(this.operationBuilder.response().content( "[{\"a\": {\"b\": null}}," + "{\"a\": {\"b\": null}}]") - .build()); + .build()); } @Test @@ -180,8 +180,8 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests { .willReturn(snippetResource("response-fields-with-title")); this.snippets.expectResponseFields().withContents(containsString("Custom title")); - new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")), - attributes( + new ResponseFieldsSnippet( + Arrays.asList(fieldWithPath("a").description("one")), attributes( key("title").value("Custom title"))) .document( this.operationBuilder @@ -241,15 +241,13 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests { .attributes(key("foo").value("bravo")), fieldWithPath("a").description("three") .attributes(key("foo").value("charlie")))) - .document( - this.operationBuilder - .attribute(TemplateEngine.class.getName(), - new MustacheTemplateEngine( - resolver)) - .response() - .content( - "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}") - .build()); + .document(this.operationBuilder + .attribute(TemplateEngine.class.getName(), + new MustacheTemplateEngine(resolver)) + .response() + .content( + "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}") + .build()); } @Test @@ -319,7 +317,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests { .content("foo") .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE) - .build()); + .build()); } @Test @@ -335,7 +333,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests { .content("foo") .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE) - .build()); + .build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java index b16a8a95..9a07feba 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -53,12 +53,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { tableWithTitleAndHeader(getTitle(), "Parameter", "Description") .row("`a`", "one").row("`b`", "two")); new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"), - parameterWithName("b").description("two"))) - .document(this.operationBuilder - .attribute( - RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, - "/{a}/{b}") - .build()); + parameterWithName("b").description("two"))).document(this.operationBuilder + .attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, + "/{a}/{b}") + .build()); } @Test @@ -67,12 +65,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("`b`", "two")); new PathParametersSnippet(Arrays.asList(parameterWithName("a").ignored(), - parameterWithName("b").description("two"))) - .document(this.operationBuilder - .attribute( - RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, - "/{a}/{b}") - .build()); + parameterWithName("b").description("two"))).document(this.operationBuilder + .attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, + "/{a}/{b}") + .build()); } @Test @@ -117,12 +113,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { tableWithTitleAndHeader(getTitle(), "Parameter", "Description") .row("`a`", "one").row("`b`", "two")); new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"), - parameterWithName("b").description("two"))) - .document(this.operationBuilder - .attribute( - RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, - "/{a}/{b}?foo=bar") - .build()); + parameterWithName("b").description("two"))).document(this.operationBuilder + .attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, + "/{a}/{b}?foo=bar") + .build()); } @Test @@ -131,12 +125,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { tableWithTitleAndHeader(getTitle(), "Parameter", "Description") .row("`a`", "one").row("`b`", "two")); new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"), - parameterWithName("b").description("two"))) - .document(this.operationBuilder - .attribute( - RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, - "/{a}/{b}?foo={c}") - .build()); + parameterWithName("b").description("two"))).document(this.operationBuilder + .attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, + "/{a}/{b}?foo={c}") + .build()); } @Test @@ -153,10 +145,9 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { parameterWithName("b").description("two") .attributes(key("foo").value("bravo"))), attributes(key("title").value("The title"))) - .document(this.operationBuilder - .attribute( - RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, - "/{a}/{b}") + .document(this.operationBuilder.attribute( + RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, + "/{a}/{b}") .attribute(TemplateEngine.class.getName(), new MustacheTemplateEngine(resolver)) .build()); @@ -175,15 +166,13 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { new PathParametersSnippet(Arrays.asList( parameterWithName("a").description("one") .attributes(key("foo").value("alpha")), - parameterWithName("b").description("two") - .attributes(key("foo").value("bravo")))) - .document(this.operationBuilder - .attribute( - RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, - "/{a}/{b}") - .attribute(TemplateEngine.class.getName(), - new MustacheTemplateEngine(resolver)) - .build()); + parameterWithName("b").description("two").attributes(key("foo") + .value("bravo")))).document(this.operationBuilder.attribute( + RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, + "/{a}/{b}") + .attribute(TemplateEngine.class.getName(), + new MustacheTemplateEngine(resolver)) + .build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java index ce2cc4d4..3aa98e02 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -117,22 +117,17 @@ public class RequestParametersSnippetTests extends AbstractSnippetTests { .willReturn(snippetResource("request-parameters-with-title")); this.snippets.expectRequestParameters().withContents(containsString("The title")); - new RequestParametersSnippet( - Arrays.asList( - parameterWithName("a").description("one") - .attributes(key("foo").value("alpha")), - parameterWithName("b").description("two") - .attributes(key("foo").value("bravo"))), - attributes( - key("title").value("The title"))) - .document( - this.operationBuilder - .attribute(TemplateEngine.class.getName(), - new MustacheTemplateEngine( - resolver)) - .request("http://localhost") - .param("a", "alpha").param("b", "bravo") - .build()); + new RequestParametersSnippet(Arrays.asList( + parameterWithName("a").description("one") + .attributes(key("foo").value("alpha")), + parameterWithName("b").description("two") + .attributes(key("foo").value("bravo"))), + attributes(key("title").value("The title"))) + .document(this.operationBuilder + .attribute(TemplateEngine.class.getName(), + new MustacheTemplateEngine(resolver)) + .request("http://localhost").param("a", "alpha") + .param("b", "bravo").build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestPartsSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestPartsSnippetTests.java index f49d299a..2c495400 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestPartsSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestPartsSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -108,22 +108,17 @@ public class RequestPartsSnippetTests extends AbstractSnippetTests { .willReturn(snippetResource("request-parts-with-title")); this.snippets.expectRequestParts().withContents(containsString("The title")); - new RequestPartsSnippet( - Arrays.asList( - partWithName("a").description("one") - .attributes(key("foo").value("alpha")), - partWithName("b").description("two") - .attributes(key("foo").value("bravo"))), - attributes( - key("title").value("The title"))) - .document( - this.operationBuilder - .attribute(TemplateEngine.class.getName(), - new MustacheTemplateEngine( - resolver)) - .request("http://localhost") - .part("a", "alpha".getBytes()).and() - .part("b", "bravo".getBytes()).build()); + new RequestPartsSnippet(Arrays.asList( + partWithName("a").description("one") + .attributes(key("foo").value("alpha")), + partWithName("b").description("two") + .attributes(key("foo").value("bravo"))), + attributes(key("title").value("The title"))) + .document(this.operationBuilder + .attribute(TemplateEngine.class.getName(), + new MustacheTemplateEngine(resolver)) + .request("http://localhost").part("a", "alpha".getBytes()) + .and().part("b", "bravo".getBytes()).build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/snippet/TemplatedSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/snippet/TemplatedSnippetTests.java index aea28d3c..af87277f 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/snippet/TemplatedSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/snippet/TemplatedSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -48,7 +48,8 @@ public class TemplatedSnippetTests { TemplateFormats.asciidoctor()); @Rule - public ExpectedSnippets snippets = new ExpectedSnippets(TemplateFormats.asciidoctor()); + public ExpectedSnippets snippets = new ExpectedSnippets( + TemplateFormats.asciidoctor()); @Test public void attributesAreCopied() { diff --git a/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRequestConverterTests.java b/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRequestConverterTests.java index 8b6c67eb..b0a2b5d9 100644 --- a/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRequestConverterTests.java +++ b/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRequestConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -93,9 +93,8 @@ public class MockMvcRequestConverterTests { @Test public void requestWithCookies() throws Exception { OperationRequest request = createOperationRequest( - MockMvcRequestBuilders.get("/foo") - .cookie(new javax.servlet.http.Cookie("cookieName1", - "cookieVal1"), + MockMvcRequestBuilders.get("/foo").cookie( + new javax.servlet.http.Cookie("cookieName1", "cookieVal1"), new javax.servlet.http.Cookie("cookieName2", "cookieVal2"))); assertThat(request.getUri(), is(URI.create("http://localhost/foo"))); assertThat(request.getMethod(), is(HttpMethod.GET)); diff --git a/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java b/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java index f4de4f3e..ea8ec5c6 100644 --- a/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java +++ b/spring-restdocs-mockmvc/src/test/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -159,9 +159,8 @@ public class MockMvcRestDocumentationIntegrationTests { mockMvc.perform(post("/").accept(MediaType.APPLICATION_JSON).content("content")) .andExpect(status().isOk()).andDo(document("curl-snippet-with-content")); - assertThat( - new File( - "build/generated-snippets/curl-snippet-with-content/curl-request.adoc"), + assertThat(new File( + "build/generated-snippets/curl-snippet-with-content/curl-request.adoc"), is(snippet(asciidoctor()) .withContents(codeBlock(asciidoctor(), "bash").content(String .format("$ curl 'http://localhost:8080/' -i -X POST \\%n" @@ -177,9 +176,8 @@ public class MockMvcRestDocumentationIntegrationTests { mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON) .cookie(new Cookie("cookieName", "cookieVal"))).andExpect(status().isOk()) .andDo(document("curl-snippet-with-cookies")); - assertThat( - new File( - "build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"), + assertThat(new File( + "build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"), is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash") .content(String.format("$ curl 'http://localhost:8080/' -i \\%n" + " -H 'Accept: application/json' \\%n" @@ -193,9 +191,8 @@ public class MockMvcRestDocumentationIntegrationTests { mockMvc.perform(post("/?foo=bar").param("foo", "bar").param("a", "alpha") .accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andDo(document("curl-snippet-with-query-string")); - assertThat( - new File( - "build/generated-snippets/curl-snippet-with-query-string/curl-request.adoc"), + assertThat(new File( + "build/generated-snippets/curl-snippet-with-query-string/curl-request.adoc"), is(snippet(asciidoctor()).withContents( codeBlock(asciidoctor(), "bash").content(String.format("$ curl " + "'http://localhost:8080/?foo=bar' -i -X POST \\%n" @@ -210,12 +207,11 @@ public class MockMvcRestDocumentationIntegrationTests { mockMvc.perform(post("/").param("a", "alpha").accept(MediaType.APPLICATION_JSON) .content("some content")).andExpect(status().isOk()) .andDo(document("curl-snippet-with-content-and-parameters")); - assertThat( - new File( - "build/generated-snippets/curl-snippet-with-content-and-parameters/curl-request.adoc"), - is(snippet(asciidoctor()) - .withContents(codeBlock(asciidoctor(), "bash").content(String - .format("$ curl 'http://localhost:8080/?a=alpha' -i -X POST \\%n" + assertThat(new File( + "build/generated-snippets/curl-snippet-with-content-and-parameters/curl-request.adoc"), + is(snippet(asciidoctor()).withContents( + codeBlock(asciidoctor(), "bash").content(String.format( + "$ curl 'http://localhost:8080/?a=alpha' -i -X POST \\%n" + " -H 'Accept: application/json' \\%n" + " -d 'some content'"))))); } @@ -228,9 +224,8 @@ public class MockMvcRestDocumentationIntegrationTests { mockMvc.perform(post("/").accept(MediaType.APPLICATION_JSON).content("content")) .andExpect(status().isOk()) .andDo(document("httpie-snippet-with-content")); - assertThat( - new File( - "build/generated-snippets/httpie-snippet-with-content/httpie-request.adoc"), + assertThat(new File( + "build/generated-snippets/httpie-snippet-with-content/httpie-request.adoc"), is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash") .content(String.format("$ echo 'content' | " + "http POST 'http://localhost:8080/' \\%n" @@ -245,9 +240,8 @@ public class MockMvcRestDocumentationIntegrationTests { mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON) .cookie(new Cookie("cookieName", "cookieVal"))).andExpect(status().isOk()) .andDo(document("httpie-snippet-with-cookies")); - assertThat( - new File( - "build/generated-snippets/httpie-snippet-with-cookies/httpie-request.adoc"), + assertThat(new File( + "build/generated-snippets/httpie-snippet-with-cookies/httpie-request.adoc"), is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash") .content(String.format("$ http GET 'http://localhost:8080/' \\%n" + " 'Accept:application/json' \\%n" @@ -261,11 +255,10 @@ public class MockMvcRestDocumentationIntegrationTests { mockMvc.perform(post("/?foo=bar").param("foo", "bar").param("a", "alpha") .accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andDo(document("httpie-snippet-with-query-string")); - assertThat( - new File( - "build/generated-snippets/httpie-snippet-with-query-string/httpie-request.adoc"), - is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), - "bash").content(String.format("$ http " + assertThat(new File( + "build/generated-snippets/httpie-snippet-with-query-string/httpie-request.adoc"), + is(snippet(asciidoctor()).withContents( + codeBlock(asciidoctor(), "bash").content(String.format("$ http " + "--form POST 'http://localhost:8080/?foo=bar' \\%n" + " 'Accept:application/json' \\%n 'a=alpha'"))))); } @@ -277,9 +270,8 @@ public class MockMvcRestDocumentationIntegrationTests { mockMvc.perform(post("/").param("a", "alpha").content("some content") .accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andDo(document("httpie-snippet-post-with-content-and-parameters")); - assertThat( - new File( - "build/generated-snippets/httpie-snippet-post-with-content-and-parameters/httpie-request.adoc"), + assertThat(new File( + "build/generated-snippets/httpie-snippet-post-with-content-and-parameters/httpie-request.adoc"), is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash") .content(String.format("$ echo " + "'some content' | http POST " + "'http://localhost:8080/?a=alpha' \\%n" @@ -486,9 +478,8 @@ public class MockMvcRestDocumentationIntegrationTests { } } String prettyPrinted = String.format("{%n \"a\" : \"<>\"%n}"); - assertThat( - new File( - "build/generated-snippets/preprocessed-request/http-request.adoc"), + assertThat(new File( + "build/generated-snippets/preprocessed-request/http-request.adoc"), is(snippet(asciidoctor()) .withContents(preprocessedRequest.content(prettyPrinted)))); } @@ -518,9 +509,8 @@ public class MockMvcRestDocumentationIntegrationTests { .content(original)))); String prettyPrinted = String.format("{%n \"a\" : \"<>\",%n \"links\" : " + "[ {%n \"rel\" : \"rel\",%n \"href\" : \"...\"%n } ]%n}"); - assertThat( - new File( - "build/generated-snippets/preprocessed-response/http-response.adoc"), + assertThat(new File( + "build/generated-snippets/preprocessed-response/http-response.adoc"), is(snippet(asciidoctor()) .withContents(httpResponse(asciidoctor(), HttpStatus.OK) .header("Content-Type", "application/json;charset=UTF-8") @@ -547,9 +537,8 @@ public class MockMvcRestDocumentationIntegrationTests { finally { Thread.currentThread().setContextClassLoader(previous); } - assertThat( - new File( - "build/generated-snippets/custom-snippet-template/curl-request.adoc"), + assertThat(new File( + "build/generated-snippets/custom-snippet-template/curl-request.adoc"), is(snippet(asciidoctor()).withContents(equalTo("Custom curl request")))); mockMvc.perform(get("/")).andDo(document("index", curlRequest( diff --git a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentationConfigurerTests.java b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentationConfigurerTests.java index fd7d3238..d7da2ae1 100644 --- a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentationConfigurerTests.java +++ b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentationConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -82,8 +82,8 @@ public class RestAssuredRestDocumentationConfigurerTests { assertThat(configuration, hasEntry(equalTo(WriterResolver.class.getName()), instanceOf(WriterResolver.class))); assertThat(configuration, - hasEntry( - equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS), + hasEntry(equalTo( + RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS), instanceOf(List.class))); } diff --git a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentationIntegrationTests.java b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentationIntegrationTests.java index 68eff6f7..09ea38bf 100644 --- a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentationIntegrationTests.java +++ b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -99,9 +99,8 @@ public class RestAssuredRestDocumentationIntegrationTests { .content("content").contentType(contentType).post("/").then() .statusCode(200); - assertThat( - new File( - "build/generated-snippets/curl-snippet-with-content/curl-request.adoc"), + assertThat(new File( + "build/generated-snippets/curl-snippet-with-content/curl-request.adoc"), is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash") .content(String.format("$ curl 'http://localhost:" + tomcat.getPort() + "/' -i -X POST \\%n" @@ -118,11 +117,10 @@ public class RestAssuredRestDocumentationIntegrationTests { .filter(document("curl-snippet-with-cookies")).accept("application/json") .contentType(contentType).cookie("cookieName", "cookieVal").get("/") .then().statusCode(200); - assertThat( - new File( - "build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"), - is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), - "bash").content(String.format("$ curl 'http://localhost:" + assertThat(new File( + "build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"), + is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash") + .content(String.format("$ curl 'http://localhost:" + tomcat.getPort() + "/' -i \\%n" + " -H 'Accept: application/json' \\%n" + " -H 'Content-Type: " + contentType + "' \\%n" @@ -137,9 +135,8 @@ public class RestAssuredRestDocumentationIntegrationTests { .accept("application/json").param("foo", "bar").param("a", "alpha") .post("/?foo=bar").then().statusCode(200); String contentType = "application/x-www-form-urlencoded; charset=ISO-8859-1"; - assertThat( - new File( - "build/generated-snippets/curl-snippet-with-query-string/curl-request.adoc"), + assertThat(new File( + "build/generated-snippets/curl-snippet-with-query-string/curl-request.adoc"), is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash") .content(String.format("$ curl " + "'http://localhost:" + tomcat.getPort() + "/?foo=bar' -i -X POST \\%n" @@ -317,9 +314,8 @@ public class RestAssuredRestDocumentationIntegrationTests { .header("Content-Length", "13") .content("{\"a\":\"alpha\"}")))); String prettyPrinted = String.format("{%n \"a\" : \"<>\"%n}"); - assertThat( - new File( - "build/generated-snippets/preprocessed-request/http-request.adoc"), + assertThat(new File( + "build/generated-snippets/preprocessed-request/http-request.adoc"), is(snippet(asciidoctor()) .withContents(httpRequest(asciidoctor(), RequestMethod.GET, "/") .header("b", "bravo") @@ -342,9 +338,8 @@ public class RestAssuredRestDocumentationIntegrationTests { .get("/").then().statusCode(200); String prettyPrinted = String.format("{%n \"a\" : \"<>\",%n \"links\" : " + "[ {%n \"rel\" : \"rel\",%n \"href\" : \"...\"%n } ]%n}"); - assertThat( - new File( - "build/generated-snippets/preprocessed-response/http-response.adoc"), + assertThat(new File( + "build/generated-snippets/preprocessed-response/http-response.adoc"), is(snippet(asciidoctor()) .withContents(httpResponse(asciidoctor(), HttpStatus.OK) .header("Foo", "https://api.example.com/foo/bar") @@ -370,9 +365,8 @@ public class RestAssuredRestDocumentationIntegrationTests { finally { Thread.currentThread().setContextClassLoader(previous); } - assertThat( - new File( - "build/generated-snippets/custom-snippet-template/curl-request.adoc"), + assertThat(new File( + "build/generated-snippets/custom-snippet-template/curl-request.adoc"), is(snippet(asciidoctor()).withContents(equalTo("Custom curl request")))); } diff --git a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/RestAssuredRestDocumentationConfigurerTests.java b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/RestAssuredRestDocumentationConfigurerTests.java index caafafa5..0c115dec 100644 --- a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/RestAssuredRestDocumentationConfigurerTests.java +++ b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/RestAssuredRestDocumentationConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -81,8 +81,8 @@ public class RestAssuredRestDocumentationConfigurerTests { assertThat(configuration, hasEntry(equalTo(WriterResolver.class.getName()), instanceOf(WriterResolver.class))); assertThat(configuration, - hasEntry( - equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS), + hasEntry(equalTo( + RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS), instanceOf(List.class))); } diff --git a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/RestAssuredRestDocumentationIntegrationTests.java b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/RestAssuredRestDocumentationIntegrationTests.java index b71a1504..fcd34094 100644 --- a/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/RestAssuredRestDocumentationIntegrationTests.java +++ b/spring-restdocs-restassured/src/test/java/org/springframework/restdocs/restassured3/RestAssuredRestDocumentationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -98,9 +98,8 @@ public class RestAssuredRestDocumentationIntegrationTests { .body("content").contentType(contentType).post("/").then() .statusCode(200); - assertThat( - new File( - "build/generated-snippets/curl-snippet-with-content/curl-request.adoc"), + assertThat(new File( + "build/generated-snippets/curl-snippet-with-content/curl-request.adoc"), is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash") .content(String.format("$ curl 'http://localhost:" + tomcat.getPort() + "/' -i -X POST \\%n" @@ -117,11 +116,10 @@ public class RestAssuredRestDocumentationIntegrationTests { .filter(document("curl-snippet-with-cookies")).accept("application/json") .contentType(contentType).cookie("cookieName", "cookieVal").get("/") .then().statusCode(200); - assertThat( - new File( - "build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"), - is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), - "bash").content(String.format("$ curl 'http://localhost:" + assertThat(new File( + "build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"), + is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash") + .content(String.format("$ curl 'http://localhost:" + tomcat.getPort() + "/' -i \\%n" + " -H 'Accept: application/json' \\%n" + " -H 'Content-Type: " + contentType + "' \\%n" @@ -136,9 +134,8 @@ public class RestAssuredRestDocumentationIntegrationTests { .accept("application/json").param("foo", "bar").param("a", "alpha") .post("/?foo=bar").then().statusCode(200); String contentType = "application/x-www-form-urlencoded; charset=ISO-8859-1"; - assertThat( - new File( - "build/generated-snippets/curl-snippet-with-query-string/curl-request.adoc"), + assertThat(new File( + "build/generated-snippets/curl-snippet-with-query-string/curl-request.adoc"), is(snippet(asciidoctor()).withContents(codeBlock(asciidoctor(), "bash") .content(String.format("$ curl " + "'http://localhost:" + tomcat.getPort() + "/?foo=bar' -i -X POST \\%n" @@ -316,9 +313,8 @@ public class RestAssuredRestDocumentationIntegrationTests { .header("Content-Length", "13") .content("{\"a\":\"alpha\"}")))); String prettyPrinted = String.format("{%n \"a\" : \"<>\"%n}"); - assertThat( - new File( - "build/generated-snippets/preprocessed-request/http-request.adoc"), + assertThat(new File( + "build/generated-snippets/preprocessed-request/http-request.adoc"), is(snippet(asciidoctor()) .withContents(httpRequest(asciidoctor(), RequestMethod.GET, "/") .header("b", "bravo") @@ -341,9 +337,8 @@ public class RestAssuredRestDocumentationIntegrationTests { .get("/").then().statusCode(200); String prettyPrinted = String.format("{%n \"a\" : \"<>\",%n \"links\" : " + "[ {%n \"rel\" : \"rel\",%n \"href\" : \"...\"%n } ]%n}"); - assertThat( - new File( - "build/generated-snippets/preprocessed-response/http-response.adoc"), + assertThat(new File( + "build/generated-snippets/preprocessed-response/http-response.adoc"), is(snippet(asciidoctor()) .withContents(httpResponse(asciidoctor(), HttpStatus.OK) .header("Foo", "https://api.example.com/foo/bar") @@ -369,9 +364,8 @@ public class RestAssuredRestDocumentationIntegrationTests { finally { Thread.currentThread().setContextClassLoader(previous); } - assertThat( - new File( - "build/generated-snippets/custom-snippet-template/curl-request.adoc"), + assertThat(new File( + "build/generated-snippets/custom-snippet-template/curl-request.adoc"), is(snippet(asciidoctor()).withContents(equalTo("Custom curl request")))); }