From 8e783cdae9653b46803a0ca6f07a53e9557855a4 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 18 Jan 2018 21:41:43 -0800 Subject: [PATCH] Polish --- .../ServerPropertiesAutoConfiguration.java | 15 ++++----- .../pom.xml | 6 ++-- ...onfigurationProcessorIntegrationTests.java | 8 ++--- ...ateJsonObjectContextCustomizerFactory.java | 7 ++-- .../configurationprocessor/TypeUtils.java | 32 ++++++++++--------- ...ationMetadataAnnotationProcessorTests.java | 16 +++++----- .../simple/SimpleCollectionProperties.java | 1 + ...erviceLocatorApplicationListenerTests.java | 7 ++-- 8 files changed, 47 insertions(+), 45 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java index fd8d321f97..3b2ae957a9 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.web; +import reactor.core.support.Assert; + import org.springframework.beans.BeansException; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -80,14 +82,11 @@ public class ServerPropertiesAutoConfiguration { // a single bean String[] serverPropertiesBeans = this.applicationContext .getBeanNamesForType(ServerProperties.class); - if (serverPropertiesBeans.length == 0) { - throw new IllegalStateException("No ServerProperties bean registered"); - } - if (serverPropertiesBeans.length > 1) { - throw new IllegalStateException( - "Multiple ServerProperties beans registered " + StringUtils - .arrayToCommaDelimitedString(serverPropertiesBeans)); - } + Assert.state(serverPropertiesBeans.length != 0, + "No ServerProperties registered"); + Assert.state(serverPropertiesBeans.length == 1, + "Multiple ServerProperties registered " + StringUtils + .arrayToCommaDelimitedString(serverPropertiesBeans)); } } diff --git a/spring-boot-integration-tests/spring-boot-configuration-processor-tests/pom.xml b/spring-boot-integration-tests/spring-boot-configuration-processor-tests/pom.xml index b53545a47d..e2d2a10466 100644 --- a/spring-boot-integration-tests/spring-boot-configuration-processor-tests/pom.xml +++ b/spring-boot-integration-tests/spring-boot-configuration-processor-tests/pom.xml @@ -1,7 +1,6 @@ - + 4.0.0 org.springframework.boot @@ -34,7 +33,6 @@ 2.0.1.Final - org.springframework.boot spring-boot-configuration-processor diff --git a/spring-boot-integration-tests/spring-boot-configuration-processor-tests/src/test/java/org/springframework/boot/configurationprocessor/tests/ConfigurationProcessorIntegrationTests.java b/spring-boot-integration-tests/spring-boot-configuration-processor-tests/src/test/java/org/springframework/boot/configurationprocessor/tests/ConfigurationProcessorIntegrationTests.java index 8c65e06790..8190981640 100644 --- a/spring-boot-integration-tests/spring-boot-configuration-processor-tests/src/test/java/org/springframework/boot/configurationprocessor/tests/ConfigurationProcessorIntegrationTests.java +++ b/spring-boot-integration-tests/spring-boot-configuration-processor-tests/src/test/java/org/springframework/boot/configurationprocessor/tests/ConfigurationProcessorIntegrationTests.java @@ -44,8 +44,8 @@ public class ConfigurationProcessorIntegrationTests { "META-INF/spring-configuration-metadata.json"); assertThat(resource.exists()).isTrue(); // Make sure the right file is detected - assertThat(resource.getURL().toString()).contains( - "spring-boot-configuration-processor-tests"); + assertThat(resource.getURL().toString()) + .contains("spring-boot-configuration-processor-tests"); repository = ConfigurationMetadataRepositoryJsonBuilder .create(resource.getInputStream()).build(); @@ -53,8 +53,8 @@ public class ConfigurationProcessorIntegrationTests { @Test public void extractTypeFromAnnotatedGetter() { - ConfigurationMetadataProperty property = repository.getAllProperties().get( - "annotated.name"); + ConfigurationMetadataProperty property = repository.getAllProperties() + .get("annotated.name"); assertThat(property).isNotNull(); assertThat(property.getType()).isEqualTo("java.lang.String"); } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactory.java b/spring-boot-test/src/main/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactory.java index 64adf73954..9523e2959d 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactory.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-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. @@ -75,8 +75,9 @@ class DuplicateJsonObjectContextCustomizerFactory implements ContextCustomizerFa } private void logDuplicateJsonObjectsWarning(List jsonObjects) { - StringBuilder message = new StringBuilder(String.format("%n%nFound multiple occurrences of" - + " org.json.JSONObject on the class path:%n%n")); + StringBuilder message = new StringBuilder( + String.format("%n%nFound multiple occurrences of" + + " org.json.JSONObject on the class path:%n%n")); for (URL jsonObject : jsonObjects) { message.append(String.format("\t%s%n", jsonObject)); } diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java index 2b6b0a2b6a..d831184454 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java @@ -168,7 +168,6 @@ class TypeUtils { return WRAPPER_TO_PRIMITIVE.get(type.toString()); } - /** * A visitor that extracts the full qualified name of a type, including generic * information. @@ -188,21 +187,24 @@ class TypeUtils { return getQualifiedName(enclosingElement) + "$" + type.asElement().getSimpleName().toString(); } - StringBuilder sb = new StringBuilder(); - sb.append(getQualifiedName(type.asElement())); + StringBuilder name = new StringBuilder(); + name.append(getQualifiedName(type.asElement())); if (!type.getTypeArguments().isEmpty()) { - sb.append("<"); - Iterator it = type.getTypeArguments().iterator(); - while (it.hasNext()) { - sb.append(it.next()); - if (it.hasNext()) { - sb.append(","); - } - } - sb.append(">"); - + appendTypeArguments(type, name); } - return sb.toString(); + return name.toString(); + } + + private void appendTypeArguments(DeclaredType type, StringBuilder name) { + name.append("<"); + Iterator iterator = type.getTypeArguments().iterator(); + while (iterator.hasNext()) { + name.append(iterator.next()); + if (iterator.hasNext()) { + name.append(","); + } + } + name.append(">"); } @Override @@ -223,7 +225,7 @@ class TypeUtils { if (enclosingElement != null) { return getQualifiedName(enclosingElement) + "$" + ((DeclaredType) element.asType()).asElement().getSimpleName() - .toString(); + .toString(); } if (element instanceof TypeElement) { return ((TypeElement) element).getQualifiedName().toString(); diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index 74dddf6f47..edbaaef161 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -261,12 +261,12 @@ public class ConfigurationMetadataAnnotationProcessorTests { @Test public void parseArrayConfig() throws Exception { ConfigurationMetadata metadata = compile(SimpleArrayProperties.class); - assertThat(metadata).has(Metadata.withGroup("array") - .ofType(SimpleArrayProperties.class)); - assertThat(metadata).has(Metadata.withProperty("array.primitive", - "java.lang.Integer[]")); - assertThat(metadata).has(Metadata.withProperty("array.simple", - "java.lang.String[]")); + assertThat(metadata) + .has(Metadata.withGroup("array").ofType(SimpleArrayProperties.class)); + assertThat(metadata) + .has(Metadata.withProperty("array.primitive", "java.lang.Integer[]")); + assertThat(metadata) + .has(Metadata.withProperty("array.simple", "java.lang.String[]")); assertThat(metadata).has(Metadata.withProperty("array.inner", "org.springframework.boot.configurationsample.simple.SimpleArrayProperties$Holder[]")); assertThat(metadata).has(Metadata.withProperty("array.name-to-integer", @@ -464,8 +464,8 @@ public class ConfigurationMetadataAnnotationProcessorTests { @Test public void wildcardTypes() throws IOException { ConfigurationMetadata metadata = compile(WildcardConfig.class); - assertThat(metadata).has(Metadata.withGroup("wildcard") - .ofType(WildcardConfig.class)); + assertThat(metadata) + .has(Metadata.withGroup("wildcard").ofType(WildcardConfig.class)); assertThat(metadata).has(Metadata.withProperty("wildcard.string-to-number") .ofType("java.util.Map") .fromSource(WildcardConfig.class)); diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/SimpleCollectionProperties.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/SimpleCollectionProperties.java index 732129ae4c..91f0207102 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/SimpleCollectionProperties.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/SimpleCollectionProperties.java @@ -89,6 +89,7 @@ public class SimpleCollectionProperties { public static class Holder { + @SuppressWarnings("unused") private T target; public void setTarget(T target) { diff --git a/spring-boot/src/test/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListenerTests.java index 2d3eb5bfc7..8d03f153b1 100644 --- a/spring-boot/src/test/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/liquibase/LiquibaseServiceLocatorApplicationListenerTests.java @@ -68,8 +68,8 @@ public class LiquibaseServiceLocatorApplicationListenerTests { SpringApplication application = new SpringApplication(Conf.class); application.setWebEnvironment(false); DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); - resourceLoader.setClassLoader(new ClassHidingClassLoader( - CustomResolverServiceLocator.class)); + resourceLoader.setClassLoader( + new ClassHidingClassLoader(CustomResolverServiceLocator.class)); application.setResourceLoader(resourceLoader); this.context = application.run(); Object resolver = getServiceLocator(); @@ -93,7 +93,8 @@ public class LiquibaseServiceLocatorApplicationListenerTests { private final List> hiddenClasses; private ClassHidingClassLoader(Class... hiddenClasses) { - super(new URL[0], LiquibaseServiceLocatorApplicationListenerTests.class.getClassLoader()); + super(new URL[0], LiquibaseServiceLocatorApplicationListenerTests.class + .getClassLoader()); this.hiddenClasses = Arrays.asList(hiddenClasses); }