From 276a1807c7bceed73c6f015045016179927e7cd7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 26 Oct 2017 16:10:42 +0100 Subject: [PATCH] Polish --- .../headers/ResponseHeadersSnippetTests.java | 6 +-- .../hypermedia/LinksSnippetTests.java | 29 +++++----- .../RequestPartFieldsSnippetTests.java | 4 +- .../request/PathParametersSnippetTests.java | 53 ++++++++----------- .../RequestParametersSnippetTests.java | 11 ++-- .../request/RequestPartsSnippetTests.java | 11 ++-- .../snippet/TemplatedSnippetTests.java | 3 +- 7 files changed, 57 insertions(+), 60 deletions(-) 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..e761ff29 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 @@ -91,7 +91,8 @@ 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")); @@ -132,8 +133,7 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests { .response().header("X-Test", "test") .header("Content-Type", "application/json") - .header("Etag", "lskjadldj3ii32l2ij23") - .build()); + .header("Etag", "lskjadldj3ii32l2ij23").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..89ed0b40 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 @@ -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")), @@ -146,28 +148,31 @@ public class LinksSnippetTests extends AbstractSnippetTests { .attributes(key("foo").value("alpha")), new LinkDescriptor("b").description("two") .attributes(key("foo").value("bravo")))) - .document(this.operationBuilder.attribute( - TemplateEngine.class.getName(), + .document(this.operationBuilder + .attribute(TemplateEngine.class + .getName(), new MustacheTemplateEngine(resolver)) - .build()); + .build()); } @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")), - new LinkDescriptor("a").description("one")) + new LinkDescriptor("a").description("one")) .and(new LinkDescriptor("b").description("two")) .document(this.operationBuilder.build()); } @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/payload/RequestPartFieldsSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestPartFieldsSnippetTests.java index 8a1334ee..685655b1 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 @@ -58,7 +58,7 @@ public class RequestPartFieldsSnippetTests extends AbstractSnippetTests { .part("one", "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}" .getBytes()) - .build()); + .build()); } @Test @@ -77,7 +77,7 @@ public class RequestPartFieldsSnippetTests extends AbstractSnippetTests { .part("one", "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}" .getBytes()) - .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..404efcef 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 @@ -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 @@ -81,10 +77,11 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("`b`", "two")); new PathParametersSnippet( - Arrays.asList(parameterWithName("b").description("two")), true) - .document(this.operationBuilder.attribute( - RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, - "/{a}/{b}").build()); + Arrays.asList(parameterWithName("b").description("two")), + true).document(this.operationBuilder + .attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, + "/{a}/{b}") + .build()); } @Test @@ -117,12 +114,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 +126,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 @@ -150,8 +143,8 @@ public class PathParametersSnippetTests extends AbstractSnippetTests { Arrays.asList( parameterWithName("a").description("one") .attributes(key("foo").value("alpha")), - parameterWithName("b").description("two") - .attributes(key("foo").value("bravo"))), + parameterWithName("b").description("two") + .attributes(key("foo").value("bravo"))), attributes(key("title").value("The title"))) .document(this.operationBuilder .attribute( 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..9234cae9 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 @@ -117,12 +117,11 @@ 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"))), + 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( 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..e106e886 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 @@ -108,12 +108,11 @@ 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"))), + 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( 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..d8999104 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 @@ -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() {