From 6e29ee4557f3c77dfe0cb46728f6723453d2b4bc Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sat, 5 Sep 2015 10:38:30 -0700 Subject: [PATCH] Polish --- .../ManagementServerProperties.java | 14 +-- ...anagementWebSecurityAutoConfiguration.java | 60 ++++++------ .../MetricRepositoryAutoConfiguration.java | 2 +- .../mvc/ActuatorHalBrowserEndpoint.java | 1 + .../endpoint/mvc/ActuatorHalJsonEndpoint.java | 2 +- .../dropwizard/DropwizardMetricServices.java | 2 +- .../metrics/repository/redis/RedisUtils.java | 5 +- .../writer/DropwizardMetricWriter.java | 2 +- .../boot/actuate/system/SystemProperties.java | 5 +- .../PublicMetricsAutoConfigurationTests.java | 34 ++++--- ...rtiesReportEndpointSerializationTests.java | 27 +++--- .../endpoint/MetricsEndpointTests.java | 4 +- .../ElasticsearchHealthIndicatorTests.java | 2 +- .../health/MailHealthIndicatorTests.java | 4 +- .../statsd/StatsdMetricWriterTests.java | 2 + .../MessageSourceAutoConfiguration.java | 12 +-- .../cache/CacheConfigurations.java | 5 +- .../condition/ConditionEvaluationReport.java | 2 +- .../GroovyTemplateAutoConfiguration.java | 3 +- .../template/GroovyTemplateResolver.java | 5 +- .../IntegrationAutoConfiguration.java | 12 +-- ...ctiveMQConnectionFactoryConfiguration.java | 14 +-- .../jms/artemis/package-info.java | 1 + ...eviceDelegatingViewResolverProperties.java | 2 +- .../EmbeddedMongoAutoConfiguration.java | 7 +- .../orm/jpa/EntityManagerFactoryBuilder.java | 2 +- ...Auth2AuthorizationServerConfiguration.java | 58 +++++------ .../template/TemplateLocation.java | 6 +- .../web/BasicErrorController.java | 15 +-- .../DispatcherServletAutoConfiguration.java | 96 +++++++++---------- .../cache/CacheAutoConfigurationTests.java | 56 +++++------ .../ConditionalOnSingleCandidateTests.java | 2 +- ...ationPropertiesAutoConfigurationTests.java | 6 +- ...olrRepositoriesAutoConfigurationTests.java | 4 +- .../flyway/FlywayAutoConfigurationTests.java | 2 +- .../HazelcastAutoConfigurationTests.java | 16 ++-- .../JacksonAutoConfigurationTests.java | 16 ++-- .../ArtemisAutoConfigurationTests.java | 2 +- .../HornetQAutoConfigurationTests.java | 2 +- .../jndi/TestableInitialContextFactory.java | 2 +- .../jooq/JooqAutoConfigurationTests.java | 2 + .../EmbeddedMongoAutoConfigurationTests.java | 26 ++--- .../SecurityAutoConfigurationTests.java | 1 + .../oauth2/OAuth2AutoConfigurationTests.java | 2 +- .../CustomOAuth2SsoConfigurationTests.java | 2 +- .../AbstractSocialAutoConfigurationTests.java | 1 + .../template/ViewResolverPropertiesTest.java | 2 +- .../jta/JtaAutoConfigurationTests.java | 10 +- ...asicErrorControllerDirectMockMvcTests.java | 2 +- .../BasicErrorControllerIntegrationTests.java | 2 +- .../web/BasicErrorControllerMockMvcTests.java | 2 +- .../web/MultipartAutoConfigurationTests.java | 60 ++++++------ .../web/ServerPropertiesTests.java | 2 +- .../springframework/boot/cli/SpringCli.java | 5 +- .../cli/command/init/InitializrService.java | 1 + .../init/InitializrServiceMetadata.java | 2 +- .../cli/command/init/ProjectGenerator.java | 1 + .../options/CompilerOptionHandler.java | 6 +- .../boot/cli/command/run/RunCommand.java | 7 +- .../command/run/SpringApplicationRunner.java | 47 ++++----- .../boot/cli/compiler/AstUtils.java | 51 ++++++---- .../boot/cli/compiler/GroovyCompiler.java | 35 ++++--- .../PackagedSpringApplicationLauncher.java | 5 +- .../boot/groovy/DelegateTestRunner.java | 5 +- .../command/init/InitializrServiceTests.java | 10 +- ...rviceCapabilitiesReportGeneratorTests.java | 2 +- .../boot/cli/util/SystemProperties.java | 5 +- .../devtools/RemoteSpringApplication.java | 6 +- .../FileWatchingFailureHandler.java | 1 + .../devtools/filewatch/FileSystemWatcher.java | 1 + .../devtools/livereload/Base64Encoder.java | 5 +- .../client/DelayedLiveReloadTrigger.java | 1 + .../boot/devtools/restart/ChangeableUrls.java | 2 +- .../boot/devtools/restart/Restarter.java | 1 + .../tunnel/client/HttpTunnelConnection.java | 1 + .../devtools/tunnel/client/TunnelClient.java | 1 + .../tunnel/server/HttpTunnelServer.java | 1 + .../livereload/LiveReloadServerTests.java | 38 ++++---- .../boot/devtools/restart/RestarterTests.java | 1 + .../test/MockClientHttpRequestFactory.java | 1 + .../springframework/boot/gradle/Versions.java | 5 +- .../spring-boot-security-tests/pom.xml | 2 +- ...gurationMetadataRepositoryJsonBuilder.java | 2 +- .../fieldvalues/javac/Trees.java | 2 +- ...ationMetadataAnnotationProcessorTests.java | 5 +- .../ConfigurationMetadataMatchers.java | 5 +- .../metadata/ConfigurationMetadataTests.java | 2 +- .../boot/gradle/SpringBootPlugin.groovy | 1 - .../gradle/SpringBootPluginExtension.groovy | 6 +- .../DependencyManagementPluginFeatures.groovy | 6 +- .../boot/gradle/run/SourceSets.java | 5 +- .../boot/loader/tools/Layouts.java | 5 +- .../boot/loader/tools/LibraryScope.java | 3 + .../boot/loader/tools/RunProcess.java | 1 + .../boot/loader/tools/SignalUtils.java | 5 +- .../tools/sample/ClassWithMainMethod.java | 5 + .../boot/loader/LaunchedURLClassLoader.java | 2 + .../boot/loader/jar/Bytes.java | 5 +- .../boot/loader/jar/Handler.java | 1 + .../boot/loader/ByteArrayStartsWith.java | 8 +- .../ExecutableArchiveLauncherTests.java | 22 ++--- .../loader/archive/JarFileArchiveTests.java | 4 +- .../boot/maven/DependencyFilterMojoTests.java | 2 +- .../springframework/boot/maven/Verify.java | 5 +- .../maven/sample/ClassWithMainMethod.java | 5 + .../springframework/boot/ApplicationHome.java | 3 +- .../boot/SpringBootBanner.java | 10 +- .../boot/SpringBootVersion.java | 5 +- .../boot/bind/RelaxedPropertyResolver.java | 8 +- .../jetty/JettyEmbeddedServletContainer.java | 1 + .../TomcatEmbeddedServletContainer.java | 1 + .../UndertowEmbeddedServletContainer.java | 2 +- .../boot/logging/log4j2/ColorConverter.java | 4 +- .../WhitespaceThrowablePatternConverter.java | 2 +- .../boot/test/Base64Encoder.java | 5 +- .../test/SpringApplicationContextLoader.java | 27 ++++-- .../test/SpringBootMockServletContext.java | 1 + .../boot/ansi/AnsiOutputEnabledValue.java | 5 +- .../boot/bind/RelaxedDataBinderTests.java | 4 +- ...tEmbeddedServletContainerFactoryTests.java | 7 +- ...edServletContainerMvcIntegrationTests.java | 14 +-- .../MockEmbeddedServletContainerFactory.java | 29 +++--- ...tEmbeddedServletContainerFactoryTests.java | 4 +- .../EnableConfigurationPropertiesTests.java | 22 ++--- ...tespaceThrowablePatternConverterTests.java | 2 +- 125 files changed, 636 insertions(+), 504 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java index 32fff7812be..34017c4fa14 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java @@ -78,6 +78,13 @@ public class ManagementServerProperties implements SecurityPrerequisite { private final Security security = maybeCreateSecurity(); + private Security maybeCreateSecurity() { + if (ClassUtils.isPresent(SECURITY_CHECK_CLASS, null)) { + return new Security(); + } + return null; + } + /** * Returns the management port or {@code null} if the * {@link ServerProperties#getPort() server port} should be used. @@ -183,11 +190,4 @@ public class ManagementServerProperties implements SecurityPrerequisite { } - private static Security maybeCreateSecurity() { - if (ClassUtils.isPresent(SECURITY_CHECK_CLASS, null)) { - return new Security(); - } - return null; - } - } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfiguration.java index 55398cf4bfa..481b61a63e5 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementWebSecurityAutoConfiguration.java @@ -152,8 +152,8 @@ public class ManagementWebSecurityAutoConfiguration { List ignored = SpringBootWebSecurityConfiguration .getIgnored(this.security); if (!this.management.getSecurity().isEnabled()) { - ignored.addAll(Arrays - .asList(getEndpointPaths(this.endpointHandlerMapping))); + ignored.addAll(Arrays.asList(EndpointPaths + .get(this.endpointHandlerMapping))); } if (ignored.contains("none")) { ignored.remove("none"); @@ -333,44 +333,48 @@ public class ManagementWebSecurityAutoConfiguration { private String[] getPaths() { EndpointHandlerMapping endpointHandlerMapping = ManagementWebSecurityConfigurerAdapter.this.endpointHandlerMapping; if (this.sensitive) { - return getEndpointPaths(endpointHandlerMapping); + return EndpointPaths.get(endpointHandlerMapping); } - return getEndpointPaths(endpointHandlerMapping, false); + return EndpointPaths.get(endpointHandlerMapping, false); } } } - private static String[] getEndpointPaths(EndpointHandlerMapping endpointHandlerMapping) { - return StringUtils.mergeStringArrays( - getEndpointPaths(endpointHandlerMapping, false), - getEndpointPaths(endpointHandlerMapping, true)); - } + private static class EndpointPaths { - private static String[] getEndpointPaths( - EndpointHandlerMapping endpointHandlerMapping, boolean secure) { - if (endpointHandlerMapping == null) { - return NO_PATHS; + public static String[] get(EndpointHandlerMapping endpointHandlerMapping) { + String[] insecure = get(endpointHandlerMapping, false); + String[] secure = get(endpointHandlerMapping, true); + return StringUtils.mergeStringArrays(insecure, secure); } - Set endpoints = endpointHandlerMapping.getEndpoints(); - Set paths = new LinkedHashSet(endpoints.size()); - for (MvcEndpoint endpoint : endpoints) { - if (endpoint.isSensitive() == secure) { - String path = endpointHandlerMapping.getPath(endpoint.getPath()); - paths.add(path); - if (!path.equals("")) { - // Ensure that nested paths are secured - paths.add(path + "/**"); - // Add Spring MVC-generated additional paths - paths.add(path + ".*"); - } - else { - paths.add("/"); + + public static String[] get(EndpointHandlerMapping endpointHandlerMapping, + boolean secure) { + if (endpointHandlerMapping == null) { + return NO_PATHS; + } + Set endpoints = endpointHandlerMapping.getEndpoints(); + Set paths = new LinkedHashSet(endpoints.size()); + for (MvcEndpoint endpoint : endpoints) { + if (endpoint.isSensitive() == secure) { + String path = endpointHandlerMapping.getPath(endpoint.getPath()); + paths.add(path); + if (!path.equals("")) { + // Ensure that nested paths are secured + paths.add(path + "/**"); + // Add Spring MVC-generated additional paths + paths.add(path + ".*"); + } + else { + paths.add("/"); + } } } + return paths.toArray(new String[paths.size()]); } - return paths.toArray(new String[paths.size()]); + } } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java index c92a020bff0..d1075e37c19 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java @@ -105,7 +105,7 @@ public class MetricRepositoryAutoConfiguration { } @Configuration - @ConditionalOnJava(value = JavaVersion.EIGHT) + @ConditionalOnJava(JavaVersion.EIGHT) @ConditionalOnMissingBean(GaugeService.class) static class FastMetricServicesConfiguration { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/ActuatorHalBrowserEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/ActuatorHalBrowserEndpoint.java index 9bce5578b0a..084c8f601dd 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/ActuatorHalBrowserEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/ActuatorHalBrowserEndpoint.java @@ -87,6 +87,7 @@ public class ActuatorHalBrowserEndpoint extends ActuatorHalJsonEndpoint implemen } } catch (Exception ex) { + // Ignore } } return null; diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/ActuatorHalJsonEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/ActuatorHalJsonEndpoint.java index ea7db45d567..4edf09a9a56 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/ActuatorHalJsonEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/ActuatorHalJsonEndpoint.java @@ -66,7 +66,7 @@ public class ActuatorHalJsonEndpoint extends WebMvcConfigurerAdapter implements private String getDefaultPath(ManagementServletContext managementServletContext) { if (StringUtils.hasText(managementServletContext.getContextPath())) { - return this.path = ""; + return ""; } return "/actuator"; } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java index d9491c714ee..e899adb16e8 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/dropwizard/DropwizardMetricServices.java @@ -152,7 +152,7 @@ public class DropwizardMetricServices implements CounterService, GaugeService { /** * Simple {@link Gauge} implementation to {@literal double} value. */ - private static class SimpleGauge implements Gauge { + private final static class SimpleGauge implements Gauge { private final double value; diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/redis/RedisUtils.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/redis/RedisUtils.java index 34c936636e3..7a58c5aae22 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/redis/RedisUtils.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/redis/RedisUtils.java @@ -28,7 +28,10 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; * * @author Luke Taylor */ -class RedisUtils { +final class RedisUtils { + + private RedisUtils() { + } static RedisTemplate createRedisTemplate( RedisConnectionFactory connectionFactory, Class valueClass) { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DropwizardMetricWriter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DropwizardMetricWriter.java index 7a8751aed90..b8c79122774 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DropwizardMetricWriter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DropwizardMetricWriter.java @@ -121,7 +121,7 @@ public class DropwizardMetricWriter implements MetricWriter { /** * Simple {@link Gauge} implementation to {@literal double} value. */ - private static class SimpleGauge implements Gauge { + private final static class SimpleGauge implements Gauge { private final double value; diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/SystemProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/SystemProperties.java index ad2205b8958..f256c5c2f10 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/SystemProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/system/SystemProperties.java @@ -21,7 +21,10 @@ package org.springframework.boot.actuate.system; * * @author Phillip Webb */ -class SystemProperties { +final class SystemProperties { + + private SystemProperties() { + } public static String get(String... properties) { for (String property : properties) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java index 784e3fe58c3..cb7822bebd0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java @@ -269,18 +269,18 @@ public class PublicMetricsAutoConfigurationTests { @Bean public DataSource tomcatDataSource() { - return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class) - .build(); + return InitalizedBuilder.create() + .type(org.apache.tomcat.jdbc.pool.DataSource.class).build(); } @Bean public DataSource hikariDS() { - return initializeBuilder().type(HikariDataSource.class).build(); + return InitalizedBuilder.create().type(HikariDataSource.class).build(); } @Bean public DataSource commonsDbcpDataSource() { - return initializeBuilder().type(BasicDataSource.class).build(); + return InitalizedBuilder.create().type(BasicDataSource.class).build(); } } @@ -290,13 +290,13 @@ public class PublicMetricsAutoConfigurationTests { @Bean @Primary public DataSource myDataSource() { - return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class) - .build(); + return InitalizedBuilder.create() + .type(org.apache.tomcat.jdbc.pool.DataSource.class).build(); } @Bean public DataSource commonsDbcpDataSource() { - return initializeBuilder().type(BasicDataSource.class).build(); + return InitalizedBuilder.create().type(BasicDataSource.class).build(); } } @@ -306,13 +306,13 @@ public class PublicMetricsAutoConfigurationTests { @Bean @Primary public DataSource myDataSource() { - return initializeBuilder().type(org.apache.tomcat.jdbc.pool.DataSource.class) - .build(); + return InitalizedBuilder.create() + .type(org.apache.tomcat.jdbc.pool.DataSource.class).build(); } @Bean public DataSource dataSource() { - return initializeBuilder().type(BasicDataSource.class).build(); + return InitalizedBuilder.create().type(BasicDataSource.class).build(); } } @@ -331,11 +331,6 @@ public class PublicMetricsAutoConfigurationTests { } } - private static DataSourceBuilder initializeBuilder() { - return DataSourceBuilder.create().driverClassName("org.hsqldb.jdbc.JDBCDriver") - .url("jdbc:hsqldb:mem:test").username("sa"); - } - @Configuration static class RichGaugeReaderConfig { @@ -385,4 +380,13 @@ public class PublicMetricsAutoConfigurationTests { } + private static class InitalizedBuilder { + + public static DataSourceBuilder create() { + return DataSourceBuilder.create() + .driverClassName("org.hsqldb.jdbc.JDBCDriver") + .url("jdbc:hsqldb:mem:test").username("sa"); + } + + } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointSerializationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointSerializationTests.java index 68f40d82c3d..f0ce19395cd 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointSerializationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointSerializationTests.java @@ -294,18 +294,6 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { private String name = "654321"; - public static class Bar { - private String name = "123456"; - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - } - private Bar bar = new Bar(); public Bar getBar() { @@ -329,6 +317,18 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { return "Name: " + this.name; } + public static class Bar { + private String name = "123456"; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + } + } public static class Cycle extends Foo { @@ -346,6 +346,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { public void setSelf(Foo self) { this.self = self; } + } public static class MapHolder extends Foo { @@ -359,6 +360,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { public void setMap(Map map) { this.map = map; } + } public static class ListHolder extends Foo { @@ -372,6 +374,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests { public void setList(List list) { this.list = list; } + } public static class Addressed extends Foo { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/MetricsEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/MetricsEndpointTests.java index 5eb60461a3d..3d757dd7d1d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/MetricsEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/MetricsEndpointTests.java @@ -46,9 +46,9 @@ public class MetricsEndpointTests extends AbstractEndpointTests private Metric metric1 = new Metric("a", 1); - private Metric metric2 = new Metric("b", 2);; + private Metric metric2 = new Metric("b", 2); - private Metric metric3 = new Metric("c", 3);; + private Metric metric3 = new Metric("c", 3); public MetricsEndpointTests() { super(Config.class, MetricsEndpoint.class, "metrics", true, "endpoints.metrics"); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java index 4f7f529e3f3..ef3ca35a203 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java @@ -170,7 +170,7 @@ public class ElasticsearchHealthIndicatorTests { assertThat((T) details.get(detail), is(equalTo(value))); } - private static class StubClusterHealthResponse extends ClusterHealthResponse { + private final static class StubClusterHealthResponse extends ClusterHealthResponse { private final ClusterHealthStatus status; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MailHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MailHealthIndicatorTests.java index 7505f6b322b..ed5602ee8b6 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MailHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/MailHealthIndicatorTests.java @@ -35,7 +35,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doThrow; +import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.mock; /** @@ -72,7 +72,7 @@ public class MailHealthIndicatorTests { @Test public void smtpIsDown() throws MessagingException { - doThrow(new MessagingException("A test exception")).when(this.mailSender) + willThrow(new MessagingException("A test exception")).given(this.mailSender) .testConnection(); Health health = this.indicator.health(); assertEquals(Status.DOWN, health.getStatus()); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/statsd/StatsdMetricWriterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/statsd/StatsdMetricWriterTests.java index d50b89d9a21..9b7082a4dc5 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/statsd/StatsdMetricWriterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/statsd/StatsdMetricWriterTests.java @@ -120,6 +120,7 @@ public class StatsdMetricWriterTests { .getData(), Charset.forName("UTF-8")).trim()); } catch (Exception e) { + // Ignore } } }).start(); @@ -135,6 +136,7 @@ public class StatsdMetricWriterTests { Thread.sleep(50L); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java index 8fa04d65986..f5454b97e6b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfiguration.java @@ -41,9 +41,6 @@ import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.StringUtils; -import static org.springframework.util.StringUtils.commaDelimitedListToStringArray; -import static org.springframework.util.StringUtils.trimAllWhitespace; - /** * {@link EnableAutoConfiguration Auto-configuration} for {@link MessageSource}. * @@ -90,8 +87,9 @@ public class MessageSourceAutoConfiguration { public MessageSource messageSource() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); if (StringUtils.hasText(this.basename)) { - messageSource - .setBasenames(commaDelimitedListToStringArray(trimAllWhitespace(this.basename))); + messageSource.setBasenames(StringUtils + .commaDelimitedListToStringArray(StringUtils + .trimAllWhitespace(this.basename))); } if (this.encoding != null) { messageSource.setDefaultEncoding(this.encoding.name()); @@ -152,7 +150,8 @@ public class MessageSourceAutoConfiguration { private ConditionOutcome getMatchOutcomeForBasename(ConditionContext context, String basename) { - for (String name : commaDelimitedListToStringArray(trimAllWhitespace(basename))) { + for (String name : StringUtils.commaDelimitedListToStringArray(StringUtils + .trimAllWhitespace(basename))) { for (Resource resource : getResources(context.getClassLoader(), name)) { if (resource.exists()) { return ConditionOutcome.match("Bundle found for " @@ -193,6 +192,7 @@ public class MessageSourceAutoConfiguration { } } catch (Throwable ex) { + // Ignore } ROOT_CLASSLOADER = classLoader; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java index 3f404bd3c2a..0a25d566eab 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java @@ -27,7 +27,10 @@ import org.springframework.util.Assert; * * @author Phillip Webb */ -class CacheConfigurations { +final class CacheConfigurations { + + private CacheConfigurations() { + } private static final Map> MAPPINGS; static { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java index 2165b1fd3b5..a429216b5da 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java @@ -45,7 +45,7 @@ import org.springframework.util.ObjectUtils; * @author Phillip Webb * @author Andy Wilkinson */ -public class ConditionEvaluationReport { +public final class ConditionEvaluationReport { private static final String BEAN_NAME = "autoConfigurationReport"; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java index abf1ad0576e..33f984174e6 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java @@ -103,10 +103,11 @@ public class GroovyTemplateAutoConfiguration { && codeSource.getLocation().toString().contains("-all")) { return true; } + return false; } catch (Exception ex) { + return false; } - return false; } @Bean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateResolver.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateResolver.java index 8b4417df9e6..42bc3329315 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateResolver.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateResolver.java @@ -1,11 +1,11 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.boot.autoconfigure.groovy.template; import java.io.IOException; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java index 64bf06f367d..1453d6ebb28 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java @@ -43,6 +43,12 @@ import org.springframework.integration.monitor.IntegrationMBeanExporter; @AutoConfigureAfter(JmxAutoConfiguration.class) public class IntegrationAutoConfiguration { + @Bean + @ConditionalOnMissingBean(MBeanServer.class) + public MBeanServer mbeanServer() { + return new JmxAutoConfiguration().mbeanServer(); + } + @Configuration @EnableIntegration protected static class IntegrationConfiguration { @@ -56,10 +62,4 @@ public class IntegrationAutoConfiguration { protected static class IntegrationJmxConfiguration { } - @Bean - @ConditionalOnMissingBean(MBeanServer.class) - public MBeanServer mbeanServer() { - return new JmxAutoConfiguration().mbeanServer(); - } - } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java index 974a67de93f..aee6fbc1d1d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java @@ -39,6 +39,13 @@ import org.springframework.context.annotation.Configuration; @ConditionalOnMissingBean(ConnectionFactory.class) class ActiveMQConnectionFactoryConfiguration { + @Bean + @ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "false", matchIfMissing = true) + public ActiveMQConnectionFactory jmsConnectionFactory(ActiveMQProperties properties) { + return new ActiveMQConnectionFactoryFactory(properties) + .createConnectionFactory(ActiveMQConnectionFactory.class); + } + @ConditionalOnClass(PooledConnectionFactory.class) static class PooledConnectionFactoryConfiguration { @@ -55,11 +62,4 @@ class ActiveMQConnectionFactoryConfiguration { } } - @Bean - @ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "false", matchIfMissing = true) - public ActiveMQConnectionFactory jmsConnectionFactory(ActiveMQProperties properties) { - return new ActiveMQConnectionFactoryFactory(properties) - .createConnectionFactory(ActiveMQConnectionFactory.class); - } - } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/package-info.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/package-info.java index d069cf12341..9dffac2ab70 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/package-info.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/package-info.java @@ -20,3 +20,4 @@ * @author EddĂș MelĂ©ndez */ package org.springframework.boot.autoconfigure.jms.artemis; + diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverProperties.java index 3a6a086aa75..f34ee787593 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverProperties.java @@ -67,7 +67,7 @@ public class DeviceDelegatingViewResolverProperties { } public boolean isEnableFallback() { - return enableFallback; + return this.enableFallback; } public String getNormalPrefix() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java index 4674f3863e3..8fc52d228f6 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java @@ -60,8 +60,7 @@ import de.flapdoodle.embed.process.config.io.ProcessOutput; import de.flapdoodle.embed.process.io.Processors; import de.flapdoodle.embed.process.io.Slf4jLevel; import de.flapdoodle.embed.process.io.progress.Slf4jProgressListener; - -import static de.flapdoodle.embed.process.runtime.Network.localhostIsIPv6; +import de.flapdoodle.embed.process.runtime.Network; /** * {@link EnableAutoConfiguration Auto-configuration} for Embedded Mongo. @@ -139,7 +138,7 @@ public class EmbeddedMongoAutoConfiguration { MongodConfigBuilder builder = new MongodConfigBuilder() .version(featureAwareVersion); if (getPort() > 0) { - builder.net(new Net(getPort(), localhostIsIPv6())); + builder.net(new Net(getPort(), Network.localhostIsIPv6())); } return builder.build(); } @@ -196,7 +195,7 @@ public class EmbeddedMongoAutoConfiguration { * A workaround for the lack of a {@code toString} implementation on * {@code GenericFeatureAwareVersion}. */ - private static class ToStringFriendlyFeatureAwareVersion implements + private final static class ToStringFriendlyFeatureAwareVersion implements IFeatureAwareVersion { private final String version; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/EntityManagerFactoryBuilder.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/EntityManagerFactoryBuilder.java index cc70868a236..adea63ee954 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/EntityManagerFactoryBuilder.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/EntityManagerFactoryBuilder.java @@ -80,7 +80,7 @@ public class EntityManagerFactoryBuilder { /** * A fluent builder for a LocalContainerEntityManagerFactoryBean. */ - public class Builder { + public final class Builder { private DataSource dataSource; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java index 7be3da0341a..d91b7bba747 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java @@ -75,6 +75,35 @@ public class OAuth2AuthorizationServerConfiguration extends @Autowired(required = false) private TokenStore tokenStore; + @Override + public void configure(ClientDetailsServiceConfigurer clients) throws Exception { + ClientDetailsServiceBuilder.ClientBuilder builder = clients + .inMemory().withClient(this.details.getClientId()); + builder.secret(this.details.getClientSecret()) + .resourceIds(this.details.getResourceIds().toArray(new String[0])) + .authorizedGrantTypes( + this.details.getAuthorizedGrantTypes().toArray(new String[0])) + .authorities( + AuthorityUtils.authorityListToSet(this.details.getAuthorities()) + .toArray(new String[0])) + .scopes(this.details.getScope().toArray(new String[0])); + if (this.details.getRegisteredRedirectUri() != null) { + builder.redirectUris(this.details.getRegisteredRedirectUri().toArray( + new String[0])); + } + } + + @Override + public void configure(AuthorizationServerEndpointsConfigurer endpoints) + throws Exception { + if (this.tokenStore != null) { + endpoints.tokenStore(this.tokenStore); + } + if (this.details.getAuthorizedGrantTypes().contains("password")) { + endpoints.authenticationManager(this.authenticationManager); + } + } + @Configuration protected static class ClientDetailsLogger { @@ -119,33 +148,4 @@ public class OAuth2AuthorizationServerConfiguration extends } - @Override - public void configure(ClientDetailsServiceConfigurer clients) throws Exception { - ClientDetailsServiceBuilder.ClientBuilder builder = clients - .inMemory().withClient(this.details.getClientId()); - builder.secret(this.details.getClientSecret()) - .resourceIds(this.details.getResourceIds().toArray(new String[0])) - .authorizedGrantTypes( - this.details.getAuthorizedGrantTypes().toArray(new String[0])) - .authorities( - AuthorityUtils.authorityListToSet(this.details.getAuthorities()) - .toArray(new String[0])) - .scopes(this.details.getScope().toArray(new String[0])); - if (this.details.getRegisteredRedirectUri() != null) { - builder.redirectUris(this.details.getRegisteredRedirectUri().toArray( - new String[0])); - } - } - - @Override - public void configure(AuthorizationServerEndpointsConfigurer endpoints) - throws Exception { - if (this.tokenStore != null) { - endpoints.tokenStore(this.tokenStore); - } - if (this.details.getAuthorizedGrantTypes().contains("password")) { - endpoints.authenticationManager(this.authenticationManager); - } - } - } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/TemplateLocation.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/TemplateLocation.java index 5ae444b4cc1..487594a830c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/TemplateLocation.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/TemplateLocation.java @@ -50,13 +50,11 @@ public class TemplateLocation { return true; } try { - if (anyExists(resolver)) { - return true; - } + return anyExists(resolver); } catch (IOException ex) { + return false; } - return false; } private boolean anyExists(ResourcePatternResolver resolver) throws IOException { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java index 27f843167e4..348297f3424 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java @@ -96,14 +96,15 @@ public class BasicErrorController implements ErrorController { protected HttpStatus getStatus(HttpServletRequest request) { Integer statusCode = (Integer) request .getAttribute("javax.servlet.error.status_code"); - if (statusCode != null) { - try { - return HttpStatus.valueOf(statusCode); - } - catch (Exception ex) { - } + if (statusCode == null) { + return HttpStatus.INTERNAL_SERVER_ERROR; + } + try { + return HttpStatus.valueOf(statusCode); + } + catch (Exception ex) { + return HttpStatus.INTERNAL_SERVER_ERROR; } - return HttpStatus.INTERNAL_SERVER_ERROR; } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java index 0b9d8c77eb6..f8fe51b2c5f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java @@ -122,65 +122,59 @@ public class DispatcherServletAutoConfiguration { return checkServletRegistrations(beanFactory); } - } - - private static ConditionOutcome checkServlets( - ConfigurableListableBeanFactory beanFactory) { - List servlets = Arrays.asList(beanFactory.getBeanNamesForType( - DispatcherServlet.class, false, false)); - boolean containsDispatcherBean = beanFactory - .containsBean(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); - if (servlets.isEmpty()) { + private ConditionOutcome checkServlets(ConfigurableListableBeanFactory beanFactory) { + List servlets = Arrays.asList(beanFactory.getBeanNamesForType( + DispatcherServlet.class, false, false)); + boolean containsDispatcherBean = beanFactory + .containsBean(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); + if (servlets.isEmpty()) { + if (containsDispatcherBean) { + return ConditionOutcome.noMatch("found no DispatcherServlet " + + "but a non-DispatcherServlet named " + + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); + } + return ConditionOutcome.match("no DispatcherServlet found"); + } + if (servlets.contains(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) { + return ConditionOutcome.noMatch("found DispatcherServlet named " + + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); + } if (containsDispatcherBean) { - return ConditionOutcome.noMatch("found no DispatcherServlet " - + "but a non-DispatcherServlet named " + return ConditionOutcome.noMatch("found non-DispatcherServlet named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); } - return ConditionOutcome.match("no DispatcherServlet found"); - } - if (servlets.contains(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) { - return ConditionOutcome.noMatch("found DispatcherServlet named " - + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); + return ConditionOutcome.match("one or more DispatcherServlets " + + "found and none is named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); } - if (containsDispatcherBean) { - return ConditionOutcome.noMatch("found non-DispatcherServlet named " - + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); - } - - return ConditionOutcome.match("one or more DispatcherServlets " - + "found and none is named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); - - } - - private static ConditionOutcome checkServletRegistrations( - ConfigurableListableBeanFactory beanFactory) { - List registrations = Arrays.asList(beanFactory.getBeanNamesForType( - ServletRegistrationBean.class, false, false)); - boolean containsDispatcherRegistrationBean = beanFactory - .containsBean(DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); - - if (registrations.isEmpty()) { - if (containsDispatcherRegistrationBean) { - return ConditionOutcome.noMatch("found no ServletRegistrationBean " - + "but a non-ServletRegistrationBean named " + private ConditionOutcome checkServletRegistrations( + ConfigurableListableBeanFactory beanFactory) { + List registrations = Arrays.asList(beanFactory.getBeanNamesForType( + ServletRegistrationBean.class, false, false)); + boolean containsDispatcherRegistrationBean = beanFactory + .containsBean(DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); + if (registrations.isEmpty()) { + if (containsDispatcherRegistrationBean) { + return ConditionOutcome.noMatch("found no ServletRegistrationBean " + + "but a non-ServletRegistrationBean named " + + DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); + } + return ConditionOutcome.match("no ServletRegistrationBean found"); + } + if (registrations.contains(DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME)) { + return ConditionOutcome.noMatch("found ServletRegistrationBean named " + DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); } - return ConditionOutcome.match("no ServletRegistrationBean found"); - } + if (containsDispatcherRegistrationBean) { + return ConditionOutcome + .noMatch("found non-ServletRegistrationBean named " + + DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); + } + return ConditionOutcome + .match("one or more ServletRegistrationBeans is found and none is named " + + DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); - if (registrations.contains(DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME)) { - return ConditionOutcome.noMatch("found ServletRegistrationBean named " - + DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); } - if (containsDispatcherRegistrationBean) { - return ConditionOutcome.noMatch("found non-ServletRegistrationBean named " - + DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); - } - - return ConditionOutcome - .match("one or more ServletRegistrationBeans is found and none is named " - + DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME); - } + } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index b2a30d8c3f5..b5845a18660 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -75,13 +75,12 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNot.not; +import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; /** * Tests for {@link CacheAutoConfiguration}. @@ -145,7 +144,7 @@ public class CacheAutoConfigurationTests { public void simpleCacheExplicit() { load(DefaultCacheConfiguration.class, "spring.cache.type=simple"); ConcurrentMapCacheManager cacheManager = validateCacheManager(ConcurrentMapCacheManager.class); - assertThat(cacheManager.getCacheNames(), is(empty())); + assertThat(cacheManager.getCacheNames(), empty()); } @Test @@ -191,7 +190,7 @@ public class CacheAutoConfigurationTests { public void redisCacheExplicit() { load(RedisCacheConfiguration.class, "spring.cache.type=redis"); RedisCacheManager cacheManager = validateCacheManager(RedisCacheManager.class); - assertThat(cacheManager.getCacheNames(), is(empty())); + assertThat(cacheManager.getCacheNames(), empty()); } @Test @@ -207,7 +206,7 @@ public class CacheAutoConfigurationTests { public void noOpCacheExplicit() { load(DefaultCacheConfiguration.class, "spring.cache.type=none"); NoOpCacheManager cacheManager = validateCacheManager(NoOpCacheManager.class); - assertThat(cacheManager.getCacheNames(), is(empty())); + assertThat(cacheManager.getCacheNames(), empty()); } @Test @@ -224,9 +223,9 @@ public class CacheAutoConfigurationTests { load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); - assertThat(cacheManager.getCacheNames(), is(empty())); + assertThat(cacheManager.getCacheNames(), empty()); assertThat(this.context.getBean(javax.cache.CacheManager.class), - is(cacheManager.getCacheManager())); + equalTo(cacheManager.getCacheManager())); } @Test @@ -263,7 +262,7 @@ public class CacheAutoConfigurationTests { load(JCacheCustomCacheManager.class, "spring.cache.type=jcache"); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); assertThat(cacheManager.getCacheManager(), - is(this.context.getBean("customJCacheCacheManager"))); + equalTo(this.context.getBean("customJCacheCacheManager"))); } @Test @@ -284,7 +283,8 @@ public class CacheAutoConfigurationTests { "spring.cache.jcache.config=" + configLocation); JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); Resource configResource = new ClassPathResource(configLocation); - assertThat(cacheManager.getCacheManager().getURI(), is(configResource.getURI())); + assertThat(cacheManager.getCacheManager().getURI(), + equalTo(configResource.getURI())); } @Test @@ -307,7 +307,7 @@ public class CacheAutoConfigurationTests { containsInAnyOrder("cacheTest1", "cacheTest2")); assertThat(cacheManager.getCacheNames(), hasSize(2)); assertThat(this.context.getBean(net.sf.ehcache.CacheManager.class), - is(cacheManager.getCacheManager())); + equalTo(cacheManager.getCacheManager())); } @Test @@ -325,7 +325,7 @@ public class CacheAutoConfigurationTests { load(EhCacheCustomCacheManager.class, "spring.cache.type=ehcache"); EhCacheCacheManager cacheManager = validateCacheManager(EhCacheCacheManager.class); assertThat(cacheManager.getCacheManager(), - is(this.context.getBean("customEhCacheCacheManager"))); + equalTo(this.context.getBean("customEhCacheCacheManager"))); } @Test @@ -337,7 +337,7 @@ public class CacheAutoConfigurationTests { assertThat(cacheManager.getCacheNames(), containsInAnyOrder("defaultCache")); assertThat(cacheManager.getCacheNames(), hasSize(1)); assertThat(this.context.getBean(HazelcastInstance.class), - is(new DirectFieldAccessor(cacheManager) + equalTo(new DirectFieldAccessor(cacheManager) .getPropertyValue("hazelcastInstance"))); } @@ -367,7 +367,7 @@ public class CacheAutoConfigurationTests { assertThat( new DirectFieldAccessor(cacheManager) .getPropertyValue("hazelcastInstance"), - is(this.context.getBean("customHazelcastInstance"))); + equalTo(this.context.getBean("customHazelcastInstance"))); } @Test @@ -384,9 +384,9 @@ public class CacheAutoConfigurationTests { assertThat( new DirectFieldAccessor(cacheManager) .getPropertyValue("hazelcastInstance"), - is((Object) hazelcastInstance)); + equalTo((Object) hazelcastInstance)); assertThat(hazelcastInstance.getConfig().getConfigurationFile(), - is(new ClassPathResource(mainConfig).getFile())); + equalTo(new ClassPathResource(mainConfig).getFile())); } @Test @@ -404,11 +404,11 @@ public class CacheAutoConfigurationTests { HazelcastCacheManager cacheManager = validateCacheManager(HazelcastCacheManager.class); HazelcastInstance cacheHazelcastInstance = (HazelcastInstance) new DirectFieldAccessor( cacheManager).getPropertyValue("hazelcastInstance"); - assertThat(cacheHazelcastInstance, is(not(hazelcastInstance))); // Our custom + assertThat(cacheHazelcastInstance, not(hazelcastInstance)); // Our custom assertThat(hazelcastInstance.getConfig().getConfigurationFile(), - is(new ClassPathResource(mainConfig).getFile())); + equalTo(new ClassPathResource(mainConfig).getFile())); assertThat(cacheHazelcastInstance.getConfig().getConfigurationFile(), - is(new ClassPathResource(cacheConfig).getFile())); + equalTo(new ClassPathResource(cacheConfig).getFile())); } @Test @@ -432,7 +432,8 @@ public class CacheAutoConfigurationTests { JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); Resource configResource = new ClassPathResource(configLocation); - assertThat(cacheManager.getCacheManager().getURI(), is(configResource.getURI())); + assertThat(cacheManager.getCacheManager().getURI(), + equalTo(configResource.getURI())); } @Test @@ -486,7 +487,8 @@ public class CacheAutoConfigurationTests { JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class); Resource configResource = new ClassPathResource(configLocation); - assertThat(cacheManager.getCacheManager().getURI(), is(configResource.getURI())); + assertThat(cacheManager.getCacheManager().getURI(), + equalTo(configResource.getURI())); } @Test @@ -538,7 +540,7 @@ public class CacheAutoConfigurationTests { private T validateCacheManager(Class type) { CacheManager cacheManager = this.context.getBean(CacheManager.class); - assertThat("Wrong cache manager type", cacheManager, is(instanceOf(type))); + assertThat("Wrong cache manager type", cacheManager, instanceOf(type)); return type.cast(cacheManager); } @@ -615,8 +617,8 @@ public class CacheAutoConfigurationTests { @Bean public javax.cache.CacheManager customJCacheCacheManager() { javax.cache.CacheManager cacheManager = mock(javax.cache.CacheManager.class); - when(cacheManager.getCacheNames()) - .thenReturn(Collections.emptyList()); + given(cacheManager.getCacheNames()).willReturn( + Collections.emptyList()); return cacheManager; } @@ -650,8 +652,8 @@ public class CacheAutoConfigurationTests { @Bean public net.sf.ehcache.CacheManager customEhCacheCacheManager() { net.sf.ehcache.CacheManager cacheManager = mock(net.sf.ehcache.CacheManager.class); - when(cacheManager.getStatus()).thenReturn(Status.STATUS_ALIVE); - when(cacheManager.getCacheNames()).thenReturn(new String[0]); + given(cacheManager.getStatus()).willReturn(Status.STATUS_ALIVE); + given(cacheManager.getCacheNames()).willReturn(new String[0]); return cacheManager; } @@ -675,7 +677,7 @@ public class CacheAutoConfigurationTests { @Bean public ConfigurationBuilder configurationBuilder() { ConfigurationBuilder builder = mock(ConfigurationBuilder.class); - when(builder.build()).thenReturn(new ConfigurationBuilder().build()); + given(builder.build()).willReturn(new ConfigurationBuilder().build()); return builder; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnSingleCandidateTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnSingleCandidateTests.java index f6579c8dc4d..a215ade28df 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnSingleCandidateTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnSingleCandidateTests.java @@ -108,7 +108,7 @@ public class ConditionalOnSingleCandidateTests { } @Configuration - @ConditionalOnSingleCandidate(value = String.class) + @ConditionalOnSingleCandidate(String.class) protected static class OnBeanSingleCandidateConfiguration { @Bean 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 7329e83da72..0a7142a5278 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 @@ -25,7 +25,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; -import static org.hamcrest.core.Is.is; +import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; /** @@ -47,13 +47,13 @@ public class ConfigurationPropertiesAutoConfigurationTests { @Test public void processAnnotatedBean() { load(new Class[] { AutoConfig.class, SampleBean.class }, "foo.name:test"); - assertThat(this.context.getBean(SampleBean.class).getName(), is("test")); + assertThat(this.context.getBean(SampleBean.class).getName(), equalTo("test")); } @Test public void processAnnotatedBeanNoAutoConfig() { load(new Class[] { SampleBean.class }, "foo.name:test"); - assertThat(this.context.getBean(SampleBean.class).getName(), is("default")); + assertThat(this.context.getBean(SampleBean.class).getName(), equalTo("default")); } private void load(Class[] configs, String... environment) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/SolrRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/SolrRepositoriesAutoConfigurationTests.java index 4beccbbbf5c..2a75d93ce89 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/SolrRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/solr/SolrRepositoriesAutoConfigurationTests.java @@ -32,8 +32,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Configuration; import org.springframework.data.solr.repository.config.EnableSolrRepositories; -import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.hamcrest.core.IsNull.notNullValue; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; /** diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index ee151c6e44c..cd17875d853 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -52,7 +52,7 @@ public class FlywayAutoConfigurationTests { @Rule public ExpectedException thrown = ExpectedException.none(); - private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();; + private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); @Before public void init() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java index e5a29523007..99f740ec24f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java @@ -35,9 +35,9 @@ import com.hazelcast.config.QueueConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.collection.IsMapContaining.hasKey; -import static org.hamcrest.core.Is.is; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertThat; /** @@ -65,7 +65,7 @@ public class HazelcastAutoConfigurationTests { HazelcastInstance hazelcastInstance = this.context .getBean(HazelcastInstance.class); assertThat(hazelcastInstance.getConfig().getConfigurationUrl(), - is(new ClassPathResource("hazelcast.xml").getURL())); + equalTo(new ClassPathResource("hazelcast.xml").getURL())); } @Test @@ -93,7 +93,7 @@ public class HazelcastAutoConfigurationTests { HazelcastInstance hazelcastInstance = this.context .getBean(HazelcastInstance.class); assertThat(hazelcastInstance.getConfig().getConfigurationFile(), - is(new ClassPathResource( + equalTo(new ClassPathResource( "org/springframework/boot/autoconfigure/hazelcast" + "/hazelcast-specific.xml").getFile())); } @@ -104,7 +104,7 @@ public class HazelcastAutoConfigurationTests { HazelcastInstance hazelcastInstance = this.context .getBean(HazelcastInstance.class); assertThat(hazelcastInstance.getConfig().getConfigurationUrl(), - is(new ClassPathResource("hazelcast-default.xml").getURL())); + equalTo(new ClassPathResource("hazelcast-default.xml").getURL())); } @Test @@ -125,9 +125,9 @@ public class HazelcastAutoConfigurationTests { HazelcastInstance hazelcastInstance = this.context .getBean(HazelcastInstance.class); assertThat(hazelcastInstance.getConfig().getInstanceName(), - is("my-test-instance")); + equalTo("my-test-instance")); // Should reuse any existing instance by default. - assertThat(hazelcastInstance, is(existingHazelcastInstance)); + assertThat(hazelcastInstance, equalTo(existingHazelcastInstance)); } finally { existingHazelcastInstance.shutdown(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java index e13d478184d..ed1aeb16311 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java @@ -160,13 +160,6 @@ public class JacksonAutoConfigurationTests { assertThat(mapper.getDateFormat(), is(instanceOf(MyDateFormat.class))); } - public static class MyDateFormat extends SimpleDateFormat { - - public MyDateFormat() { - super("yyyy-MM-dd HH:mm:ss"); - } - } - @Test public void noCustomPropertyNamingStrategy() throws Exception { this.context.register(JacksonAutoConfiguration.class); @@ -419,6 +412,13 @@ public class JacksonAutoConfigurationTests { objectMapper.writeValueAsString(dateTime)); } + public static class MyDateFormat extends SimpleDateFormat { + + public MyDateFormat() { + super("yyyy-MM-dd HH:mm:ss"); + } + } + @Configuration protected static class MockObjectMapperConfig { @@ -469,7 +469,7 @@ public class JacksonAutoConfigurationTests { } - protected static class Foo { + protected static final class Foo { private String name; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java index 95b880757bb..f7c356e19f5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java @@ -309,7 +309,7 @@ public class ArtemisAutoConfigurationTests { return applicationContext; } - private static class DestinationChecker { + private final static class DestinationChecker { private final JmsTemplate jmsTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfigurationTests.java index cb85bf2d7af..f83d9841f2a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/hornetq/HornetQAutoConfigurationTests.java @@ -323,7 +323,7 @@ public class HornetQAutoConfigurationTests { return applicationContext; } - private static class DestinationChecker { + private final static class DestinationChecker { private final JmsTemplate jmsTemplate; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jndi/TestableInitialContextFactory.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jndi/TestableInitialContextFactory.java index 50f018abdc4..7f8241f9736 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jndi/TestableInitialContextFactory.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jndi/TestableInitialContextFactory.java @@ -64,7 +64,7 @@ public class TestableInitialContextFactory implements InitialContextFactory { return context; } - private static class TestableContext extends InitialContext { + private final static class TestableContext extends InitialContext { private final Map bindings = new HashMap(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java index 4a0628c41d9..145c1570118 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java @@ -110,6 +110,7 @@ public class JooqAutoConfigurationTests { fail("An DataIntegrityViolationException should have been thrown."); } catch (DataIntegrityViolationException ex) { + // Ignore } dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest;", equalTo("2"))); @@ -137,6 +138,7 @@ public class JooqAutoConfigurationTests { fail("A DataIntegrityViolationException should have been thrown."); } catch (DataIntegrityViolationException ex) { + // Ignore } dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest_tx;", equalTo("1"))); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java index 486c7941ab2..a8c91973e14 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java @@ -24,10 +24,12 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration; +import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.util.SocketUtils; import com.mongodb.CommandResult; import com.mongodb.MongoClient; @@ -36,10 +38,7 @@ import de.flapdoodle.embed.mongo.distribution.Feature; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; -import static org.springframework.boot.test.EnvironmentTestUtils.addEnvironment; -import static org.springframework.util.SocketUtils.findAvailableTcpPort; /** * Tests for {@link EmbeddedMongoAutoConfiguration}. @@ -71,9 +70,9 @@ public class EmbeddedMongoAutoConfigurationTests { @Test public void customFeatures() { this.context = new AnnotationConfigApplicationContext(); - int mongoPort = findAvailableTcpPort(); - addEnvironment(this.context, "spring.data.mongodb.port=" + mongoPort, - "spring.mongodb.embedded.features=TEXT_SEARCH, SYNC_DELAY"); + int mongoPort = SocketUtils.findAvailableTcpPort(); + EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=" + + mongoPort, "spring.mongodb.embedded.features=TEXT_SEARCH, SYNC_DELAY"); this.context.register(EmbeddedMongoAutoConfiguration.class); this.context.refresh(); assertThat(this.context.getBean(EmbeddedMongoProperties.class).getFeatures(), @@ -83,25 +82,26 @@ public class EmbeddedMongoAutoConfigurationTests { @Test public void randomlyAllocatedPortIsAvailableWhenCreatingMongoClient() { this.context = new AnnotationConfigApplicationContext(); - addEnvironment(this.context, "spring.data.mongodb.port=0"); + EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=0"); this.context.register(EmbeddedMongoAutoConfiguration.class, MongoClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertThat( this.context.getBean(MongoClient.class).getAddress().getPort(), - is(equalTo(Integer.valueOf(this.context.getEnvironment().getProperty( - "local.mongo.port"))))); + equalTo(Integer.valueOf(this.context.getEnvironment().getProperty( + "local.mongo.port")))); } private void assertVersionConfiguration(String configuredVersion, String expectedVersion) { this.context = new AnnotationConfigApplicationContext(); - int mongoPort = findAvailableTcpPort(); - addEnvironment(this.context, "spring.data.mongodb.port=" + mongoPort); + int mongoPort = SocketUtils.findAvailableTcpPort(); + EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=" + + mongoPort); if (configuredVersion != null) { - addEnvironment(this.context, "spring.mongodb.embedded.version=" - + configuredVersion); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.mongodb.embedded.version=" + configuredVersion); } this.context.register(MongoAutoConfiguration.class, MongoDataAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java index 877cf8dc190..66a89918ee4 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java @@ -345,6 +345,7 @@ public class SecurityAutoConfigurationTests { fail("Expected Exception"); } catch (AuthenticationException success) { + // Expected } token = new UsernamePasswordAuthenticationToken("foo", "bar"); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java index 5e845e8da25..458c6b6b043 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java @@ -92,7 +92,7 @@ import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.databind.JsonNode; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertThat; /** * Verify Spring Security OAuth2 auto-configuration secures end points properly, accepts diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoConfigurationTests.java index 9ae5b409f87..ff6bd2594ab 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/CustomOAuth2SsoConfigurationTests.java @@ -109,7 +109,7 @@ public class CustomOAuth2SsoConfigurationTests { @RestController public static class TestController { - @RequestMapping(value = "/ui/test") + @RequestMapping("/ui/test") public String test() { return "test"; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/AbstractSocialAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/AbstractSocialAutoConfigurationTests.java index 9da33428109..41402752a3c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/AbstractSocialAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/AbstractSocialAutoConfigurationTests.java @@ -67,6 +67,7 @@ public class AbstractSocialAutoConfigurationTests { fail("Unexpected bean in context of type " + beanClass.getName()); } catch (NoSuchBeanDefinitionException ex) { + // Expected } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/template/ViewResolverPropertiesTest.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/template/ViewResolverPropertiesTest.java index b9c14760abd..04a0559e8a8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/template/ViewResolverPropertiesTest.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/template/ViewResolverPropertiesTest.java @@ -21,8 +21,8 @@ import java.nio.charset.Charset; import org.junit.Test; import org.springframework.util.MimeTypeUtils; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasToString; +import static org.junit.Assert.assertThat; /** * Tests for {@link AbstractViewResolverProperties}. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/jta/JtaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/jta/JtaAutoConfigurationTests.java index 9b574631c4a..a4d89f77858 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/jta/JtaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/jta/JtaAutoConfigurationTests.java @@ -64,8 +64,8 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Tests for {@link JtaAutoConfiguration}. @@ -276,10 +276,10 @@ public class JtaAutoConfigurationTests { XASession session = mock(XASession.class); TemporaryQueue queue = mock(TemporaryQueue.class); XAResource resource = mock(XAResource.class); - when(connectionFactory.createXAConnection()).thenReturn(connection); - when(connection.createXASession()).thenReturn(session); - when(session.createTemporaryQueue()).thenReturn(queue); - when(session.getXAResource()).thenReturn(resource); + given(connectionFactory.createXAConnection()).willReturn(connection); + given(connection.createXASession()).willReturn(session); + given(session.createTemporaryQueue()).willReturn(queue); + given(session.getXAResource()).willReturn(resource); return wrapper.wrapConnectionFactory(connectionFactory); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java index 517ee3037da..764ba535f83 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java @@ -101,7 +101,7 @@ public class BasicErrorControllerDirectMockMvcTests { WebMvcIncludedConfiguration.class).run("--server.port=0", "--error.whitelabel.enabled=false")); - thrown.expect(ServletException.class); + this.thrown.expect(ServletException.class); this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML)); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java index e10ef732e74..e91af18df92 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java @@ -174,7 +174,7 @@ public class BasicErrorControllerIntegrationTests { } - @ResponseStatus(value = HttpStatus.NOT_ACCEPTABLE) + @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) @SuppressWarnings("serial") private static class NoReasonExpectedException extends RuntimeException { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java index e5073bf201c..748cc447eb2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java @@ -186,7 +186,7 @@ public class BasicErrorControllerMockMvcTests { } - @ResponseStatus(value = HttpStatus.NOT_FOUND) + @ResponseStatus(HttpStatus.NOT_FOUND) private static class NotFoundException extends RuntimeException { public NotFoundException(String string) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java index e4454c50411..54fe9b7e8dd 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java @@ -95,10 +95,6 @@ public class MultipartAutoConfigurationTests { equalTo(1)); } - @Configuration - public static class ContainerWithNothing { - } - @Test public void containerWithNoMultipartJettyConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( @@ -112,19 +108,6 @@ public class MultipartAutoConfigurationTests { verifyServletWorks(); } - @Configuration - public static class ContainerWithNoMultipartJetty { - @Bean - JettyEmbeddedServletContainerFactory containerFactory() { - return new JettyEmbeddedServletContainerFactory(); - } - - @Bean - WebController controller() { - return new WebController(); - } - } - @Test public void containerWithNoMultipartUndertowConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( @@ -138,19 +121,6 @@ public class MultipartAutoConfigurationTests { equalTo(1)); } - @Configuration - public static class ContainerWithNoMultipartUndertow { - @Bean - UndertowEmbeddedServletContainerFactory containerFactory() { - return new UndertowEmbeddedServletContainerFactory(); - } - - @Bean - WebController controller() { - return new WebController(); - } - } - @Test public void containerWithNoMultipartTomcatConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( @@ -249,6 +219,36 @@ public class MultipartAutoConfigurationTests { String.class)); } + @Configuration + public static class ContainerWithNothing { + } + + @Configuration + public static class ContainerWithNoMultipartJetty { + @Bean + JettyEmbeddedServletContainerFactory containerFactory() { + return new JettyEmbeddedServletContainerFactory(); + } + + @Bean + WebController controller() { + return new WebController(); + } + } + + @Configuration + public static class ContainerWithNoMultipartUndertow { + @Bean + UndertowEmbeddedServletContainerFactory containerFactory() { + return new UndertowEmbeddedServletContainerFactory(); + } + + @Bean + WebController controller() { + return new WebController(); + } + } + @Configuration @Import({ EmbeddedServletContainerAutoConfiguration.class, DispatcherServletAutoConfiguration.class, MultipartAutoConfiguration.class, diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 3592e24e324..646aff9ac98 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -42,7 +42,7 @@ import org.springframework.boot.context.embedded.ServletContextInitializer; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java index d7563985b3a..d938fee9087 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java @@ -34,7 +34,10 @@ import org.springframework.boot.loader.tools.LogbackInitializer; * @see #main(String...) * @see CommandRunner */ -public class SpringCli { +public final class SpringCli { + + private SpringCli() { + } public static void main(String... args) { System.setProperty("java.awt.headless", Boolean.toString(true)); diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrService.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrService.java index 27ebbe2a0c5..85f6a0bd2aa 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrService.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrService.java @@ -219,6 +219,7 @@ class InitializrService { } } catch (Exception ex) { + // Ignore } } return null; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrServiceMetadata.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrServiceMetadata.java index 5d375c7166c..3bf83a36786 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrServiceMetadata.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitializrServiceMetadata.java @@ -220,7 +220,7 @@ class InitializrServiceMetadata { return result; } - private static class MetadataHolder { + private final static class MetadataHolder { private final Map content; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java index 08c54887c9d..22dab37133a 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java @@ -90,6 +90,7 @@ class ProjectGenerator { return ZIP_MIME_TYPE.equals(entity.getContentType().getMimeType()); } catch (Exception ex) { + // Ignore } } return false; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/CompilerOptionHandler.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/CompilerOptionHandler.java index 926d9d27b31..287dcf6a98e 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/CompilerOptionHandler.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/CompilerOptionHandler.java @@ -16,9 +16,9 @@ package org.springframework.boot.cli.command.options; -import joptsimple.OptionSpec; +import java.util.Arrays; -import static java.util.Arrays.asList; +import joptsimple.OptionSpec; /** * An {@link OptionHandler} for commands that result in the compilation of one or more @@ -46,7 +46,7 @@ public class CompilerOptionHandler extends OptionHandler { this.autoconfigureOption = option("autoconfigure", "Add autoconfigure compiler transformations").withOptionalArg() .ofType(Boolean.class).defaultsTo(true); - this.classpathOption = option(asList("classpath", "cp"), + this.classpathOption = option(Arrays.asList("classpath", "cp"), "Additional classpath entries").withRequiredArg(); doOptions(); } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java index efb387f295a..1dea781212f 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/RunCommand.java @@ -17,6 +17,7 @@ package org.springframework.boot.cli.command.run; import java.io.File; +import java.util.Arrays; import java.util.List; import java.util.logging.Level; @@ -33,8 +34,6 @@ import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration; import joptsimple.OptionSet; import joptsimple.OptionSpec; -import static java.util.Arrays.asList; - /** * {@link Command} to 'run' a groovy script or scripts. * @@ -73,9 +72,9 @@ public class RunCommand extends OptionParsingCommand { @Override protected void doOptions() { this.watchOption = option("watch", "Watch the specified file for changes"); - this.verboseOption = option(asList("verbose", "v"), + this.verboseOption = option(Arrays.asList("verbose", "v"), "Verbose logging of dependency resolution"); - this.quietOption = option(asList("quiet", "q"), "Quiet logging"); + this.quietOption = option(Arrays.asList("quiet", "q"), "Quiet logging"); } public synchronized void stop() { diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/SpringApplicationRunner.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/SpringApplicationRunner.java index 9d9f6be2bdc..0e37ad88ccf 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/SpringApplicationRunner.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/run/SpringApplicationRunner.java @@ -17,6 +17,7 @@ package org.springframework.boot.cli.command.run; import java.io.File; +import java.io.IOException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; @@ -89,22 +90,9 @@ public class SpringApplicationRunner { */ public synchronized void compileAndRun() throws Exception { try { - stop(); - - // Compile - Object[] compiledSources = this.compiler.compile(this.sources); - if (compiledSources.length == 0) { - throw new RuntimeException("No classes found in '" + this.sources + "'"); - } - - // Start monitoring for changes - if (this.fileWatchThread == null - && this.configuration.isWatchForFileChanges()) { - this.fileWatchThread = new FileWatchThread(); - this.fileWatchThread.start(); - } - + Object[] compiledSources = compile(); + monitorForChanges(); // Run in new thread to ensure that the context classloader is setup this.runThread = new RunThread(compiledSources); this.runThread.start(); @@ -120,6 +108,28 @@ public class SpringApplicationRunner { } } + public void stop() { + if (this.runThread != null) { + this.runThread.shutdown(); + this.runThread = null; + } + } + + private Object[] compile() throws IOException { + Object[] compiledSources = this.compiler.compile(this.sources); + if (compiledSources.length == 0) { + throw new RuntimeException("No classes found in '" + this.sources + "'"); + } + return compiledSources; + } + + private void monitorForChanges() { + if (this.fileWatchThread == null && this.configuration.isWatchForFileChanges()) { + this.fileWatchThread = new FileWatchThread(); + this.fileWatchThread.start(); + } + } + /** * Thread used to launch the Spring Application with the correct context classloader. */ @@ -246,11 +256,4 @@ public class SpringApplicationRunner { } - public void stop() { - if (this.runThread != null) { - this.runThread.shutdown(); - this.runThread = null; - } - } - } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AstUtils.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AstUtils.java index 605266253e1..df86fe1a91a 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AstUtils.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AstUtils.java @@ -19,6 +19,7 @@ package org.springframework.boot.cli.compiler; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.codehaus.groovy.ast.AnnotatedNode; @@ -147,32 +148,44 @@ public abstract class AstUtils { */ public static ClosureExpression getClosure(BlockStatement block, String name, boolean remove) { - - for (Statement statement : new ArrayList(block.getStatements())) { - if (statement instanceof ExpressionStatement) { - Expression expression = ((ExpressionStatement) statement).getExpression(); - if (expression instanceof MethodCallExpression) { - MethodCallExpression call = (MethodCallExpression) expression; - Expression methodCall = call.getMethod(); - if (methodCall instanceof ConstantExpression) { - ConstantExpression method = (ConstantExpression) methodCall; - if (name.equals(method.getValue())) { - ArgumentListExpression arguments = (ArgumentListExpression) call - .getArguments(); - if (remove) { - block.getStatements().remove(statement); - } - ClosureExpression closure = (ClosureExpression) arguments - .getExpression(0); - return closure; - } + for (ExpressionStatement statement : getExpressionStatements(block)) { + Expression expression = statement.getExpression(); + if (expression instanceof MethodCallExpression) { + ClosureExpression closure = getClosure(name, + (MethodCallExpression) expression); + if (closure != null) { + if (remove) { + block.getStatements().remove(statement); } + return closure; } } } return null; } + private static List getExpressionStatements(BlockStatement block) { + ArrayList statements = new ArrayList(); + for (Statement statement : block.getStatements()) { + if (statement instanceof ExpressionStatement) { + statements.add((ExpressionStatement) statement); + } + } + return statements; + } + + private static ClosureExpression getClosure(String name, + MethodCallExpression expression) { + Expression method = expression.getMethod(); + if (method instanceof ConstantExpression) { + if (name.equals(((ConstantExpression) method).getValue())) { + return (ClosureExpression) ((ArgumentListExpression) expression + .getArguments()).getExpression(0); + } + } + return null; + } + public static ClosureExpression getClosure(BlockStatement block, String name) { return getClosure(block, name, false); } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java index 227a81771e2..83da6d3325b 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java @@ -200,7 +200,7 @@ public class GroovyCompiler { for (Object loadedClass : collector.getLoadedClasses()) { classes.add((Class) loadedClass); } - ClassNode mainClassNode = getMainClass(compilationUnit); + ClassNode mainClassNode = MainClass.get(compilationUnit); Class mainClass = null; for (Class loadedClass : classes) { @@ -275,7 +275,7 @@ public class GroovyCompiler { ImportCustomizer importCustomizer = new SmartImportCustomizer(source, context, classNode); - ClassNode mainClassNode = getMainClass(source.getAST().getClasses()); + ClassNode mainClassNode = MainClass.get(source.getAST().getClasses()); // Additional auto configuration for (CompilerAutoConfiguration autoConfiguration : GroovyCompiler.this.compilerAutoConfigurations) { @@ -300,22 +300,27 @@ public class GroovyCompiler { } - @SuppressWarnings("unchecked") - private static ClassNode getMainClass(CompilationUnit source) { - return getMainClass(source.getAST().getClasses()); - } + private static class MainClass { - private static ClassNode getMainClass(List classes) { - for (ClassNode node : classes) { - if (AstUtils.hasAtLeastOneAnnotation(node, "Enable*AutoConfiguration")) { - return null; // No need to enhance this - } - if (AstUtils.hasAtLeastOneAnnotation(node, "*Controller", "Configuration", - "Component", "*Service", "Repository", "Enable*")) { - return node; + @SuppressWarnings("unchecked") + public static ClassNode get(CompilationUnit source) { + return get(source.getAST().getClasses()); + } + + public static ClassNode get(List classes) { + for (ClassNode node : classes) { + if (AstUtils.hasAtLeastOneAnnotation(node, "Enable*AutoConfiguration")) { + return null; // No need to enhance this + } + if (AstUtils + .hasAtLeastOneAnnotation(node, "*Controller", "Configuration", + "Component", "*Service", "Repository", "Enable*")) { + return node; + } } + return (classes.isEmpty() ? null : classes.get(0)); } - return (classes.isEmpty() ? null : classes.get(0)); + } } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/jar/PackagedSpringApplicationLauncher.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/jar/PackagedSpringApplicationLauncher.java index 10f6a817a8d..5454dbf4d20 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/jar/PackagedSpringApplicationLauncher.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/jar/PackagedSpringApplicationLauncher.java @@ -30,12 +30,15 @@ import org.springframework.boot.cli.app.SpringApplicationLauncher; * @author Andy Wilkinson * @author Phillip Webb */ -public class PackagedSpringApplicationLauncher { +public final class PackagedSpringApplicationLauncher { public static final String SOURCE_ENTRY = "Spring-Application-Source-Classes"; public static final String START_CLASS_ENTRY = "Start-Class"; + private PackagedSpringApplicationLauncher() { + } + private void run(String[] args) throws Exception { URLClassLoader classLoader = (URLClassLoader) Thread.currentThread() .getContextClassLoader(); diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java index 2177e517b62..0e38d2c58ca 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java @@ -27,7 +27,10 @@ import org.springframework.boot.cli.command.test.TestRunner; * @author Phillip Webb * @see TestRunner */ -public class DelegateTestRunner { +public final class DelegateTestRunner { + + private DelegateTestRunner() { + } public static void run(Class[] testClasses, Result result) { JUnitCore jUnitCore = new JUnitCore(); diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitializrServiceTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitializrServiceTests.java index a2d14457aca..7acf8ddf966 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitializrServiceTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitializrServiceTests.java @@ -24,13 +24,13 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import static junit.framework.TestCase.assertNotNull; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Tests for {@link InitializrService} @@ -104,7 +104,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests { mockSuccessfulMetadataGet(false); CloseableHttpResponse response = mock(CloseableHttpResponse.class); mockStatus(response, 500); - when(this.http.execute(isA(HttpGet.class))).thenReturn(response); + given(this.http.execute(isA(HttpGet.class))).willReturn(response); ProjectGenerationRequest request = new ProjectGenerationRequest(); this.thrown.expect(ReportableException.class); this.thrown.expectMessage("No content received from server"); @@ -126,7 +126,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests { CloseableHttpResponse response = mock(CloseableHttpResponse.class); mockHttpEntity(response, "Foo-Bar-Not-JSON".getBytes(), "application/json"); mockStatus(response, 200); - when(this.http.execute(isA(HttpGet.class))).thenReturn(response); + given(this.http.execute(isA(HttpGet.class))).willReturn(response); ProjectGenerationRequest request = new ProjectGenerationRequest(); this.thrown.expect(ReportableException.class); this.thrown.expectMessage("Invalid content received from server"); @@ -137,7 +137,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests { public void loadMetadataNoContent() throws IOException { CloseableHttpResponse response = mock(CloseableHttpResponse.class); mockStatus(response, 500); - when(this.http.execute(isA(HttpGet.class))).thenReturn(response); + given(this.http.execute(isA(HttpGet.class))).willReturn(response); ProjectGenerationRequest request = new ProjectGenerationRequest(); this.thrown.expect(ReportableException.class); this.thrown.expectMessage("No content received from server"); diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/ServiceCapabilitiesReportGeneratorTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/ServiceCapabilitiesReportGeneratorTests.java index 69a073a985a..9759e7484be 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/ServiceCapabilitiesReportGeneratorTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/ServiceCapabilitiesReportGeneratorTests.java @@ -21,7 +21,7 @@ import java.io.IOException; import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.core.StringContains.containsString; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertThat; /** diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/util/SystemProperties.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/util/SystemProperties.java index 217691b4c73..48c3c10cfec 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/util/SystemProperties.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/util/SystemProperties.java @@ -25,7 +25,10 @@ import java.util.Map.Entry; * * @author Andy Wilkinson */ -public class SystemProperties { +public final class SystemProperties { + + private SystemProperties() { + } /** * Performs the given {@code action} with the given system properties set. System diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/RemoteSpringApplication.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/RemoteSpringApplication.java index 5ed574f35c5..17a65bfd21b 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/RemoteSpringApplication.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/RemoteSpringApplication.java @@ -35,7 +35,10 @@ import org.springframework.core.io.ClassPathResource; * @since 1.3.0 * @see RemoteClientConfiguration */ -public class RemoteSpringApplication { +public final class RemoteSpringApplication { + + private RemoteSpringApplication() { + } private void run(String[] args) { Restarter.initialize(args, RestartInitializer.NONE); @@ -60,6 +63,7 @@ public class RemoteSpringApplication { Thread.sleep(1000); } catch (InterruptedException ex) { + // Ignore } } } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/FileWatchingFailureHandler.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/FileWatchingFailureHandler.java index 47accf60183..9614d054313 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/FileWatchingFailureHandler.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/FileWatchingFailureHandler.java @@ -53,6 +53,7 @@ class FileWatchingFailureHandler implements FailureHandler { latch.await(); } catch (InterruptedException ex) { + // Ignore } return Outcome.RETRY; } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/filewatch/FileSystemWatcher.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/filewatch/FileSystemWatcher.java index cbafbdbf389..c2d8f3c9895 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/filewatch/FileSystemWatcher.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/filewatch/FileSystemWatcher.java @@ -149,6 +149,7 @@ public class FileSystemWatcher { scan(); } catch (InterruptedException ex) { + // Ignore } remainingScans = FileSystemWatcher.this.remainingScans.get(); } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/livereload/Base64Encoder.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/livereload/Base64Encoder.java index 2116166632a..65f37db04cb 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/livereload/Base64Encoder.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/livereload/Base64Encoder.java @@ -23,7 +23,7 @@ import java.nio.charset.Charset; * * @author Phillip Webb */ -class Base64Encoder { +final class Base64Encoder { private static final Charset UTF_8 = Charset.forName("UTF-8"); @@ -34,6 +34,9 @@ class Base64Encoder { private static final byte EQUALS_SIGN = '='; + private Base64Encoder() { + } + public static String encode(String string) { return encode(string.getBytes(UTF_8)); } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/DelayedLiveReloadTrigger.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/DelayedLiveReloadTrigger.java index 1a56b402794..183cd3c0917 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/DelayedLiveReloadTrigger.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/DelayedLiveReloadTrigger.java @@ -95,6 +95,7 @@ class DelayedLiveReloadTrigger implements Runnable { this.liveReloadServer.triggerReload(); } catch (InterruptedException ex) { + // Ignore } } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java index 2016174f1d8..bfd8a81a43d 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java @@ -30,7 +30,7 @@ import java.util.regex.Pattern; * * @author Phillip Webb */ -class ChangeableUrls implements Iterable { +final class ChangeableUrls implements Iterable { private static final String[] SKIPPED_PROJECTS = { "spring-boot", "spring-boot-devtools", "spring-boot-autoconfigure", "spring-boot-actuator", diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java index 896f4025101..58d91dcc4eb 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java @@ -394,6 +394,7 @@ public class Restarter { } } catch (final OutOfMemoryError ex) { + // Expected } } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/client/HttpTunnelConnection.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/client/HttpTunnelConnection.java index 07cbd71978f..af7bb908ad6 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/client/HttpTunnelConnection.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/client/HttpTunnelConnection.java @@ -166,6 +166,7 @@ public class HttpTunnelConnection implements TunnelConnection { close(); } catch (IOException ex) { + // Ignore } } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/client/TunnelClient.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/client/TunnelClient.java index d609c27a323..19c8768a5da 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/client/TunnelClient.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/client/TunnelClient.java @@ -95,6 +95,7 @@ public class TunnelClient implements SmartInitializingSingleton { this.serverThread.join(2000); } catch (InterruptedException ex) { + // Ignore } this.serverThread = null; } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServer.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServer.java index f59751340d0..5f5f8a5c82d 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServer.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServer.java @@ -428,6 +428,7 @@ public class HttpTunnelServer { } } catch (InterruptedException ex) { + // Ignore } } } diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java index 965f02b3a41..c22fb7ca2eb 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java @@ -151,6 +151,25 @@ public class LiveReloadServerTests { return socket; } + /** + * Useful main method for manual testing against a real browser. + * @param args main args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + LiveReloadServer server = new LiveReloadServer(); + server.start(); + while (true) { + try { + Thread.sleep(1000); + } + catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + server.triggerReload(); + } + } + private static class Driver extends JettyListenerEventDriver { private int pongCount; @@ -197,25 +216,6 @@ public class LiveReloadServerTests { } - /** - * Useful main method for manual testing against a real browser. - * @param args main args - * @throws IOException - */ - public static void main(String[] args) throws IOException { - LiveReloadServer server = new LiveReloadServer(); - server.start(); - while (true) { - try { - Thread.sleep(1000); - } - catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - } - server.triggerReload(); - } - } - /** * {@link LiveReloadServer} with additional monitoring. */ diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java index a51bfc19110..eaf34f03c07 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestarterTests.java @@ -228,6 +228,7 @@ public class RestarterTests { Thread.sleep(1200); } catch (InterruptedException ex) { + // Ignore } } diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/test/MockClientHttpRequestFactory.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/test/MockClientHttpRequestFactory.java index f8f822fe76f..4a8bffd466a 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/test/MockClientHttpRequestFactory.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/test/MockClientHttpRequestFactory.java @@ -124,6 +124,7 @@ public class MockClientHttpRequestFactory implements ClientHttpRequestFactory { Thread.sleep(this.delay); } catch (InterruptedException ex) { + // Ignore } } } diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/Versions.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/Versions.java index f6f07800ee2..9f123cfeec1 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/Versions.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/Versions.java @@ -27,7 +27,10 @@ import org.xml.sax.InputSource; /** * @author Andy Wilkinson */ -public class Versions { +public final class Versions { + + private Versions() { + } public static String getBootVersion() { return evaluateExpression("/*[local-name()='project']/*[local-name()='version']" diff --git a/spring-boot-integration-tests/spring-boot-security-tests/pom.xml b/spring-boot-integration-tests/spring-boot-security-tests/pom.xml index 4ea1f674b79..6f124268ca2 100644 --- a/spring-boot-integration-tests/spring-boot-security-tests/pom.xml +++ b/spring-boot-integration-tests/spring-boot-security-tests/pom.xml @@ -16,7 +16,7 @@ http://www.spring.io - ${basedir}/.. + ${basedir}/../.. spring-boot-security-tests-web-helloworld diff --git a/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilder.java b/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilder.java index 5fd28e2931f..199e24e0980 100644 --- a/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilder.java +++ b/spring-boot-tools/spring-boot-configuration-metadata/src/main/java/org/springframework/boot/configurationmetadata/ConfigurationMetadataRepositoryJsonBuilder.java @@ -32,7 +32,7 @@ import org.json.JSONException; * @author Stephane Nicoll * @since 1.3.0 */ -public class ConfigurationMetadataRepositoryJsonBuilder { +public final class ConfigurationMetadataRepositoryJsonBuilder { public static final Charset UTF_8 = Charset.forName("UTF-8"); diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/Trees.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/Trees.java index 639ecfc1845..8a525241042 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/Trees.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/Trees.java @@ -27,7 +27,7 @@ import javax.lang.model.element.Element; * @author Phillip Webb * @since 1.2.0 */ -class Trees extends ReflectionWrapper { +final class Trees extends ReflectionWrapper { private Trees(Object instance) { super(instance); diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index 435d71adf7a..2e8fddd96e3 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -68,7 +68,6 @@ import static org.junit.Assert.assertTrue; import static org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.containsGroup; import static org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.containsHint; import static org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.containsProperty; -import static org.springframework.boot.configurationprocessor.MetadataStore.METADATA_PATH; /** * Tests for {@link ConfigurationMetadataAnnotationProcessor}. @@ -491,10 +490,10 @@ public class ConfigurationMetadataAnnotationProcessorTests { public void incrementalBuild() throws Exception { TestProject project = new TestProject(this.temporaryFolder, FooProperties.class, BarProperties.class); - assertFalse(project.getOutputFile(METADATA_PATH).exists()); + assertFalse(project.getOutputFile(MetadataStore.METADATA_PATH).exists()); ConfigurationMetadata metadata = project.fullBuild(); - assertTrue(project.getOutputFile(METADATA_PATH).exists()); + assertTrue(project.getOutputFile(MetadataStore.METADATA_PATH).exists()); assertThat(metadata, containsProperty("foo.counter").fromSource(FooProperties.class)); diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataMatchers.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataMatchers.java index affb83eef13..94cb7103883 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataMatchers.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataMatchers.java @@ -37,7 +37,10 @@ import org.springframework.boot.configurationprocessor.metadata.ItemMetadata.Ite * @author Phillip Webb * @author Stephane Nicoll */ -public class ConfigurationMetadataMatchers { +public final class ConfigurationMetadataMatchers { + + private ConfigurationMetadataMatchers() { + } public static ContainsItemMatcher containsGroup(String name) { return new ContainsItemMatcher(ItemType.GROUP, name); diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadataTests.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadataTests.java index e3830350375..326d88049e9 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadataTests.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadataTests.java @@ -19,7 +19,7 @@ package org.springframework.boot.configurationprocessor.metadata; import org.junit.Test; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertThat; /** * Tests for {@link ConfigurationMetadata}. diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPlugin.groovy b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPlugin.groovy index dee21899d0e..3d4b8241f28 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPlugin.groovy +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPlugin.groovy @@ -24,7 +24,6 @@ import org.springframework.boot.gradle.dependencymanagement.DependencyManagement import org.springframework.boot.gradle.repackage.RepackagePluginFeatures import org.springframework.boot.gradle.run.RunPluginFeatures - /** * Gradle 'Spring Boot' {@link Plugin}. * diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPluginExtension.groovy b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPluginExtension.groovy index a54ecc48ba8..82133babef0 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPluginExtension.groovy +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/SpringBootPluginExtension.groovy @@ -18,10 +18,10 @@ package org.springframework.boot.gradle import java.io.File; import java.util.Map; +import java.util.Set; -import org.springframework.boot.loader.tools.Layout -import org.springframework.boot.loader.tools.Layouts - +import org.springframework.boot.loader.tools.Layout; +import org.springframework.boot.loader.tools.Layouts; /** * Gradle DSL Extension for 'Spring Boot'. Most of the time Spring Boot can guess the diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/dependencymanagement/DependencyManagementPluginFeatures.groovy b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/dependencymanagement/DependencyManagementPluginFeatures.groovy index e8958f4cdbe..11105c7a0a9 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/dependencymanagement/DependencyManagementPluginFeatures.groovy +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/dependencymanagement/DependencyManagementPluginFeatures.groovy @@ -16,12 +16,12 @@ package org.springframework.boot.gradle.dependencymanagement; +import org.gradle.api.Project; +import org.springframework.boot.gradle.PluginFeatures; + import io.spring.gradle.dependencymanagement.DependencyManagementExtension import io.spring.gradle.dependencymanagement.DependencyManagementPlugin -import org.gradle.api.Project -import org.springframework.boot.gradle.PluginFeatures - /** * {@link PluginFeatures} to configure dependency management * diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/run/SourceSets.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/run/SourceSets.java index c96d09b5992..43424fa4c9c 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/run/SourceSets.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/run/SourceSets.java @@ -28,7 +28,10 @@ import org.gradle.api.tasks.SourceSet; * @author Dave Syer * @author Phillip Webb */ -class SourceSets { +final class SourceSets { + + private SourceSets() { + } public static SourceSet findMainSourceSet(Project project) { for (SourceSet sourceSet : getJavaSourceSets(project)) { diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Layouts.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Layouts.java index ed1a5cb1252..243cf742a70 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Layouts.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Layouts.java @@ -31,7 +31,10 @@ import java.util.Set; * @author Dave Syer * @author Andy Wilkinson */ -public class Layouts { +public final class Layouts { + + private Layouts() { + } /** * Return the a layout for the given source file. diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LibraryScope.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LibraryScope.java index f997e6863d1..9b5ac40b362 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LibraryScope.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/LibraryScope.java @@ -25,6 +25,9 @@ package org.springframework.boot.loader.tools; */ public interface LibraryScope { + @Override + String toString(); + /** * The library is used at compile time and runtime. */ diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java index f3b8bcf797a..b14602a90e0 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java @@ -147,6 +147,7 @@ public class RunProcess { reader.close(); } catch (Exception ex) { + // Ignore } } diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java index 6d8ff61cebe..6cb91891822 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/SignalUtils.java @@ -26,10 +26,13 @@ import sun.misc.SignalHandler; * @since 1.1.0 */ @SuppressWarnings("restriction") -public class SignalUtils { +public final class SignalUtils { private static final Signal SIG_INT = new Signal("INT"); + private SignalUtils() { + } + /** * Handle {@literal INT} signals by calling the specified {@link Runnable} * @param runnable the runnable to call on SIGINT. diff --git a/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/sample/ClassWithMainMethod.java b/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/sample/ClassWithMainMethod.java index 09a2b81451c..6fe35ae29b7 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/sample/ClassWithMainMethod.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/sample/ClassWithMainMethod.java @@ -23,7 +23,12 @@ package org.springframework.boot.loader.tools.sample; */ public class ClassWithMainMethod { + public void run() { + System.out.println("Hello World"); + } + public static void main(String[] args) { + new ClassWithMainMethod().run(); } } diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java index 52083c4ff4a..acc4eaef915 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java @@ -138,6 +138,7 @@ public class LaunchedURLClassLoader extends URLClassLoader { } } catch (Exception ex) { + // Ignore and continue } // 2) Try to find locally @@ -147,6 +148,7 @@ public class LaunchedURLClassLoader extends URLClassLoader { return cls; } catch (Exception ex) { + // Ignore and continue } // 3) Use standard loading diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Bytes.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Bytes.java index 1fdb551f928..fb4baffe39b 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Bytes.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Bytes.java @@ -27,10 +27,13 @@ import org.springframework.boot.loader.data.RandomAccessData.ResourceAccess; * * @author Phillip Webb */ -class Bytes { +final class Bytes { private static final byte[] EMPTY_BYTES = new byte[] {}; + private Bytes() { + } + public static byte[] get(RandomAccessData data) throws IOException { InputStream inputStream = data.getInputStream(ResourceAccess.ONCE); try { diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java index fd428551428..3fde7aece99 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java @@ -55,6 +55,7 @@ public class Handler extends URLStreamHandler { .getDeclaredMethod("openConnection", URL.class); } catch (Exception ex) { + // Swallow and ignore } OPEN_CONNECTION_METHOD = method; } diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ByteArrayStartsWith.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ByteArrayStartsWith.java index 593450f71aa..411ec44dc50 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ByteArrayStartsWith.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ByteArrayStartsWith.java @@ -34,16 +34,16 @@ public class ByteArrayStartsWith extends TypeSafeMatcher { @Override public void describeTo(Description description) { - description.appendText("a byte array starting with ").appendValue(bytes); + description.appendText("a byte array starting with ").appendValue(this.bytes); } @Override protected boolean matchesSafely(byte[] item) { - if (item.length < bytes.length) { + if (item.length < this.bytes.length) { return false; } - for (int i = 0; i < bytes.length; i++) { - if (item[i] != bytes[i]) { + for (int i = 0; i < this.bytes.length; i++) { + if (item[i] != this.bytes[i]) { return false; } } diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ExecutableArchiveLauncherTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ExecutableArchiveLauncherTests.java index 3108b35287c..d5fdc6cf3cc 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ExecutableArchiveLauncherTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/ExecutableArchiveLauncherTests.java @@ -90,6 +90,17 @@ public class ExecutableArchiveLauncherTests { assertArrayEquals(urls, ((URLClassLoader) classLoader).getURLs()); } + private void doWithTccl(ClassLoader classLoader, Callable action) throws Exception { + ClassLoader old = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(classLoader); + action.call(); + } + finally { + Thread.currentThread().setContextClassLoader(old); + } + } + private static final class UnitTestExecutableArchiveLauncher extends ExecutableArchiveLauncher { @@ -103,15 +114,4 @@ public class ExecutableArchiveLauncherTests { } } - private void doWithTccl(ClassLoader classLoader, Callable action) throws Exception { - ClassLoader old = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(classLoader); - action.call(); - } - finally { - Thread.currentThread().setContextClassLoader(old); - } - } - } diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java index 4512345e16e..2fe946ddeeb 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java @@ -57,8 +57,8 @@ public class JarFileArchiveTests { private void setup(boolean unpackNested) throws Exception { this.rootJarFile = this.temporaryFolder.newFile(); - this.rootJarFileUrl = rootJarFile.toURI().toString(); - System.out.println(rootJarFileUrl); + this.rootJarFileUrl = this.rootJarFile.toURI().toString(); + System.out.println(this.rootJarFileUrl); TestJarCreator.createTestJar(this.rootJarFile, unpackNested); this.archive = new JarFileArchive(this.rootJarFile); } diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java b/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java index 1f37f240fa6..b45e088d2bc 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java @@ -72,7 +72,7 @@ public class DependencyFilterMojoTests { return a; } - private static class TestableDependencyFilterMojo extends + private static final class TestableDependencyFilterMojo extends AbstractDependencyFilterMojo { private TestableDependencyFilterMojo(List excludes, diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java b/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java index 2eeab97bfba..c0fb36c3d5b 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java @@ -40,10 +40,13 @@ import static org.junit.Assert.assertTrue; * @author Phillip Webb * @author Andy Wilkinson */ -public class Verify { +public final class Verify { public static final String SAMPLE_APP = "org.test.SampleApplication"; + private Verify() { + } + public static void verifyJar(File file) throws Exception { new JarArchiveVerification(file, SAMPLE_APP).verify(); } diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/sample/ClassWithMainMethod.java b/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/sample/ClassWithMainMethod.java index 9b167ee7ee5..74ab0f31131 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/sample/ClassWithMainMethod.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/sample/ClassWithMainMethod.java @@ -23,7 +23,12 @@ package org.springframework.boot.maven.sample; */ public class ClassWithMainMethod { + public void run() { + System.out.println("Hello World"); + } + public static void main(String[] args) { + new ClassWithMainMethod().run(); } } diff --git a/spring-boot/src/main/java/org/springframework/boot/ApplicationHome.java b/spring-boot/src/main/java/org/springframework/boot/ApplicationHome.java index f61b14a108b..ee7cd3e8286 100644 --- a/spring-boot/src/main/java/org/springframework/boot/ApplicationHome.java +++ b/spring-boot/src/main/java/org/springframework/boot/ApplicationHome.java @@ -64,10 +64,11 @@ public class ApplicationHome { if (source != null && source.exists()) { return source.getAbsoluteFile(); } + return null; } catch (Exception ex) { + return null; } - return null; } private File findSource(URL location) throws IOException { diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringBootBanner.java b/spring-boot/src/main/java/org/springframework/boot/SpringBootBanner.java index e7e8a80b0c0..2cf91591f13 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringBootBanner.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringBootBanner.java @@ -18,13 +18,11 @@ package org.springframework.boot; import java.io.PrintStream; +import org.springframework.boot.ansi.AnsiColor; import org.springframework.boot.ansi.AnsiOutput; +import org.springframework.boot.ansi.AnsiStyle; import org.springframework.core.env.Environment; -import static org.springframework.boot.ansi.AnsiColor.DEFAULT; -import static org.springframework.boot.ansi.AnsiColor.GREEN; -import static org.springframework.boot.ansi.AnsiStyle.FAINT; - /** * Default Banner implementation which writes the 'Spring' banner. * @@ -58,8 +56,8 @@ class SpringBootBanner implements Banner { padding += " "; } - printStream.println(AnsiOutput.toString(GREEN, SPRING_BOOT, DEFAULT, padding, - FAINT, version)); + printStream.println(AnsiOutput.toString(AnsiColor.GREEN, SPRING_BOOT, + AnsiColor.DEFAULT, padding, AnsiStyle.FAINT, version)); printStream.println(); } diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringBootVersion.java b/spring-boot/src/main/java/org/springframework/boot/SpringBootVersion.java index 307d3717b4a..095d4ef24e8 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringBootVersion.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringBootVersion.java @@ -28,7 +28,10 @@ package org.springframework.boot; * @author Drummond Dawson * @since 1.3.0 */ -public class SpringBootVersion { +public final class SpringBootVersion { + + private SpringBootVersion() { + } /** * Return the full version string of the present Spring Boot codebase, or {@code null} diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedPropertyResolver.java b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedPropertyResolver.java index 1894f708470..fa0e6bfef05 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedPropertyResolver.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedPropertyResolver.java @@ -20,11 +20,8 @@ import java.util.Map; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.PropertyResolver; -import org.springframework.core.env.PropertySources; import org.springframework.util.Assert; -import static java.lang.String.format; - /** * {@link PropertyResolver} that attempts to resolve values using {@link RelaxedNames}. * @@ -56,7 +53,7 @@ public class RelaxedPropertyResolver implements PropertyResolver { public T getRequiredProperty(String key, Class targetType) throws IllegalStateException { T value = getProperty(key, targetType); - Assert.state(value != null, format("required key [%s] not found", key)); + Assert.state(value != null, String.format("required key [%s] not found", key)); return value; } @@ -137,8 +134,7 @@ public class RelaxedPropertyResolver implements PropertyResolver { * {@link ConfigurableEnvironment}. * @param keyPrefix the key prefix used to filter results * @return a map of all sub properties starting with the specified key prefix. - * @see PropertySourceUtils#getSubProperties(PropertySources, String) - * @see PropertySourceUtils#getSubProperties(PropertySources, String, String) + * @see PropertySourceUtils#getSubProperties */ public Map getSubProperties(String keyPrefix) { Assert.isInstanceOf(ConfigurableEnvironment.class, this.resolver, diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java index 1e8616e9edd..90c78160e68 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java @@ -96,6 +96,7 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer { this.server.stop(); } catch (Exception ex) { + // Ignore } } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java index 7bee8784d83..8d9d4aba870 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java @@ -174,6 +174,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer this.tomcat.stop(); } catch (LifecycleException ex) { + // Ignore } } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java index 89811e47dbb..ac001f6427c 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java @@ -236,7 +236,7 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine /** * An active undertow port. */ - private static class Port { + private final static class Port { private final int number; diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/ColorConverter.java b/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/ColorConverter.java index 573e83a0ae3..7dcab872aec 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/ColorConverter.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/ColorConverter.java @@ -45,8 +45,8 @@ import org.springframework.boot.ansi.AnsiStyle; * @since 1.3.0 */ @Plugin(name = "color", category = PatternConverter.CATEGORY) -@ConverterKeys(value = { "clr", "color" }) -public class ColorConverter extends LogEventPatternConverter { +@ConverterKeys({ "clr", "color" }) +public final class ColorConverter extends LogEventPatternConverter { private static final Map ELEMENTS; static { diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/WhitespaceThrowablePatternConverter.java b/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/WhitespaceThrowablePatternConverter.java index b7e3f2f1684..fd751b3f2c9 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/WhitespaceThrowablePatternConverter.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/WhitespaceThrowablePatternConverter.java @@ -31,7 +31,7 @@ import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter; */ @Plugin(name = "WhitespaceThrowablePatternConverter", category = PatternConverter.CATEGORY) @ConverterKeys({ "wEx", "wThrowable", "wException" }) -public class WhitespaceThrowablePatternConverter extends ThrowablePatternConverter { +public final class WhitespaceThrowablePatternConverter extends ThrowablePatternConverter { private WhitespaceThrowablePatternConverter(String[] options) { super("WhitespaceThrowable", "throwable", options); diff --git a/spring-boot/src/main/java/org/springframework/boot/test/Base64Encoder.java b/spring-boot/src/main/java/org/springframework/boot/test/Base64Encoder.java index 16ed4360082..f9eb63dfb38 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/Base64Encoder.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/Base64Encoder.java @@ -23,7 +23,7 @@ import java.nio.charset.Charset; * * @author Phillip Webb */ -class Base64Encoder { +final class Base64Encoder { private static final Charset UTF_8 = Charset.forName("UTF-8"); @@ -34,6 +34,9 @@ class Base64Encoder { private static final byte EQUALS_SIGN = '='; + private Base64Encoder() { + } + public static String encode(String string) { return encode(string.getBytes(UTF_8)); } diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java index e5cd39e0cc4..8d3251e612e 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java @@ -18,6 +18,7 @@ package org.springframework.boot.test; import java.io.IOException; import java.io.StringReader; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -147,7 +148,7 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { disableJmx(properties); properties.putAll(extractEnvironmentProperties(config .getPropertySourceProperties())); - if (!isIntegrationTest(config.getTestClass())) { + if (!TestAnnotations.isIntegrationTest(config)) { properties.putAll(getDefaultEnvironmentProperties()); } return properties; @@ -252,8 +253,8 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { void configure(MergedContextConfiguration configuration, SpringApplication application, List> initializers) { - WebMergedContextConfiguration webConfiguration = (WebMergedContextConfiguration) configuration; - if (!isIntegrationTest(webConfiguration.getTestClass())) { + if (!TestAnnotations.isIntegrationTest(configuration)) { + WebMergedContextConfiguration webConfiguration = (WebMergedContextConfiguration) configuration; addMockServletContext(initializers, webConfiguration); application.setApplicationContextClass(WEB_CONTEXT_CLASS); } @@ -270,11 +271,6 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { } - private static boolean isIntegrationTest(Class testClass) { - return ((AnnotationUtils.findAnnotation(testClass, IntegrationTest.class) != null) || (AnnotationUtils - .findAnnotation(testClass, WebIntegrationTest.class) != null)); - } - /** * {@link ApplicationContextInitializer} to setup test property source locations. */ @@ -295,4 +291,19 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { } + private static class TestAnnotations { + + public static boolean isIntegrationTest(MergedContextConfiguration configuration) { + return (hasAnnotation(configuration, IntegrationTest.class) || hasAnnotation( + configuration, WebIntegrationTest.class)); + } + + private static boolean hasAnnotation(MergedContextConfiguration configuration, + Class annotation) { + return (AnnotationUtils.findAnnotation(configuration.getTestClass(), + annotation) != null); + } + + } + } diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringBootMockServletContext.java b/spring-boot/src/main/java/org/springframework/boot/test/SpringBootMockServletContext.java index 522f6caf0b4..a1f05232321 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringBootMockServletContext.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/SpringBootMockServletContext.java @@ -103,6 +103,7 @@ public class SpringBootMockServletContext extends MockServletContext { return this.emptyRootFolder.toURI().toURL(); } catch (IOException ex) { + // Ignore } } return resource; diff --git a/spring-boot/src/test/java/org/springframework/boot/ansi/AnsiOutputEnabledValue.java b/spring-boot/src/test/java/org/springframework/boot/ansi/AnsiOutputEnabledValue.java index 22a9bed1ca1..62e21e65fe8 100644 --- a/spring-boot/src/test/java/org/springframework/boot/ansi/AnsiOutputEnabledValue.java +++ b/spring-boot/src/test/java/org/springframework/boot/ansi/AnsiOutputEnabledValue.java @@ -23,7 +23,10 @@ import org.springframework.boot.ansi.AnsiOutput.Enabled; * * @author Phillip Webb */ -public class AnsiOutputEnabledValue { +public final class AnsiOutputEnabledValue { + + private AnsiOutputEnabledValue() { + } public static Enabled get() { return AnsiOutput.getEnabled(); diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java index 4d9bbe431ea..e39b95ba243 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.bind; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.ArrayList; import java.util.Collection; @@ -51,7 +52,6 @@ import org.springframework.validation.DataBinder; import org.springframework.validation.FieldError; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; -import static java.lang.annotation.RetentionPolicy.RUNTIME; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertEquals; @@ -695,7 +695,7 @@ public class RelaxedDataBinderTests { @Documented @Target({ ElementType.FIELD }) - @Retention(RUNTIME) + @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = RequiredKeysValidator.class) public @interface RequiredKeys { diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java index bccafec2d66..76a71f2ea54 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java @@ -27,6 +27,7 @@ import java.net.URISyntaxException; import java.nio.charset.Charset; import java.security.KeyStore; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -69,7 +70,6 @@ import org.springframework.util.SocketUtils; import org.springframework.util.StreamUtils; import org.springframework.util.concurrent.ListenableFuture; -import static java.util.Collections.singletonMap; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -110,6 +110,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { this.container.stop(); } catch (Exception ex) { + // Ignore } } } @@ -584,8 +585,8 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { String testContent = setUpFactoryForCompression(contentSize, mimeTypes, excludedUserAgents); TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory(); - Map contentDecoderMap = singletonMap("gzip", - (InputStreamFactory) inputStreamFactory); + Map contentDecoderMap = Collections.singletonMap( + "gzip", (InputStreamFactory) inputStreamFactory); String response = getResponse( getLocalUrl("/test.txt"), new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create() diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java index 1a7be91bf4f..049d47230db 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java @@ -61,6 +61,7 @@ public class EmbeddedServletContainerMvcIntegrationTests { this.context.close(); } catch (Exception ex) { + // Ignore } } @@ -109,6 +110,13 @@ public class EmbeddedServletContainerMvcIntegrationTests { } } + // Simple main method for testing in a browser + @SuppressWarnings("resource") + public static void main(String[] args) { + new AnnotationConfigEmbeddedWebApplicationContext( + JettyEmbeddedServletContainerFactory.class, Config.class); + } + @Configuration @Import(Config.class) public static class TomcatConfig { @@ -199,13 +207,7 @@ public class EmbeddedServletContainerMvcIntegrationTests { public String sayHello() { return "Hello World"; } - } - // Simple main method for testing in a browser - @SuppressWarnings("resource") - public static void main(String[] args) { - new AnnotationConfigEmbeddedWebApplicationContext( - JettyEmbeddedServletContainerFactory.class, Config.class); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/MockEmbeddedServletContainerFactory.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/MockEmbeddedServletContainerFactory.java index 3309e7a1c14..ade0571ee9b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/MockEmbeddedServletContainerFactory.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/MockEmbeddedServletContainerFactory.java @@ -166,20 +166,6 @@ public class MockEmbeddedServletContainerFactory extends return (Enumeration) EmptyEnumeration.EMPTY_ENUMERATION; } - private static class EmptyEnumeration implements Enumeration { - static final EmptyEnumeration EMPTY_ENUMERATION = new EmptyEnumeration(); - - @Override - public boolean hasMoreElements() { - return false; - } - - @Override - public E nextElement() { - throw new NoSuchElementException(); - } - } - @Override public void start() throws EmbeddedServletContainerException { } @@ -210,6 +196,21 @@ public class MockEmbeddedServletContainerFactory extends public int getPort() { return this.port; } + + private static class EmptyEnumeration implements Enumeration { + static final EmptyEnumeration EMPTY_ENUMERATION = new EmptyEnumeration(); + + @Override + public boolean hasMoreElements() { + return false; + } + + @Override + public E nextElement() { + throw new NoSuchElementException(); + } + } + } public static class RegisteredServlet { diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java index 6bf67189c22..a21ee1ba94f 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java @@ -276,7 +276,7 @@ public class TomcatEmbeddedServletContainerFactoryTests extends fail(); } catch (IllegalStateException ex) { - + // Ignore } } @@ -306,7 +306,7 @@ public class TomcatEmbeddedServletContainerFactoryTests extends fail(); } catch (IllegalStateException ex) { - + // Ignore } } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java index a7e2f7ab790..b86e5daf440 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java @@ -379,6 +379,17 @@ public class EnableConfigurationPropertiesTests { assertEquals("foo", this.context.getBean(External.class).getName()); } + /** + * Strict tests need a known set of properties so we remove system items which may be + * environment specific. + */ + private void removeSystemProperties() { + MutablePropertySources sources = this.context.getEnvironment() + .getPropertySources(); + sources.remove("systemProperties"); + sources.remove("systemEnvironment"); + } + @Configuration @EnableConfigurationProperties public static class TestConfigurationWithAnnotatedBean { @@ -391,17 +402,6 @@ public class EnableConfigurationPropertiesTests { } - /** - * Strict tests need a known set of properties so we remove system items which may be - * environment specific. - */ - private void removeSystemProperties() { - MutablePropertySources sources = this.context.getEnvironment() - .getPropertySources(); - sources.remove("systemProperties"); - sources.remove("systemEnvironment"); - } - @Configuration @EnableConfigurationProperties(TestProperties.class) protected static class TestConfiguration { diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/WhitespaceThrowablePatternConverterTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/WhitespaceThrowablePatternConverterTests.java index dd4ba2a1e18..848737a8fad 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/WhitespaceThrowablePatternConverterTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/WhitespaceThrowablePatternConverterTests.java @@ -4,10 +4,10 @@ import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.impl.Log4jLogEvent; import org.junit.Test; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.startsWith; +import static org.junit.Assert.assertThat; /** * Tests for {@link WhitespaceThrowablePatternConverter}.