From bee5fa7fc625e3878523834240c4e85746b2cd0c Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 3 Jan 2018 11:41:27 -0800 Subject: [PATCH] Polish --- ...dryHealthWebEndpointAutoConfiguration.java | 4 +- .../WebMvcEndpointCorsIntegrationTests.java | 3 +- .../AutoConfigurationImportSelector.java | 7 +- .../autoconfigure/web/ResourceProperties.java | 4 +- ...aultServletWebServerFactoryCustomizer.java | 6 +- .../servlet/WelcomePageHandlerMapping.java | 7 +- .../SpringDataWebAutoConfigurationTests.java | 3 +- ...ConfigurationReactiveIntegrationTests.java | 52 ++-- .../FreeMarkerAutoConfigurationTests.java | 18 +- .../JacksonAutoConfigurationTests.java | 293 +++++++++++------- .../web/ResourcePropertiesTests.java | 4 +- .../infrastructure/CommandLineInvoker.java | 3 +- .../RepositoryConfigurationFactoryTests.java | 50 +-- ...rySystemSessionAutoConfigurationTests.java | 15 +- .../context/FilteredClassLoaderTests.java | 8 +- .../loader/data/RandomAccessDataFile.java | 4 +- .../jetty/JettyReactiveWebServerFactory.java | 8 +- .../jetty/JettyServletWebServerFactory.java | 14 +- .../embedded/jetty/SslServerCustomizer.java | 74 ++--- .../TomcatReactiveWebServerFactory.java | 2 +- .../tomcat/TomcatServletWebServerFactory.java | 2 +- .../UndertowReactiveWebServerFactory.java | 2 +- .../UndertowServletWebServerFactory.java | 2 +- .../boot/web/server/Http2.java | 2 +- 24 files changed, 334 insertions(+), 253 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryHealthWebEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryHealthWebEndpointAutoConfiguration.java index dd3b06c95e..a6d1bb810a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryHealthWebEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryHealthWebEndpointAutoConfiguration.java @@ -37,9 +37,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** - * {@link EnableAutoConfiguration Auto-configuration} for Cloud Foundry Health endpoint extensions. + * {@link EnableAutoConfiguration Auto-configuration} for Cloud Foundry Health endpoint + * extensions. * * @author Madhura Bhave + * @since 2.0.0 */ @Configuration @ConditionalOnCloudPlatform(CloudPlatform.CLOUD_FOUNDRY) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointCorsIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointCorsIntegrationTests.java index 323b9cadc2..52b63e64b0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointCorsIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointCorsIntegrationTests.java @@ -70,7 +70,8 @@ public class WebMvcEndpointCorsIntegrationTests { createMockMvc() .perform(options("/actuator/beans").header("Origin", "foo.example.com") .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET")) - .andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); + .andExpect( + header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java index ea983467ad..74731736ce 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -217,10 +217,11 @@ public class AutoConfigurationImportSelector private List getExcludeAutoConfigurationsProperty() { if (getEnvironment() instanceof ConfigurableEnvironment) { Binder binder = Binder.get(getEnvironment()); - return binder.bind(PROPERTY_NAME_AUTOCONFIGURE_EXCLUDE, String[].class).map(Arrays::asList) - .orElse(Collections.emptyList()); + return binder.bind(PROPERTY_NAME_AUTOCONFIGURE_EXCLUDE, String[].class) + .map(Arrays::asList).orElse(Collections.emptyList()); } - String[] excludes = getEnvironment().getProperty(PROPERTY_NAME_AUTOCONFIGURE_EXCLUDE, String[].class); + String[] excludes = getEnvironment() + .getProperty(PROPERTY_NAME_AUTOCONFIGURE_EXCLUDE, String[].class); return (excludes == null ? Collections.emptyList() : Arrays.asList(excludes)); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java index 7f916334fa..0fdf605249 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java @@ -487,8 +487,8 @@ public class ResourceProperties { return CacheControl.noCache(); } if (this.maxAge != null) { - return CacheControl - .maxAge(this.maxAge.getSeconds(), TimeUnit.SECONDS); + return CacheControl.maxAge(this.maxAge.getSeconds(), + TimeUnit.SECONDS); } return CacheControl.empty(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizer.java index 6421e82bfb..97c48878cd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DefaultServletWebServerFactoryCustomizer.java @@ -390,15 +390,13 @@ public class DefaultServletWebServerFactoryCustomizer } private static void customizeRedirectContextRoot( - TomcatServletWebServerFactory factory, - boolean redirectContextRoot) { + TomcatServletWebServerFactory factory, boolean redirectContextRoot) { factory.addContextCustomizers((context) -> context .setMapperContextRootRedirectEnabled(redirectContextRoot)); } private static void customizeUseRelativeRedirects( - TomcatServletWebServerFactory factory, - boolean useRelativeRedirects) { + TomcatServletWebServerFactory factory, boolean useRelativeRedirects) { factory.addContextCustomizers( (context) -> context.setUseRelativeRedirects(useRelativeRedirects)); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMapping.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMapping.java index 8fdfbade81..50f04d3700 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMapping.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMapping.java @@ -36,8 +36,8 @@ import org.springframework.web.servlet.mvc.ParameterizableViewController; /** * An {@link AbstractUrlHandlerMapping} for an application's welcome page. Supports both - * static and templated files. If both a static and templated index page are available, the - * static page is preferred. + * static and templated files. If both a static and templated index page are available, + * the static page is preferred. * * @author Andy Wilkinson * @author Bruce Brouwer @@ -46,7 +46,8 @@ final class WelcomePageHandlerMapping extends AbstractUrlHandlerMapping { private static final Log logger = LogFactory.getLog(WelcomePageHandlerMapping.class); - private static final List MEDIA_TYPES_ALL = Collections.singletonList(MediaType.ALL); + private static final List MEDIA_TYPES_ALL = Collections + .singletonList(MediaType.ALL); WelcomePageHandlerMapping(TemplateAvailabilityProviders templateAvailabilityProviders, ApplicationContext applicationContext, Optional welcomePage, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java index c2c8cd6d24..c6db99274f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java @@ -106,7 +106,8 @@ public class SpringDataWebAutoConfigurationTests { load(); PageableHandlerMethodArgumentResolver argumentResolver = this.context .getBean(PageableHandlerMethodArgumentResolver.class); - SpringDataWebProperties.Pageable properties = new SpringDataWebProperties().getPageable(); + SpringDataWebProperties.Pageable properties = new SpringDataWebProperties() + .getPageable(); assertThat(ReflectionTestUtils.getField(argumentResolver, "pageParameterName")) .isEqualTo(properties.getPageParameter()); assertThat(ReflectionTestUtils.getField(argumentResolver, "sizeParameterName")) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java index d39b1b3eb3..75a252ba59 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java @@ -69,46 +69,53 @@ public class FreeMarkerAutoConfigurationReactiveIntegrationTests { @Test public void customPrefix() { - this.contextRunner.withPropertyValues("spring.freemarker.prefix:prefix/").run(context -> { - MockServerWebExchange exchange = render(context, "prefixed"); - String result = exchange.getResponse().getBodyAsString().block(); - assertThat(result).contains("prefixed"); - }); + this.contextRunner.withPropertyValues("spring.freemarker.prefix:prefix/") + .run(context -> { + MockServerWebExchange exchange = render(context, "prefixed"); + String result = exchange.getResponse().getBodyAsString().block(); + assertThat(result).contains("prefixed"); + }); } @Test public void customSuffix() { - this.contextRunner.withPropertyValues("spring.freemarker.suffix:.freemarker").run(context -> { - MockServerWebExchange exchange = render(context, "suffixed"); - String result = exchange.getResponse().getBodyAsString().block(); - assertThat(result).contains("suffixed"); - }); + this.contextRunner.withPropertyValues("spring.freemarker.suffix:.freemarker") + .run(context -> { + MockServerWebExchange exchange = render(context, "suffixed"); + String result = exchange.getResponse().getBodyAsString().block(); + assertThat(result).contains("suffixed"); + }); } @Test public void customTemplateLoaderPath() { - this.contextRunner.withPropertyValues("spring.freemarker.templateLoaderPath:classpath:/custom-templates/").run(context -> { - MockServerWebExchange exchange = render(context, "custom"); - String result = exchange.getResponse().getBodyAsString().block(); - assertThat(result).contains("custom"); - }); + this.contextRunner + .withPropertyValues( + "spring.freemarker.templateLoaderPath:classpath:/custom-templates/") + .run(context -> { + MockServerWebExchange exchange = render(context, "custom"); + String result = exchange.getResponse().getBodyAsString().block(); + assertThat(result).contains("custom"); + }); } @SuppressWarnings("deprecation") @Test public void customFreeMarkerSettings() { - this.contextRunner.withPropertyValues("spring.freemarker.settings.boolean_format:yup,nope") - .run(context -> assertThat(context.getBean(FreeMarkerConfigurer.class).getConfiguration() - .getSetting("boolean_format")).isEqualTo("yup,nope")); + this.contextRunner + .withPropertyValues("spring.freemarker.settings.boolean_format:yup,nope") + .run(context -> assertThat(context.getBean(FreeMarkerConfigurer.class) + .getConfiguration().getSetting("boolean_format")) + .isEqualTo("yup,nope")); } @Test public void renderTemplate() { this.contextRunner.withPropertyValues().run(context -> { - FreeMarkerConfigurer freemarker = context - .getBean(FreeMarkerConfigurer.class); + FreeMarkerConfigurer freemarker = context.getBean(FreeMarkerConfigurer.class); StringWriter writer = new StringWriter(); - freemarker.getConfiguration().getTemplate("message.ftl").process(this, writer); + freemarker.getConfiguration().getTemplate("message.ftl").process(this, + writer); assertThat(writer.toString()).contains("Hello World"); }); } @@ -118,8 +125,7 @@ public class FreeMarkerAutoConfigurationReactiveIntegrationTests { } private MockServerWebExchange render(ApplicationContext context, String viewName) { - FreeMarkerViewResolver resolver = context - .getBean(FreeMarkerViewResolver.class); + FreeMarkerViewResolver resolver = context.getBean(FreeMarkerViewResolver.class); Mono view = resolver.resolveViewName(viewName, Locale.UK); MockServerWebExchange exchange = MockServerWebExchange .from(MockServerHttpRequest.get("/path")); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java index 5640e844da..d4cca1a9ad 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java @@ -60,9 +60,11 @@ public class FreeMarkerAutoConfigurationTests { @Test public void nonExistentTemplateLocation() { - this.contextRunner.withPropertyValues("spring.freemarker.templateLoaderPath:" - + "classpath:/does-not-exist/,classpath:/also-does-not-exist") - .run(context -> this.output.expect(containsString("Cannot find template location"))); + this.contextRunner + .withPropertyValues("spring.freemarker.templateLoaderPath:" + + "classpath:/does-not-exist/,classpath:/also-does-not-exist") + .run(context -> this.output + .expect(containsString("Cannot find template location"))); } @Test @@ -70,15 +72,17 @@ public class FreeMarkerAutoConfigurationTests { new File("target/test-classes/templates/empty-directory").mkdir(); this.contextRunner.withPropertyValues("spring.freemarker.templateLoaderPath:" + "classpath:/templates/empty-directory/").run(context -> { - }); + }); } @Test public void nonExistentLocationAndEmptyLocation() { new File("target/test-classes/templates/empty-directory").mkdir(); - this.contextRunner.withPropertyValues("spring.freemarker.templateLoaderPath:" - + "classpath:/does-not-exist/,classpath:/templates/empty-directory/").run(context -> { - }); + this.contextRunner + .withPropertyValues("spring.freemarker.templateLoaderPath:" + + "classpath:/does-not-exist/,classpath:/templates/empty-directory/") + .run(context -> { + }); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java index 01f9a23312..6699ad3215 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java @@ -90,11 +90,14 @@ public class JacksonAutoConfigurationTests { @Test public void doubleModuleRegistration() { - this.contextRunner.withUserConfiguration(DoubleModulesConfig.class).withConfiguration(AutoConfigurations.of( - HttpMessageConvertersAutoConfiguration.class)).run(context -> { - ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(mapper.writeValueAsString(new Foo())).isEqualTo("{\"foo\":\"bar\"}"); - }); + this.contextRunner.withUserConfiguration(DoubleModulesConfig.class) + .withConfiguration(AutoConfigurations + .of(HttpMessageConvertersAutoConfiguration.class)) + .run(context -> { + ObjectMapper mapper = context.getBean(ObjectMapper.class); + assertThat(mapper.writeValueAsString(new Foo())) + .isEqualTo("{\"foo\":\"bar\"}"); + }); } /* @@ -113,34 +116,42 @@ public class JacksonAutoConfigurationTests { @Test public void customDateFormat() { - this.contextRunner.withPropertyValues("spring.jackson.date-format:yyyyMMddHHmmss").run(context -> { - ObjectMapper mapper = context.getBean(ObjectMapper.class); - DateFormat dateFormat = mapper.getDateFormat(); - assertThat(dateFormat).isInstanceOf(SimpleDateFormat.class); - assertThat(((SimpleDateFormat) dateFormat).toPattern()) - .isEqualTo("yyyyMMddHHmmss"); - }); + this.contextRunner.withPropertyValues("spring.jackson.date-format:yyyyMMddHHmmss") + .run(context -> { + ObjectMapper mapper = context.getBean(ObjectMapper.class); + DateFormat dateFormat = mapper.getDateFormat(); + assertThat(dateFormat).isInstanceOf(SimpleDateFormat.class); + assertThat(((SimpleDateFormat) dateFormat).toPattern()) + .isEqualTo("yyyyMMddHHmmss"); + }); } @Test public void customJodaDateTimeFormat() throws Exception { - this.contextRunner.withPropertyValues("spring.jackson.date-format:yyyyMMddHHmmss", - "spring.jackson.joda-date-time-format:yyyy-MM-dd HH:mm:ss").run(context -> { - ObjectMapper mapper = context.getBean(ObjectMapper.class); - DateTime dateTime = new DateTime(1988, 6, 25, 20, 30, DateTimeZone.UTC); - assertThat(mapper.writeValueAsString(dateTime)) - .isEqualTo("\"1988-06-25 20:30:00\""); - Date date = dateTime.toDate(); - assertThat(mapper.writeValueAsString(date)).isEqualTo("\"19880625203000\""); - }); + this.contextRunner + .withPropertyValues("spring.jackson.date-format:yyyyMMddHHmmss", + "spring.jackson.joda-date-time-format:yyyy-MM-dd HH:mm:ss") + .run(context -> { + ObjectMapper mapper = context.getBean(ObjectMapper.class); + DateTime dateTime = new DateTime(1988, 6, 25, 20, 30, + DateTimeZone.UTC); + assertThat(mapper.writeValueAsString(dateTime)) + .isEqualTo("\"1988-06-25 20:30:00\""); + Date date = dateTime.toDate(); + assertThat(mapper.writeValueAsString(date)) + .isEqualTo("\"19880625203000\""); + }); } @Test public void customDateFormatClass() { - this.contextRunner.withPropertyValues("spring.jackson.date-format:org.springframework.boot.autoconfigure.jackson.JacksonAutoConfigurationTests.MyDateFormat").run(context -> { - ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(mapper.getDateFormat()).isInstanceOf(MyDateFormat.class); - }); + this.contextRunner + .withPropertyValues( + "spring.jackson.date-format:org.springframework.boot.autoconfigure.jackson.JacksonAutoConfigurationTests.MyDateFormat") + .run(context -> { + ObjectMapper mapper = context.getBean(ObjectMapper.class); + assertThat(mapper.getDateFormat()).isInstanceOf(MyDateFormat.class); + }); } @Test @@ -153,16 +164,20 @@ public class JacksonAutoConfigurationTests { @Test public void customPropertyNamingStrategyField() { - this.contextRunner.withPropertyValues("spring.jackson.property-naming-strategy:SNAKE_CASE").run(context -> { - ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(mapper.getPropertyNamingStrategy()) - .isInstanceOf(SnakeCaseStrategy.class); - }); + this.contextRunner + .withPropertyValues("spring.jackson.property-naming-strategy:SNAKE_CASE") + .run(context -> { + ObjectMapper mapper = context.getBean(ObjectMapper.class); + assertThat(mapper.getPropertyNamingStrategy()) + .isInstanceOf(SnakeCaseStrategy.class); + }); } @Test public void customPropertyNamingStrategyClass() { - this.contextRunner.withPropertyValues("spring.jackson.property-naming-strategy:com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy") + this.contextRunner + .withPropertyValues( + "spring.jackson.property-naming-strategy:com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); assertThat(mapper.getPropertyNamingStrategy()) @@ -172,123 +187,151 @@ public class JacksonAutoConfigurationTests { @Test public void enableSerializationFeature() { - this.contextRunner.withPropertyValues("spring.jackson.serialization.indent_output:true") + this.contextRunner + .withPropertyValues("spring.jackson.serialization.indent_output:true") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(SerializationFeature.INDENT_OUTPUT.enabledByDefault()).isFalse(); - assertThat(mapper.getSerializationConfig() - .hasSerializationFeatures(SerializationFeature.INDENT_OUTPUT.getMask())) - .isTrue(); + assertThat(SerializationFeature.INDENT_OUTPUT.enabledByDefault()) + .isFalse(); + assertThat(mapper.getSerializationConfig().hasSerializationFeatures( + SerializationFeature.INDENT_OUTPUT.getMask())).isTrue(); }); } @Test public void disableSerializationFeature() { - this.contextRunner.withPropertyValues("spring.jackson.serialization.write_dates_as_timestamps:false") + this.contextRunner + .withPropertyValues( + "spring.jackson.serialization.write_dates_as_timestamps:false") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS.enabledByDefault()) - .isTrue(); + assertThat(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS + .enabledByDefault()).isTrue(); assertThat(mapper.getSerializationConfig().hasSerializationFeatures( - SerializationFeature.WRITE_DATES_AS_TIMESTAMPS.getMask())).isFalse(); + SerializationFeature.WRITE_DATES_AS_TIMESTAMPS.getMask())) + .isFalse(); }); } @Test public void enableDeserializationFeature() { - this.contextRunner.withPropertyValues("spring.jackson.deserialization.use_big_decimal_for_floats:true") + this.contextRunner + .withPropertyValues( + "spring.jackson.deserialization.use_big_decimal_for_floats:true") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS.enabledByDefault()) - .isFalse(); - assertThat(mapper.getDeserializationConfig().hasDeserializationFeatures( - DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS.getMask())).isTrue(); + assertThat(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS + .enabledByDefault()).isFalse(); + assertThat( + mapper.getDeserializationConfig().hasDeserializationFeatures( + DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS + .getMask())).isTrue(); }); } @Test public void disableDeserializationFeature() { - this.contextRunner.withPropertyValues("spring.jackson.deserialization.fail-on-unknown-properties:false") + this.contextRunner + .withPropertyValues( + "spring.jackson.deserialization.fail-on-unknown-properties:false") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES.enabledByDefault()) - .isTrue(); - assertThat(mapper.getDeserializationConfig().hasDeserializationFeatures( - DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES.getMask())).isFalse(); + assertThat(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES + .enabledByDefault()).isTrue(); + assertThat( + mapper.getDeserializationConfig().hasDeserializationFeatures( + DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES + .getMask())).isFalse(); }); } @Test public void enableMapperFeature() { - this.contextRunner.withPropertyValues("spring.jackson.mapper.require_setters_for_getters:true") + this.contextRunner + .withPropertyValues( + "spring.jackson.mapper.require_setters_for_getters:true") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS.enabledByDefault()) - .isFalse(); - assertThat(mapper.getSerializationConfig() - .hasMapperFeatures(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS.getMask())) - .isTrue(); - assertThat(mapper.getDeserializationConfig() - .hasMapperFeatures(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS.getMask())) - .isTrue(); + assertThat( + MapperFeature.REQUIRE_SETTERS_FOR_GETTERS.enabledByDefault()) + .isFalse(); + assertThat(mapper.getSerializationConfig().hasMapperFeatures( + MapperFeature.REQUIRE_SETTERS_FOR_GETTERS.getMask())) + .isTrue(); + assertThat(mapper.getDeserializationConfig().hasMapperFeatures( + MapperFeature.REQUIRE_SETTERS_FOR_GETTERS.getMask())) + .isTrue(); }); } @Test public void disableMapperFeature() { - this.contextRunner.withPropertyValues("spring.jackson.mapper.use_annotations:false") + this.contextRunner + .withPropertyValues("spring.jackson.mapper.use_annotations:false") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); assertThat(MapperFeature.USE_ANNOTATIONS.enabledByDefault()).isTrue(); assertThat(mapper.getDeserializationConfig() - .hasMapperFeatures(MapperFeature.USE_ANNOTATIONS.getMask())).isFalse(); + .hasMapperFeatures(MapperFeature.USE_ANNOTATIONS.getMask())) + .isFalse(); assertThat(mapper.getSerializationConfig() - .hasMapperFeatures(MapperFeature.USE_ANNOTATIONS.getMask())).isFalse(); + .hasMapperFeatures(MapperFeature.USE_ANNOTATIONS.getMask())) + .isFalse(); }); } @Test public void enableParserFeature() { - this.contextRunner.withPropertyValues("spring.jackson.parser.allow_single_quotes:true") + this.contextRunner + .withPropertyValues("spring.jackson.parser.allow_single_quotes:true") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(JsonParser.Feature.ALLOW_SINGLE_QUOTES.enabledByDefault()).isFalse(); - assertThat(mapper.getFactory().isEnabled(JsonParser.Feature.ALLOW_SINGLE_QUOTES)) - .isTrue(); + assertThat(JsonParser.Feature.ALLOW_SINGLE_QUOTES.enabledByDefault()) + .isFalse(); + assertThat(mapper.getFactory() + .isEnabled(JsonParser.Feature.ALLOW_SINGLE_QUOTES)).isTrue(); }); } @Test public void disableParserFeature() { - this.contextRunner.withPropertyValues("spring.jackson.parser.auto_close_source:false") + this.contextRunner + .withPropertyValues("spring.jackson.parser.auto_close_source:false") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(JsonParser.Feature.AUTO_CLOSE_SOURCE.enabledByDefault()).isTrue(); - assertThat(mapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)) - .isFalse(); + assertThat(JsonParser.Feature.AUTO_CLOSE_SOURCE.enabledByDefault()) + .isTrue(); + assertThat(mapper.getFactory() + .isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)).isFalse(); }); } @Test public void enableGeneratorFeature() { - this.contextRunner.withPropertyValues("spring.jackson.generator.write_numbers_as_strings:true") + this.contextRunner + .withPropertyValues( + "spring.jackson.generator.write_numbers_as_strings:true") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS.enabledByDefault()) - .isFalse(); + assertThat(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS + .enabledByDefault()).isFalse(); assertThat(mapper.getFactory() - .isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS)).isTrue(); + .isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS)) + .isTrue(); }); } @Test public void disableGeneratorFeature() { - this.contextRunner.withPropertyValues("spring.jackson.generator.auto_close_target:false") + this.contextRunner + .withPropertyValues("spring.jackson.generator.auto_close_target:false") .run(context -> { ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(JsonGenerator.Feature.AUTO_CLOSE_TARGET.enabledByDefault()).isTrue(); - assertThat(mapper.getFactory().isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET)) - .isFalse(); + assertThat(JsonGenerator.Feature.AUTO_CLOSE_TARGET.enabledByDefault()) + .isTrue(); + assertThat(mapper.getFactory() + .isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET)) + .isFalse(); }); } @@ -306,18 +349,20 @@ public class JacksonAutoConfigurationTests { .isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse(); assertThat(mapper.getSerializationConfig() .isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse(); - assertThat(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES.enabledByDefault()) - .isTrue(); + assertThat( + DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES.enabledByDefault()) + .isTrue(); assertThat(mapper.getDeserializationConfig() - .isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)).isFalse(); + .isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) + .isFalse(); }); } @Test public void moduleBeansAndWellKnownModulesAreRegisteredWithTheObjectMapperBuilder() { this.contextRunner.withUserConfiguration(ModuleConfig.class).run(context -> { - ObjectMapper objectMapper = context - .getBean(Jackson2ObjectMapperBuilder.class).build(); + ObjectMapper objectMapper = context.getBean(Jackson2ObjectMapperBuilder.class) + .build(); assertThat(context.getBean(CustomModule.class).getOwners()) .contains((ObjectCodec) objectMapper); assertThat(objectMapper.canSerialize(LocalDateTime.class)).isTrue(); @@ -328,8 +373,8 @@ public class JacksonAutoConfigurationTests { @Test public void defaultSerializationInclusion() { this.contextRunner.run(context -> { - ObjectMapper objectMapper = context - .getBean(Jackson2ObjectMapperBuilder.class).build(); + ObjectMapper objectMapper = context.getBean(Jackson2ObjectMapperBuilder.class) + .build(); assertThat(objectMapper.getSerializationConfig().getDefaultPropertyInclusion() .getValueInclusion()).isEqualTo(JsonInclude.Include.USE_DEFAULTS); }); @@ -337,56 +382,65 @@ public class JacksonAutoConfigurationTests { @Test public void customSerializationInclusion() { - this.contextRunner.withPropertyValues("spring.jackson.default-property-inclusion:non_null") + this.contextRunner + .withPropertyValues("spring.jackson.default-property-inclusion:non_null") .run(context -> { ObjectMapper objectMapper = context .getBean(Jackson2ObjectMapperBuilder.class).build(); - assertThat(objectMapper.getSerializationConfig().getDefaultPropertyInclusion() - .getValueInclusion()).isEqualTo(JsonInclude.Include.NON_NULL); + assertThat(objectMapper.getSerializationConfig() + .getDefaultPropertyInclusion().getValueInclusion()) + .isEqualTo(JsonInclude.Include.NON_NULL); }); } @Test public void customTimeZoneFormattingADateTime() { - this.contextRunner.withPropertyValues("spring.jackson.time-zone:America/Los_Angeles", - "spring.jackson.date-format:zzzz", "spring.jackson.locale:en").run(context -> { - ObjectMapper objectMapper = context - .getBean(Jackson2ObjectMapperBuilder.class).build(); - DateTime dateTime = new DateTime(1436966242231L, DateTimeZone.UTC); - assertThat(objectMapper.writeValueAsString(dateTime)) - .isEqualTo("\"Pacific Daylight Time\""); - }); + this.contextRunner + .withPropertyValues("spring.jackson.time-zone:America/Los_Angeles", + "spring.jackson.date-format:zzzz", "spring.jackson.locale:en") + .run(context -> { + ObjectMapper objectMapper = context + .getBean(Jackson2ObjectMapperBuilder.class).build(); + DateTime dateTime = new DateTime(1436966242231L, DateTimeZone.UTC); + assertThat(objectMapper.writeValueAsString(dateTime)) + .isEqualTo("\"Pacific Daylight Time\""); + }); } @Test public void customTimeZoneFormattingADate() throws JsonProcessingException { this.contextRunner.withPropertyValues("spring.jackson.time-zone:GMT+10", "spring.jackson.date-format:z").run(context -> { - ObjectMapper objectMapper = context - .getBean(Jackson2ObjectMapperBuilder.class).build(); - Date date = new Date(1436966242231L); - assertThat(objectMapper.writeValueAsString(date)).isEqualTo("\"GMT+10:00\""); - }); + ObjectMapper objectMapper = context + .getBean(Jackson2ObjectMapperBuilder.class).build(); + Date date = new Date(1436966242231L); + assertThat(objectMapper.writeValueAsString(date)) + .isEqualTo("\"GMT+10:00\""); + }); } @Test public void customLocaleWithJodaTime() throws JsonProcessingException { - this.contextRunner.withPropertyValues("spring.jackson.locale:de_DE", "spring.jackson.date-format:zzzz", - "spring.jackson.serialization.write-dates-with-zone-id:true").run(context -> { - ObjectMapper objectMapper = context.getBean(ObjectMapper.class); - DateTime jodaTime = new DateTime(1478424650000L, - DateTimeZone.forID("Europe/Rome")); - assertThat(objectMapper.writeValueAsString(jodaTime)) - .startsWith("\"Mitteleuropäische "); - }); + this.contextRunner + .withPropertyValues("spring.jackson.locale:de_DE", + "spring.jackson.date-format:zzzz", + "spring.jackson.serialization.write-dates-with-zone-id:true") + .run(context -> { + ObjectMapper objectMapper = context.getBean(ObjectMapper.class); + DateTime jodaTime = new DateTime(1478424650000L, + DateTimeZone.forID("Europe/Rome")); + assertThat(objectMapper.writeValueAsString(jodaTime)) + .startsWith("\"Mitteleuropäische "); + }); } @Test public void additionalJacksonBuilderCustomization() { - this.contextRunner.withUserConfiguration(ObjectMapperBuilderCustomConfig.class).run(context -> { - ObjectMapper mapper = context.getBean(ObjectMapper.class); - assertThat(mapper.getDateFormat()).isInstanceOf(MyDateFormat.class); - }); + this.contextRunner.withUserConfiguration(ObjectMapperBuilderCustomConfig.class) + .run(context -> { + ObjectMapper mapper = context.getBean(ObjectMapper.class); + assertThat(mapper.getDateFormat()).isInstanceOf(MyDateFormat.class); + }); } @Test @@ -407,9 +461,9 @@ public class JacksonAutoConfigurationTests { ObjectMapper mapper = context.getBean(ObjectMapper.class); DateTime dateTime = new DateTime(1988, 6, 25, 20, 30, DateTimeZone.UTC); String expected = FormatConfig.DEFAULT_DATETIME_PRINTER.rawFormatter() - .withZone(DateTimeZone.UTC) - .print(dateTime); - assertThat(mapper.writeValueAsString(dateTime)).isEqualTo("\"" + expected + "\""); + .withZone(DateTimeZone.UTC).print(dateTime); + assertThat(mapper.writeValueAsString(dateTime)) + .isEqualTo("\"" + expected + "\""); }); } @@ -420,8 +474,8 @@ public class JacksonAutoConfigurationTests { .getBean(ObjectMapper.class).getDeserializationConfig(); AnnotationIntrospector annotationIntrospector = deserializationConfig .getAnnotationIntrospector().allIntrospectors().iterator().next(); - assertThat(ReflectionTestUtils.getField(annotationIntrospector, "creatorBinding")) - .isEqualTo(expectedMode); + assertThat(ReflectionTestUtils.getField(annotationIntrospector, + "creatorBinding")).isEqualTo(expectedMode); }); } @@ -465,8 +519,7 @@ public class JacksonAutoConfigurationTests { @Override public void serialize(Foo value, JsonGenerator jgen, - SerializerProvider provider) - throws IOException { + SerializerProvider provider) throws IOException { jgen.writeStartObject(); jgen.writeStringField("foo", "bar"); jgen.writeEndObject(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java index 83c117ad76..85aefd4415 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java @@ -74,8 +74,8 @@ public class ResourcePropertiesTests { @Test public void emptyCacheControl() { - CacheControl cacheControl = this.properties.getCache() - .getCachecontrol().toHttpCacheControl(); + CacheControl cacheControl = this.properties.getCache().getCachecontrol() + .toHttpCacheControl(); assertThat(cacheControl.getHeaderValue()).isNull(); } diff --git a/spring-boot-project/spring-boot-cli/src/it/java/org/springframework/boot/cli/infrastructure/CommandLineInvoker.java b/spring-boot-project/spring-boot-cli/src/it/java/org/springframework/boot/cli/infrastructure/CommandLineInvoker.java index 4bcb325a0c..5a992f8640 100644 --- a/spring-boot-project/spring-boot-cli/src/it/java/org/springframework/boot/cli/infrastructure/CommandLineInvoker.java +++ b/spring-boot-project/spring-boot-cli/src/it/java/org/springframework/boot/cli/infrastructure/CommandLineInvoker.java @@ -160,8 +160,7 @@ public final class CommandLineInvoker { private List getLines(StringBuffer buffer) { BufferedReader reader = new BufferedReader( new StringReader(buffer.toString())); - return reader.lines() - .filter((line) -> !line.startsWith("Picked up ")) + return reader.lines().filter((line) -> !line.startsWith("Picked up ")) .collect(Collectors.toList()); } diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactoryTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactoryTests.java index dacd7b9610..f5470ee253 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactoryTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactoryTests.java @@ -50,11 +50,12 @@ public class RepositoryConfigurationFactoryTests { public void snapshotRepositoriesDisabled() { TestPropertyValues.of("user.home:src/test/resources/maven-settings/basic", "disableSpringSnapshotRepos:true").applyToSystemProperties(() -> { - List repositoryConfiguration = RepositoryConfigurationFactory - .createDefaultRepositoryConfiguration(); - assertRepositoryConfiguration(repositoryConfiguration, "central", "local"); - return null; - }); + List repositoryConfiguration = RepositoryConfigurationFactory + .createDefaultRepositoryConfiguration(); + assertRepositoryConfiguration(repositoryConfiguration, "central", + "local"); + return null; + }); } @Test @@ -73,27 +74,32 @@ public class RepositoryConfigurationFactoryTests { @Test public void activeByPropertyProfileRepositories() { - TestPropertyValues.of("user.home:src/test/resources/maven-settings/active-profile-repositories", - "foo:bar").applyToSystemProperties(() -> { - List repositoryConfiguration = RepositoryConfigurationFactory - .createDefaultRepositoryConfiguration(); - assertRepositoryConfiguration(repositoryConfiguration, "central", "local", - "spring-snapshot", "spring-milestone", "active-by-property"); - return null; - }); + TestPropertyValues + .of("user.home:src/test/resources/maven-settings/active-profile-repositories", + "foo:bar") + .applyToSystemProperties(() -> { + List repositoryConfiguration = RepositoryConfigurationFactory + .createDefaultRepositoryConfiguration(); + assertRepositoryConfiguration(repositoryConfiguration, "central", + "local", "spring-snapshot", "spring-milestone", + "active-by-property"); + return null; + }); } @Test public void interpolationProfileRepositories() { - TestPropertyValues.of("user.home:src/test/resources/maven-settings/active-profile-repositories", - "interpolate:true").applyToSystemProperties(() -> { - List repositoryConfiguration = RepositoryConfigurationFactory - .createDefaultRepositoryConfiguration(); - assertRepositoryConfiguration(repositoryConfiguration, "central", "local", - "spring-snapshot", "spring-milestone", "interpolate-releases", - "interpolate-snapshots"); - return null; - }); + TestPropertyValues + .of("user.home:src/test/resources/maven-settings/active-profile-repositories", + "interpolate:true") + .applyToSystemProperties(() -> { + List repositoryConfiguration = RepositoryConfigurationFactory + .createDefaultRepositoryConfiguration(); + assertRepositoryConfiguration(repositoryConfiguration, "central", + "local", "spring-snapshot", "spring-milestone", + "interpolate-releases", "interpolate-snapshots"); + return null; + }); } private void assertRepositoryConfiguration( diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java index 8df861acd3..4ecfc8656a 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java @@ -74,8 +74,10 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests { return new SimpleLocalRepositoryManagerFactory().newInstance(session, localRepository); }); - TestPropertyValues.of("user.home:src/test/resources/maven-settings/property-interpolation", - "foo:bar").applyToSystemProperties(() -> { + TestPropertyValues + .of("user.home:src/test/resources/maven-settings/property-interpolation", + "foo:bar") + .applyToSystemProperties(() -> { new SettingsXmlRepositorySystemSessionAutoConfiguration().apply( session, SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem); @@ -89,11 +91,10 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests { final DefaultRepositorySystemSession session = MavenRepositorySystemUtils .newSession(); TestPropertyValues.of("user.home:" + userHome).applyToSystemProperties(() -> { - new SettingsXmlRepositorySystemSessionAutoConfiguration().apply( - session, - SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem); - return null; - }); + new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(session, + SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem); + return null; + }); RemoteRepository repository = new RemoteRepository.Builder("my-server", "default", "http://maven.example.com").build(); assertMirrorSelectorConfiguration(session, repository); diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/FilteredClassLoaderTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/FilteredClassLoaderTests.java index dcbc3a298b..bd7cb14dbf 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/FilteredClassLoaderTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/FilteredClassLoaderTests.java @@ -44,15 +44,11 @@ public class FilteredClassLoaderTests { @Test public void loadClassWhenFilteredOnClassShouldThrowClassNotFound() throws Exception { - FilteredClassLoader classLoader = new FilteredClassLoader( - FilteredClassLoaderTests.class); - try { + try (FilteredClassLoader classLoader = new FilteredClassLoader( + FilteredClassLoaderTests.class)) { this.thrown.expect(ClassNotFoundException.class); classLoader.loadClass(getClass().getName()); } - finally { - classLoader.close(); - } } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/data/RandomAccessDataFile.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/data/RandomAccessDataFile.java index a2f44cab3f..34a5f6b291 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/data/RandomAccessDataFile.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/data/RandomAccessDataFile.java @@ -64,8 +64,8 @@ public class RandomAccessDataFile implements RandomAccessData { throw new IllegalArgumentException("File must not be null"); } if (!file.exists()) { - throw new IllegalArgumentException(String.format( - "File %s must exist", file.getAbsolutePath())); + throw new IllegalArgumentException( + String.format("File %s must exist", file.getAbsolutePath())); } this.file = file; this.filePool = new FilePool(file, concurrentReads); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java index 83c2648c81..b9b82f8abe 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java @@ -99,8 +99,7 @@ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFact JettyReactiveWebServerFactory.logger .info("Server initialized with port: " + port); if (getSsl() != null && getSsl().isEnabled()) { - new SslServerCustomizer(port, getSsl(), getSslStoreProvider(), - getHttp2()).customize(server); + customizeSsl(server, port); } for (JettyServerCustomizer customizer : getServerCustomizers()) { customizer.customize(server); @@ -122,6 +121,11 @@ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFact return connector; } + private void customizeSsl(Server server, int port) { + new SslServerCustomizer(port, getSsl(), getSslStoreProvider(), getHttp2()) + .customize(server); + } + /** * Returns a Jetty {@link ThreadPool} that should be used by the {@link Server}. * @return a Jetty {@link ThreadPool} or {@code null} diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java index dda3a565a0..b0084fc743 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java @@ -153,8 +153,7 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor server.setHandler(addHandlerWrappers(context)); this.logger.info("Server initialized with port: " + port); if (getSsl() != null && getSsl().isEnabled()) { - new SslServerCustomizer(port, getSsl(), getSslStoreProvider(), - getHttp2()).customize(server); + customizeSsl(server, port); } for (JettyServerCustomizer customizer : getServerCustomizers()) { customizer.customize(server); @@ -214,6 +213,11 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor return handler; } + private void customizeSsl(Server server, int port) { + new SslServerCustomizer(port, getSsl(), getSslStoreProvider(), getHttp2()) + .customize(server); + } + /** * Configure the given Jetty {@link WebAppContext} for use. * @param context the context to configure @@ -419,9 +423,9 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor } /** - * Factory method called to create the {@link JettyWebServer}. Subclasses can - * override this method to return a different {@link JettyWebServer} or apply - * additional processing to the Jetty server. + * Factory method called to create the {@link JettyWebServer}. Subclasses can override + * this method to return a different {@link JettyWebServer} or apply additional + * processing to the Jetty server. * @param server the Jetty server. * @return a new {@link JettyWebServer} instance */ diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/SslServerCustomizer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/SslServerCustomizer.java index d34419d5d1..4f50d006b3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/SslServerCustomizer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/SslServerCustomizer.java @@ -58,7 +58,8 @@ class SslServerCustomizer implements JettyServerCustomizer { private final Http2 http2; - SslServerCustomizer(int port, Ssl ssl, SslStoreProvider sslStoreProvider, Http2 http2) { + SslServerCustomizer(int port, Ssl ssl, SslStoreProvider sslStoreProvider, + Http2 http2) { this.port = port; this.ssl = ssl; this.sslStoreProvider = sslStoreProvider; @@ -69,61 +70,64 @@ class SslServerCustomizer implements JettyServerCustomizer { public void customize(Server server) { SslContextFactory sslContextFactory = new SslContextFactory(); configureSsl(sslContextFactory, this.ssl, this.sslStoreProvider); - ServerConnector connector = createConnector(server, sslContextFactory, - this.port); - server.setConnectors(new Connector[] {connector}); + ServerConnector connector = createConnector(server, sslContextFactory, this.port); + server.setConnectors(new Connector[] { connector }); } - private ServerConnector createConnector(Server server, SslContextFactory sslContextFactory, int port) { + private ServerConnector createConnector(Server server, + SslContextFactory sslContextFactory, int port) { HttpConfiguration config = new HttpConfiguration(); config.setSendServerVersion(false); config.setSecureScheme("https"); config.setSecurePort(port); config.addCustomizer(new SecureRequestCustomizer()); - ServerConnector connector; - if (this.http2 != null && this.http2.getEnabled()) { - final boolean isAlpnPresent = ClassUtils - .isPresent("org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory", - getClass().getClassLoader()); - Assert.state(isAlpnPresent, - () -> "The 'org.eclipse.jetty:jetty-alpn-server' " + - "dependency is required for HTTP/2 support."); - final boolean isConscryptPresent = ClassUtils - .isPresent("org.conscrypt.Conscrypt", getClass().getClassLoader()); - Assert.state(isConscryptPresent, - () -> "The 'org.eclipse.jetty.http2:http2-server' and Conscrypt " + - "dependencies are required for HTTP/2 support."); - connector = createHttp2Connector(server, config, sslContextFactory); - } - else { - connector = createSslConnector(server, config, sslContextFactory); - } + ServerConnector connector = createServerConnector(server, sslContextFactory, + config); connector.setPort(port); return connector; } - private ServerConnector createSslConnector(Server server, HttpConfiguration config, - SslContextFactory sslContextFactory) { + private ServerConnector createServerConnector(Server server, + SslContextFactory sslContextFactory, HttpConfiguration config) { + if (this.http2 == null || !this.http2.isEnabled()) { + return createHttp11ServerConnector(server, config, sslContextFactory); + } + Assert.state(isAlpnPresent(), () -> "The 'org.eclipse.jetty:jetty-alpn-server' " + + "dependency is required for HTTP/2 support."); + Assert.state(isConscryptPresent(), + () -> "The 'org.eclipse.jetty.http2:http2-server' and Conscrypt " + + "dependencies are required for HTTP/2 support."); + return createHttp2ServerConnector(server, config, sslContextFactory); + } + + private ServerConnector createHttp11ServerConnector(Server server, + HttpConfiguration config, SslContextFactory sslContextFactory) { HttpConnectionFactory connectionFactory = new HttpConnectionFactory(config); SslConnectionFactory sslConnectionFactory = new SslConnectionFactory( sslContextFactory, HttpVersion.HTTP_1_1.asString()); - ServerConnector serverConnector = new ServerConnector(server, - sslConnectionFactory, connectionFactory); - return serverConnector; + return new ServerConnector(server, sslConnectionFactory, connectionFactory); + } + + private boolean isAlpnPresent() { + return ClassUtils.isPresent( + "org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory", null); + } + + private boolean isConscryptPresent() { + return ClassUtils.isPresent("org.conscrypt.Conscrypt", null); } - private ServerConnector createHttp2Connector(Server server, HttpConfiguration config, - SslContextFactory sslContextFactory) { + private ServerConnector createHttp2ServerConnector(Server server, + HttpConfiguration config, SslContextFactory sslContextFactory) { HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(config); ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory(); alpn.setDefaultProtocol("h2"); sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR); sslContextFactory.setProvider("Conscrypt"); - SslConnectionFactory ssl = new SslConnectionFactory( - sslContextFactory, alpn.getProtocol()); - ServerConnector http2Connector = new ServerConnector( - server, ssl, alpn, h2, new HttpConnectionFactory(config)); - return http2Connector; + SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, + alpn.getProtocol()); + return new ServerConnector(server, ssl, alpn, h2, + new HttpConnectionFactory(config)); } /** diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactory.java index 9d7fac6e68..978ca21136 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactory.java @@ -156,7 +156,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac private void customizeSsl(Connector connector) { new SslConnectorCustomizer(getSsl(), getSslStoreProvider()).customize(connector); - if (getHttp2() != null && getHttp2().getEnabled()) { + if (getHttp2() != null && getHttp2().isEnabled()) { connector.addUpgradeProtocol(new Http2Protocol()); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java index bb776e7f43..3221efb238 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java @@ -323,7 +323,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto private void customizeSsl(Connector connector) { new SslConnectorCustomizer(getSsl(), getSslStoreProvider()).customize(connector); - if (getHttp2() != null && getHttp2().getEnabled()) { + if (getHttp2() != null && getHttp2().isEnabled()) { connector.addUpgradeProtocol(new Http2Protocol()); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java index ea5d64ce29..61a6300fd6 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java @@ -103,7 +103,7 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF .customize(builder); if (getHttp2() != null) { builder.setServerOption(UndertowOptions.ENABLE_HTTP2, - getHttp2().getEnabled()); + getHttp2().isEnabled()); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java index 7be903e488..e8003f5d6f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java @@ -248,7 +248,7 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac .customize(builder); if (getHttp2() != null) { builder.setServerOption(UndertowOptions.ENABLE_HTTP2, - getHttp2().getEnabled()); + getHttp2().isEnabled()); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/Http2.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/Http2.java index ec0acb9ab2..cec91c5a42 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/Http2.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/Http2.java @@ -29,7 +29,7 @@ public class Http2 { */ private boolean enabled = false; - public boolean getEnabled() { + public boolean isEnabled() { return this.enabled; }