From 25883b5510019c3f68b78f796a01869850a5eae2 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Wed, 25 Jul 2018 14:05:46 +0900 Subject: [PATCH] Polish --- .../payload/AbstractFieldsSnippet.java | 9 +++------ .../payload/PayloadDocumentation.java | 9 +++------ .../payload/JsonContentHandlerTests.java | 19 ++++++++----------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java index cf5ac1240..c10b432ae 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java @@ -342,12 +342,9 @@ private FieldDescriptor copyWithType(FieldDescriptor source, Object type) { } private static Attribute[] asArray(Map attributeMap) { - List attributes = new ArrayList<>(); - for (Map.Entry attribute : attributeMap.entrySet()) { - attributes - .add(Attributes.key(attribute.getKey()).value(attribute.getValue())); - } - return attributes.toArray(new Attribute[attributes.size()]); + return attributeMap.entrySet().stream() + .map((attribute) -> Attributes.key(attribute.getKey()).value(attribute.getValue())) + .toArray(Attribute[]::new); } } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/PayloadDocumentation.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/PayloadDocumentation.java index 7ecbf9ebc..52ada666d 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/PayloadDocumentation.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/PayloadDocumentation.java @@ -1644,12 +1644,9 @@ public static PayloadSubsectionExtractor beneathPath(String path) { } private static Attribute[] asArray(Map attributeMap) { - List attributes = new ArrayList<>(); - for (Map.Entry attribute : attributeMap.entrySet()) { - attributes - .add(Attributes.key(attribute.getKey()).value(attribute.getValue())); - } - return attributes.toArray(new Attribute[attributes.size()]); + return attributeMap.entrySet().stream() + .map((attribute) -> Attributes.key(attribute.getKey()).value(attribute.getValue())) + .toArray(Attribute[]::new); } } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonContentHandlerTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonContentHandlerTests.java index 4040300a6..dd043a237 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonContentHandlerTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/JsonContentHandlerTests.java @@ -16,7 +16,6 @@ package org.springframework.restdocs.payload; -import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -39,14 +38,14 @@ public class JsonContentHandlerTests { public ExpectedException thrown = ExpectedException.none(); @Test - public void typeForFieldWithNullValueMustMatch() throws IOException { + public void typeForFieldWithNullValueMustMatch() { this.thrown.expect(FieldTypesDoNotMatchException.class); new JsonContentHandler("{\"a\": null}".getBytes()) .determineFieldType(new FieldDescriptor("a").type(JsonFieldType.STRING)); } @Test - public void typeForFieldWithNotNullAndThenNullValueMustMatch() throws IOException { + public void typeForFieldWithNotNullAndThenNullValueMustMatch() { this.thrown.expect(FieldTypesDoNotMatchException.class); new JsonContentHandler("{\"a\":[{\"id\":1},{\"id\":null}]}".getBytes()) .determineFieldType( @@ -54,7 +53,7 @@ public void typeForFieldWithNotNullAndThenNullValueMustMatch() throws IOExceptio } @Test - public void typeForFieldWithNullAndThenNotNullValueMustMatch() throws IOException { + public void typeForFieldWithNullAndThenNotNullValueMustMatch() { this.thrown.expect(FieldTypesDoNotMatchException.class); new JsonContentHandler("{\"a\":[{\"id\":null},{\"id\":1}]}".getBytes()) .determineFieldType( @@ -62,8 +61,7 @@ public void typeForFieldWithNullAndThenNotNullValueMustMatch() throws IOExceptio } @Test - public void typeForOptionalFieldWithNumberAndThenNullValueIsNumber() - throws IOException { + public void typeForOptionalFieldWithNumberAndThenNullValueIsNumber() { Object fieldType = new JsonContentHandler( "{\"a\":[{\"id\":1},{\"id\":null}]}\"".getBytes()) .determineFieldType(new FieldDescriptor("a[].id").optional()); @@ -71,7 +69,7 @@ public void typeForOptionalFieldWithNumberAndThenNullValueIsNumber() } @Test - public void typeForOptionalFieldWithNullAndThenNumberIsNumber() throws IOException { + public void typeForOptionalFieldWithNullAndThenNumberIsNumber() { Object fieldType = new JsonContentHandler( "{\"a\":[{\"id\":null},{\"id\":1}]}".getBytes()) .determineFieldType(new FieldDescriptor("a[].id").optional()); @@ -79,7 +77,7 @@ public void typeForOptionalFieldWithNullAndThenNumberIsNumber() throws IOExcepti } @Test - public void typeForFieldWithNumberAndThenNullValueIsVaries() throws IOException { + public void typeForFieldWithNumberAndThenNullValueIsVaries() { Object fieldType = new JsonContentHandler( "{\"a\":[{\"id\":1},{\"id\":null}]}\"".getBytes()) .determineFieldType(new FieldDescriptor("a[].id")); @@ -87,7 +85,7 @@ public void typeForFieldWithNumberAndThenNullValueIsVaries() throws IOException } @Test - public void typeForFieldWithNullAndThenNumberIsVaries() throws IOException { + public void typeForFieldWithNullAndThenNumberIsVaries() { Object fieldType = new JsonContentHandler( "{\"a\":[{\"id\":null},{\"id\":1}]}".getBytes()) .determineFieldType(new FieldDescriptor("a[].id")); @@ -95,8 +93,7 @@ public void typeForFieldWithNullAndThenNumberIsVaries() throws IOException { } @Test - public void typeForOptionalFieldWithNullValueCanBeProvidedExplicitly() - throws IOException { + public void typeForOptionalFieldWithNullValueCanBeProvidedExplicitly() { Object fieldType = new JsonContentHandler("{\"a\": null}".getBytes()) .determineFieldType( new FieldDescriptor("a").type(JsonFieldType.STRING).optional());