From 2c7dd9f51903f9e0f3b553ddb8a13577ef320312 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 2 Jun 2017 16:00:24 -0700 Subject: [PATCH] Polish --- ...InfoContributorAutoConfigurationTests.java | 2 +- .../AutoConfigurationReportEndpointTests.java | 2 +- .../endpoint/mvc/LoggersMvcEndpointTests.java | 3 +- .../web/SpringDataWebAutoConfiguration.java | 16 +-- .../influx/InfluxDbAutoConfiguration.java | 6 +- .../autoconfigure/influx/package-info.java | 2 +- .../jdbc/JdbcTemplateAutoConfiguration.java | 3 +- .../autoconfigure/jooq/JooqProperties.java | 2 +- .../mongo/ReactiveMongoClientFactory.java | 115 +++++++++++------- .../condition/AllNestedConditionsTests.java | 2 +- .../condition/AnyNestedConditionTests.java | 2 +- .../ConditionalOnCloudPlatformTests.java | 2 +- .../condition/ConditionalOnResourceTests.java | 2 +- .../condition/NoneNestedConditionsTests.java | 2 +- ...ationPropertiesAutoConfigurationTests.java | 2 +- .../OnBootstrapHostsConditionTests.java | 2 +- ...asticsearchDataAutoConfigurationTests.java | 14 +-- ...va => InfluxDbAutoConfigurationTests.java} | 2 +- .../JdbcTemplateAutoConfigurationTests.java | 16 +-- .../jms/JmsAutoConfigurationTests.java | 2 +- .../ActiveMQAutoConfigurationTests.java | 2 +- ...afkaAutoConfigurationIntegrationTests.java | 2 +- .../MailSenderAutoConfigurationTests.java | 2 +- .../MongoReactiveAutoConfigurationTests.java | 4 +- ...onditionalOnEnabledResourceChainTests.java | 2 +- .../PackagedSpringApplicationLauncher.java | 2 +- .../cli/command/init/InitCommandTests.java | 2 +- ...eddedDataSourceAutoConfigurationTests.java | 2 +- ...LocalDebugPortAvailableConditionTests.java | 2 +- .../main/asciidoc/spring-boot-features.adoc | 2 +- .../SampleWebFluxApplicationTests.java | 6 +- .../xml/SampleSpringXmlApplication.java | 2 +- ...ConfigurationContextCustomizerFactory.java | 2 +- .../test/autoconfigure/jooq/JooqTest.java | 4 +- .../jooq/JooqTestIntegrationTests.java | 4 +- .../boot/test/util/TestPropertyValues.java | 84 +++++++------ .../test/util/TestPropertyValuesTests.java | 26 ++-- ...ionMetadataRepositoryJsonBuilderTests.java | 2 +- .../boot/loader/tools/FileUtilsTests.java | 2 +- .../OriginTrackedSystemPropertySource.java | 1 + .../boot/logging/LoggingSystem.java | 4 +- .../boot/OverrideSourcesTests.java | 2 +- .../context/properties/bind/BinderTests.java | 3 + ...tionJsonEnvironmentPostProcessorTests.java | 2 +- .../jta/atomikos/AtomikosPropertiesTests.java | 1 - 45 files changed, 200 insertions(+), 166 deletions(-) rename spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/{InfluxDbAutoConfigurationTest.java => InfluxDbAutoConfigurationTests.java} (97%) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/InfoContributorAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/InfoContributorAutoConfigurationTests.java index 5f38957cef..a9c8c953e0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/InfoContributorAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/InfoContributorAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java index 839fe417ee..471a05880f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java index aa26d63ae8..c7c63b7fb0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java @@ -193,8 +193,7 @@ public class LoggersMvcEndpointTests { @Test public void setLoggerWithNoLogLevel() throws Exception { this.mvc.perform(post(PATH + "/ROOT").contentType(MediaType.APPLICATION_JSON) - .content("{}")) - .andExpect(status().isNoContent()); + .content("{}")).andExpect(status().isNoContent()); verify(this.loggingSystem).setLogLevel("ROOT", null); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfiguration.java index 932e632b3f..71dfc6a80d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfiguration.java @@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration; +import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties.Pageable; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -62,20 +63,19 @@ public class SpringDataWebAutoConfiguration { @Bean @ConditionalOnMissingBean public PageableHandlerMethodArgumentResolverCustomizer pageableCustomizer() { - return pageableResolver -> { - pageableResolver.setFallbackPageable(PageRequest.of(0, - this.properties.getPageable().getDefaultPageSize())); - pageableResolver.setPageParameterName( - this.properties.getPageable().getPageParameter()); - pageableResolver.setSizeParameterName( - this.properties.getPageable().getSizeParameter()); + return (resolver) -> { + Pageable pageable = this.properties.getPageable(); + resolver.setFallbackPageable( + PageRequest.of(0, pageable.getDefaultPageSize())); + resolver.setPageParameterName(pageable.getPageParameter()); + resolver.setSizeParameterName(pageable.getSizeParameter()); }; } @Bean @ConditionalOnMissingBean public SortHandlerMethodArgumentResolverCustomizer sortCustomizer() { - return sortResolver -> sortResolver + return (resolver) -> resolver .setSortParameter(this.properties.getSort().getSortParameter()); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java index 057684c849..5363d293b7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java @@ -54,10 +54,8 @@ public class InfluxDbAutoConfiguration { if (Strings.isNullOrEmpty(client.getUser())) { return InfluxDBFactory.connect(client.getUrl()); } - else { - return InfluxDBFactory.connect(client.getUrl(), client.getUser(), - client.getPassword()); - } + return InfluxDBFactory.connect(client.getUrl(), client.getUser(), + client.getPassword()); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/package-info.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/package-info.java index 8eb73aee36..04f316a735 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/package-info.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration.java index 70b189c6ad..2bd39ad12e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration.java @@ -84,7 +84,8 @@ public class JdbcTemplateAutoConfiguration { @Primary @ConditionalOnSingleCandidate(JdbcTemplate.class) @ConditionalOnMissingBean(NamedParameterJdbcOperations.class) - public NamedParameterJdbcTemplate namedParameterJdbcTemplate(JdbcTemplate jdbcTemplate) { + public NamedParameterJdbcTemplate namedParameterJdbcTemplate( + JdbcTemplate jdbcTemplate) { return new NamedParameterJdbcTemplate(jdbcTemplate); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqProperties.java index 6241d9a0ed..107cbf205e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqProperties.java @@ -33,7 +33,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; public class JooqProperties { /** - * Sql dialect to use, auto-detected by default. + * SQL dialect to use, auto-detected by default. */ private SQLDialect sqlDialect; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java index cf9f4c7a81..548528a43b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java @@ -34,6 +34,7 @@ import com.mongodb.reactivestreams.client.MongoClient; import com.mongodb.reactivestreams.client.MongoClients; import org.springframework.core.env.Environment; +import org.springframework.util.Assert; /** * A factory for a reactive {@link MongoClient} that applies {@link MongoProperties}. @@ -96,67 +97,88 @@ public class ReactiveMongoClientFactory { private MongoClient createNetworkMongoClient(MongoClientSettings settings) { if (hasCustomAddress() || hasCustomCredentials()) { - if (this.properties.getUri() != null) { - throw new IllegalStateException("Invalid mongo configuration, " - + "either uri or host/port/credentials must be specified"); - } - - Builder builder = builder(settings); - if (hasCustomCredentials()) { - List credentials = new ArrayList<>(); - String database = this.properties.getAuthenticationDatabase() == null - ? this.properties.getMongoClientDatabase() - : this.properties.getAuthenticationDatabase(); - credentials.add( - MongoCredential.createCredential(this.properties.getUsername(), - database, this.properties.getPassword())); - builder.credentialList(credentials); - } - String host = this.properties.getHost() == null ? "localhost" - : this.properties.getHost(); - int port = this.properties.getPort() != null ? this.properties.getPort() - : MongoProperties.DEFAULT_PORT; - ClusterSettings clusterSettings = ClusterSettings.builder() - .hosts(Collections.singletonList(new ServerAddress(host, port))) - .build(); - builder.clusterSettings(clusterSettings); - return MongoClients.create(builder.build()); + return createCredentialNetworkMongoClient(settings); } ConnectionString connectionString = new ConnectionString( this.properties.determineUri()); return MongoClients.create(createBuilder(settings, connectionString).build()); } + private MongoClient createCredentialNetworkMongoClient(MongoClientSettings settings) { + Assert.state(this.properties.getUri() == null, "Invalid mongo configuration, " + + "either uri or host/port/credentials must be specified"); + Builder builder = builder(settings); + if (hasCustomCredentials()) { + applyCredentials(builder); + } + String host = getOrDefault(this.properties.getHost(), "localhost"); + int port = getOrDefault(this.properties.getPort(), MongoProperties.DEFAULT_PORT); + ServerAddress serverAddress = new ServerAddress(host, port); + builder.clusterSettings(ClusterSettings.builder() + .hosts(Collections.singletonList(serverAddress)).build()); + return MongoClients.create(builder.build()); + } + + private void applyCredentials(Builder builder) { + List credentials = new ArrayList<>(); + String database = this.properties.getAuthenticationDatabase() == null + ? this.properties.getMongoClientDatabase() + : this.properties.getAuthenticationDatabase(); + credentials.add(MongoCredential.createCredential(this.properties.getUsername(), + database, this.properties.getPassword())); + builder.credentialList(credentials); + } + + private T getOrDefault(T value, T defaultValue) { + return (value == null ? defaultValue : value); + } + private Builder createBuilder(MongoClientSettings settings, - ConnectionString connectionString) { - Builder builder = builder(settings) - .clusterSettings(ClusterSettings.builder() - .applyConnectionString(connectionString).build()) - .connectionPoolSettings(ConnectionPoolSettings.builder() - .applyConnectionString(connectionString).build()) - .serverSettings(ServerSettings.builder() - .applyConnectionString(connectionString).build()) - .credentialList(connectionString.getCredentialList()) - .sslSettings(SslSettings.builder().applyConnectionString(connectionString) - .build()) - .socketSettings(SocketSettings.builder() - .applyConnectionString(connectionString).build()); - if (connectionString.getReadPreference() != null) { - builder.readPreference(connectionString.getReadPreference()); + ConnectionString connection) { + Builder builder = builder(settings); + builder.clusterSettings(getClusterSettings(connection)); + builder.connectionPoolSettings(getConnectionPoolSettings(connection)); + builder.serverSettings(getServerSettings(connection)); + builder.credentialList(connection.getCredentialList()); + builder.sslSettings(getSslSettings(connection)); + builder.socketSettings(getSocketSettings(connection)); + if (connection.getReadPreference() != null) { + builder.readPreference(connection.getReadPreference()); } - if (connectionString.getReadConcern() != null) { - builder.readConcern(connectionString.getReadConcern()); + if (connection.getReadConcern() != null) { + builder.readConcern(connection.getReadConcern()); } - if (connectionString.getWriteConcern() != null) { - builder.writeConcern(connectionString.getWriteConcern()); + if (connection.getWriteConcern() != null) { + builder.writeConcern(connection.getWriteConcern()); } - if (connectionString.getApplicationName() != null) { - builder.applicationName(connectionString.getApplicationName()); + if (connection.getApplicationName() != null) { + builder.applicationName(connection.getApplicationName()); } customize(builder); return builder; } + private ClusterSettings getClusterSettings(ConnectionString connection) { + return ClusterSettings.builder().applyConnectionString(connection).build(); + } + + private ConnectionPoolSettings getConnectionPoolSettings( + ConnectionString connection) { + return ConnectionPoolSettings.builder().applyConnectionString(connection).build(); + } + + private ServerSettings getServerSettings(ConnectionString connection) { + return ServerSettings.builder().applyConnectionString(connection).build(); + } + + private SslSettings getSslSettings(ConnectionString connection) { + return SslSettings.builder().applyConnectionString(connection).build(); + } + + private SocketSettings getSocketSettings(ConnectionString connection) { + return SocketSettings.builder().applyConnectionString(connection).build(); + } + private void customize(MongoClientSettings.Builder builder) { for (MongoClientSettingsBuilderCustomizer customizer : this.builderCustomizers) { customizer.customize(builder); @@ -176,7 +198,6 @@ public class ReactiveMongoClientFactory { if (settings == null) { return MongoClientSettings.builder(); } - return MongoClientSettings.builder(settings); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AllNestedConditionsTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AllNestedConditionsTests.java index 514076d4d9..5bceda853d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AllNestedConditionsTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AllNestedConditionsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AnyNestedConditionTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AnyNestedConditionTests.java index 4021f47692..4b9c197e92 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AnyNestedConditionTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AnyNestedConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnCloudPlatformTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnCloudPlatformTests.java index 1765a15f00..25d6b8787a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnCloudPlatformTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnCloudPlatformTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnResourceTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnResourceTests.java index 6d2829a941..38a926512b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnResourceTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnResourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/NoneNestedConditionsTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/NoneNestedConditionsTests.java index 7d4e5bb1b8..7f22e99ad8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/NoneNestedConditionsTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/NoneNestedConditionsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/ConfigurationPropertiesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/ConfigurationPropertiesAutoConfigurationTests.java index f8b406639f..0974dd3dd1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/ConfigurationPropertiesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/ConfigurationPropertiesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/OnBootstrapHostsConditionTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/OnBootstrapHostsConditionTests.java index 198af45167..9ac74bc70a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/OnBootstrapHostsConditionTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/OnBootstrapHostsConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java index d7c9518e7e..e44f88e1db 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java @@ -56,8 +56,7 @@ public class ElasticsearchDataAutoConfigurationTests { ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class); this.context.refresh(); - assertThat(this.context.getBeanNamesForType(ElasticsearchTemplate.class)) - .hasSize(1); + asssertHasSingleBean(ElasticsearchTemplate.class); } @Test @@ -71,9 +70,7 @@ public class ElasticsearchDataAutoConfigurationTests { ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class); this.context.refresh(); - assertThat( - this.context.getBeanNamesForType(SimpleElasticsearchMappingContext.class)) - .hasSize(1); + asssertHasSingleBean(SimpleElasticsearchMappingContext.class); } @Test @@ -87,8 +84,11 @@ public class ElasticsearchDataAutoConfigurationTests { ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class); this.context.refresh(); - assertThat(this.context.getBeanNamesForType(ElasticsearchConverter.class)) - .hasSize(1); + asssertHasSingleBean(ElasticsearchConverter.class); + } + + private void asssertHasSingleBean(Class type) { + assertThat(this.context.getBeanNamesForType(type)).hasSize(1); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTest.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTests.java similarity index 97% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTest.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTests.java index 59207aae8c..2264fd3e53 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTest.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTests.java @@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sergey Kuptsov * @author Stephane Nicoll */ -public class InfluxDbAutoConfigurationTest { +public class InfluxDbAutoConfigurationTests { private AnnotationConfigApplicationContext context; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java index 30fe4d8afc..8efcf533a2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java @@ -60,8 +60,8 @@ public class JdbcTemplateAutoConfigurationTests { load(); assertThat(this.context.getBeansOfType(JdbcOperations.class)).hasSize(1); JdbcTemplate jdbcTemplate = this.context.getBean(JdbcTemplate.class); - assertThat(jdbcTemplate.getDataSource()).isEqualTo( - this.context.getBean(DataSource.class)); + assertThat(jdbcTemplate.getDataSource()) + .isEqualTo(this.context.getBean(DataSource.class)); assertThat(jdbcTemplate.getFetchSize()).isEqualTo(-1); assertThat(jdbcTemplate.getQueryTimeout()).isEqualTo(-1); assertThat(jdbcTemplate.getMaxRows()).isEqualTo(-1); @@ -86,8 +86,8 @@ public class JdbcTemplateAutoConfigurationTests { assertThat(this.context.getBeansOfType(JdbcOperations.class)).hasSize(1); JdbcTemplate jdbcTemplate = this.context.getBean(JdbcTemplate.class); assertThat(jdbcTemplate).isNotNull(); - assertThat(jdbcTemplate.getDataSource()).isEqualTo( - this.context.getBean("customDataSource")); + assertThat(jdbcTemplate.getDataSource()) + .isEqualTo(this.context.getBean("customDataSource")); } @Test @@ -95,10 +95,10 @@ public class JdbcTemplateAutoConfigurationTests { load(); assertThat(this.context.getBeansOfType(NamedParameterJdbcOperations.class)) .hasSize(1); - NamedParameterJdbcTemplate namedParameterJdbcTemplate = this.context.getBean( - NamedParameterJdbcTemplate.class); - assertThat(namedParameterJdbcTemplate.getJdbcOperations()).isEqualTo( - this.context.getBean(JdbcOperations.class)); + NamedParameterJdbcTemplate namedParameterJdbcTemplate = this.context + .getBean(NamedParameterJdbcTemplate.class); + assertThat(namedParameterJdbcTemplate.getJdbcOperations()) + .isEqualTo(this.context.getBean(JdbcOperations.class)); } @Test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java index c4aa4c2a82..a09754893e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java index ac71acd2d6..f1d4449bdd 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationIntegrationTests.java index 01d3f4fdfc..ed056d3d85 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java index 3579bd2ad8..7c505bfe8a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java index 80ada0814d..f4ba5aa8df 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java @@ -157,8 +157,8 @@ public class MongoReactiveAutoConfigurationTests { @Bean public MongoClientSettingsBuilderCustomizer customizer() { - return clientSettingsBuilder -> - clientSettingsBuilder.applicationName("overridden-name"); + return clientSettingsBuilder -> clientSettingsBuilder + .applicationName("overridden-name"); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ConditionalOnEnabledResourceChainTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ConditionalOnEnabledResourceChainTests.java index a3a4b7b3ed..a34efba5b8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ConditionalOnEnabledResourceChainTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ConditionalOnEnabledResourceChainTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/archive/PackagedSpringApplicationLauncher.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/archive/PackagedSpringApplicationLauncher.java index 33bc228f80..2f03e58baf 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/archive/PackagedSpringApplicationLauncher.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/archive/PackagedSpringApplicationLauncher.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java index 9a0611e61f..028e34629b 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java index 46c4a7f69a..9ad2d89f9a 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsEmbeddedDataSourceAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/LocalDebugPortAvailableConditionTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/LocalDebugPortAvailableConditionTests.java index 7c292de8ea..a736c38683 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/LocalDebugPortAvailableConditionTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/LocalDebugPortAvailableConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index d40b998897..3fb049fb37 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -5861,7 +5861,7 @@ into the `ApplicationContext`: import org.junit.runner.RunWith; import org.springframework.boot.test.autoconfigure.jooq.JooqTest; import org.springframework.test.context.junit4.SpringRunner; - + @RunWith(SpringRunner.class) @JooqTest public class ExampleJooqTests { diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java index f59f8a5913..be265f5cb9 100644 --- a/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java @@ -47,11 +47,9 @@ public class SampleWebFluxApplicationTests { @Test public void testEcho() throws Exception { - this.webClient.post().uri("/echo") - .contentType(MediaType.TEXT_PLAIN) + this.webClient.post().uri("/echo").contentType(MediaType.TEXT_PLAIN) .accept(MediaType.TEXT_PLAIN) - .body(Mono.just("Hello WebFlux!"), String.class) - .exchange() + .body(Mono.just("Hello WebFlux!"), String.class).exchange() .expectBody(String.class).isEqualTo("Hello WebFlux!"); } diff --git a/spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/SampleSpringXmlApplication.java b/spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/SampleSpringXmlApplication.java index 435b2d9952..0d74b1cdc9 100644 --- a/spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/SampleSpringXmlApplication.java +++ b/spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/SampleSpringXmlApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java index 5e2c8b2036..c59967788b 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java index 8386d4f76a..4e52fde508 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java @@ -42,8 +42,8 @@ import org.springframework.transaction.annotation.Transactional; * Using this annotation will disable full auto-configuration and instead apply only * configuration relevant to jOOQ tests. *

- * By default, tests annotated with {@code @JooqTest} use the configured database. If - * you want to replace any explicit or usually auto-configured DataSource by an embedded + * By default, tests annotated with {@code @JooqTest} use the configured database. If you + * want to replace any explicit or usually auto-configured DataSource by an embedded * in-memory database, the {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase} * annotation can be used to override these settings. * diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestIntegrationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestIntegrationTests.java index 73d6febfb4..832195b8da 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestIntegrationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestIntegrationTests.java @@ -59,8 +59,8 @@ public class JooqTestIntegrationTests { @Test public void testDSLContext() { - assertThat(this.dsl.selectCount().from("INFORMATION_SCHEMA.TABLES") - .fetchOne(0, Integer.class)).isGreaterThan(0); + assertThat(this.dsl.selectCount().from("INFORMATION_SCHEMA.TABLES").fetchOne(0, + Integer.class)).isGreaterThan(0); } @Test diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java b/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java index ad4470a452..fcb27c7bfc 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java @@ -30,8 +30,8 @@ import org.springframework.core.env.SystemEnvironmentPropertySource; import org.springframework.util.Assert; /** - * Test utilities for adding properties to the environment. The type of {@link PropertySource} - * to be added can be specified by {@link Type}. + * Test utilities for adding properties to the environment. The type of + * {@link PropertySource} to be added can be specified by {@link Type}. * * @author Madhura Bhave * @since 2.0.0 @@ -44,14 +44,25 @@ public final class TestPropertyValues { addProperties(pairs); } - /** - * Return a new {@link TestPropertyValues} with the underlying map populated with the given property pairs. - * Name-value pairs can be specified with colon (":") or equals ("=") separators. - * @param pairs The key value pairs for properties that need to be added to the environment - * @return the new instance - */ - public static TestPropertyValues of(String... pairs) { - return new TestPropertyValues(pairs); + private void addProperties(String[] pairs) { + for (String pair : pairs) { + int index = getSeparatorIndex(pair); + String key = pair.substring(0, index > 0 ? index : pair.length()); + String value = index > 0 ? pair.substring(index + 1) : ""; + this.properties.put(key.trim(), value.trim()); + } + } + + private int getSeparatorIndex(String pair) { + int colonIndex = pair.indexOf(":"); + int equalIndex = pair.indexOf("="); + if (colonIndex == -1) { + return equalIndex; + } + if (equalIndex == -1) { + return colonIndex; + } + return Math.min(colonIndex, equalIndex); } /** @@ -65,17 +76,9 @@ public final class TestPropertyValues { return this; } - private void addProperties(String[] pairs) { - for (String pair : pairs) { - int index = getSeparatorIndex(pair); - String key = pair.substring(0, index > 0 ? index : pair.length()); - String value = index > 0 ? pair.substring(index + 1) : ""; - this.properties.put(key.trim(), value.trim()); - } - } - /** - * Add the properties from the underlying map to the environment owned by an {@link ApplicationContext}. + * Add the properties from the underlying map to the environment owned by an + * {@link ApplicationContext}. * @param context the context with an environment to modify */ public void applyTo(ConfigurableApplicationContext context) { @@ -83,8 +86,8 @@ public final class TestPropertyValues { } /** - * Add the properties from the underlying map to the environment. The default property source used is - * {@link MapPropertySource}. + * Add the properties from the underlying map to the environment. The default property + * source used is {@link MapPropertySource}. * @param environment the environment that needs to be modified */ public void applyTo(ConfigurableEnvironment environment) { @@ -92,7 +95,8 @@ public final class TestPropertyValues { } /** - * Add the properties from the underlying map to the environment using the specified property source type. + * Add the properties from the underlying map to the environment using the specified + * property source type. * @param environment the environment that needs to be modified * @param type the type of {@link PropertySource} to be added. See {@link Type} */ @@ -101,7 +105,8 @@ public final class TestPropertyValues { } /** - * Add the properties from the underlying map to the environment using the specified property source type and name. + * Add the properties from the underlying map to the environment using the specified + * property source type and name. * @param environment the environment that needs to be modified * @param type the type of {@link PropertySource} to be added. See {@link Type} * @param name the name for the property source @@ -120,26 +125,27 @@ public final class TestPropertyValues { if (sources.contains(name)) { PropertySource propertySource = sources.get(name); if (propertySource.getClass().equals(type.getSourceClass())) { - Map source = (Map) propertySource.getSource(); - source.putAll(this.properties); + ((Map) propertySource.getSource()) + .putAll(this.properties); return; } } - MapPropertySource source = (type.equals(Type.MAP) ? new MapPropertySource(name, this.properties) : - new SystemEnvironmentPropertySource(name, this.properties)); + MapPropertySource source = (type.equals(Type.MAP) + ? new MapPropertySource(name, this.properties) + : new SystemEnvironmentPropertySource(name, this.properties)); sources.addFirst(source); } - private static int getSeparatorIndex(String pair) { - int colonIndex = pair.indexOf(":"); - int equalIndex = pair.indexOf("="); - if (colonIndex == -1) { - return equalIndex; - } - if (equalIndex == -1) { - return colonIndex; - } - return Math.min(colonIndex, equalIndex); + /** + * Return a new {@link TestPropertyValues} with the underlying map populated with the + * given property pairs. Name-value pairs can be specified with colon (":") or equals + * ("=") separators. + * @param pairs The key value pairs for properties that need to be added to the + * environment + * @return the new instance + */ + public static TestPropertyValues of(String... pairs) { + return new TestPropertyValues(pairs); } /** @@ -166,7 +172,7 @@ public final class TestPropertyValues { public Class getSourceClass() { return this.sourceClass; } + } } - diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/util/TestPropertyValuesTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/util/TestPropertyValuesTests.java index d43364c564..87cb6cdf8d 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/util/TestPropertyValuesTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/util/TestPropertyValuesTests.java @@ -36,9 +36,11 @@ public class TestPropertyValuesTests { private final ConfigurableEnvironment environment = new StandardEnvironment(); @Test - public void applyToEnvironmentShouldAttachConfigurationPropertySource() throws Exception { + public void applyToEnvironmentShouldAttachConfigurationPropertySource() + throws Exception { TestPropertyValues.of("foo.bar=baz").applyTo(this.environment); - PropertySource source = this.environment.getPropertySources().get("configurationProperties"); + PropertySource source = this.environment.getPropertySources() + .get("configurationProperties"); assertThat(source).isNotNull(); } @@ -63,17 +65,22 @@ public class TestPropertyValuesTests { } @Test - public void applyToExistingNameAndDifferentTypeShouldOverrideExistingOne() throws Exception { - TestPropertyValues.of("foo.bar=baz", "hello.world=hi").applyTo(this.environment, Type.MAP, "other"); - TestPropertyValues.of("FOO_BAR=BAZ").applyTo(this.environment, Type.SYSTEM, "other"); - assertThat(this.environment.getPropertySources().get("other")).isInstanceOf(SystemEnvironmentPropertySource.class); + public void applyToExistingNameAndDifferentTypeShouldOverrideExistingOne() + throws Exception { + TestPropertyValues.of("foo.bar=baz", "hello.world=hi").applyTo(this.environment, + Type.MAP, "other"); + TestPropertyValues.of("FOO_BAR=BAZ").applyTo(this.environment, Type.SYSTEM, + "other"); + assertThat(this.environment.getPropertySources().get("other")) + .isInstanceOf(SystemEnvironmentPropertySource.class); assertThat(this.environment.getProperty("foo.bar")).isEqualTo("BAZ"); assertThat(this.environment.getProperty("hello.world")).isNull(); } @Test public void applyToExistingNameAndSameTypeShouldMerge() throws Exception { - TestPropertyValues.of("foo.bar=baz", "hello.world=hi").applyTo(this.environment, Type.MAP); + TestPropertyValues.of("foo.bar=baz", "hello.world=hi").applyTo(this.environment, + Type.MAP); TestPropertyValues.of("foo.bar=new").applyTo(this.environment, Type.MAP); assertThat(this.environment.getProperty("foo.bar")).isEqualTo("new"); assertThat(this.environment.getProperty("hello.world")).isEqualTo("hi"); @@ -81,10 +88,11 @@ public class TestPropertyValuesTests { @Test public void andShouldChainAndAddSingleKeyValue() throws Exception { - TestPropertyValues.of("foo.bar=baz").and("hello.world", "hi").and("bling.blah", "bing") - .applyTo(this.environment, Type.MAP); + TestPropertyValues.of("foo.bar=baz").and("hello.world", "hi") + .and("bling.blah", "bing").applyTo(this.environment, Type.MAP); assertThat(this.environment.getProperty("foo.bar")).isEqualTo("baz"); assertThat(this.environment.getProperty("hello.world")).isEqualTo("hi"); assertThat(this.environment.getProperty("bling.blah")).isEqualTo("bing"); } + } diff --git a/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilderTests.java b/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilderTests.java index d168280f34..61ea9a8b28 100644 --- a/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilderTests.java +++ b/spring-boot-tools/spring-boot-configuration-metadata/src/test/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/FileUtilsTests.java b/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/FileUtilsTests.java index 04433f5233..130bb63862 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/FileUtilsTests.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/FileUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedSystemPropertySource.java b/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedSystemPropertySource.java index fc7df8b9ef..09af5deef8 100644 --- a/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedSystemPropertySource.java +++ b/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedSystemPropertySource.java @@ -60,4 +60,5 @@ public class OriginTrackedSystemPropertySource extends SystemEnvironmentProperty } return null; } + } diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java index d2794ab6b6..36f85681a6 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystem.java @@ -116,8 +116,8 @@ public abstract class LoggingSystem { * Sets the logging level for a given logger. * @param loggerName the name of the logger to set ({@code null} can be used for the * root logger). - * @param level the log level ({@code null} can be used to remove any custom level - * for the logger and use the default configuration instead) + * @param level the log level ({@code null} can be used to remove any custom level for + * the logger and use the default configuration instead) */ public void setLogLevel(String loggerName, LogLevel level) { throw new UnsupportedOperationException("Unable to set log level"); diff --git a/spring-boot/src/test/java/org/springframework/boot/OverrideSourcesTests.java b/spring-boot/src/test/java/org/springframework/boot/OverrideSourcesTests.java index 8af43838da..a64864fddc 100644 --- a/spring-boot/src/test/java/org/springframework/boot/OverrideSourcesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/OverrideSourcesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java index a01a46b87b..78893199a3 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java @@ -225,12 +225,14 @@ public class BinderTests { Bindable target = Bindable.of(JavaBean.class); this.thrown.expect(BindException.class); this.thrown.expect(new AssertionMatcher() { + @Override public void assertion(BindException ex) throws AssertionError { assertThat(ex.getCause().getMessage()) .isEqualTo("No setter found for property: items"); assertThat(ex.getProperty()).isNull(); } + }); this.binder.bind("foo", target); } @@ -252,6 +254,7 @@ public class BinderTests { public List getItems() { return this.items; } + } public enum ExampleEnum { diff --git a/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java b/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java index 37797d4d19..51787fd528 100644 --- a/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosPropertiesTests.java b/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosPropertiesTests.java index 14e4f794e7..4621a28b85 100644 --- a/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosPropertiesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/jta/atomikos/AtomikosPropertiesTests.java @@ -56,7 +56,6 @@ public class AtomikosPropertiesTests { this.properties.getRecovery().setDelay(3000); this.properties.getRecovery().setMaxRetries(10); this.properties.getRecovery().setRetryInterval(4000); - assertThat(this.properties.asProperties().size()).isEqualTo(17); assertProperty("com.atomikos.icatch.service", "service"); assertProperty("com.atomikos.icatch.max_timeout", "1");