From fedd7b95060653a0d7555ec8357e5e3705ff0089 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 6 Mar 2017 12:00:46 -0800 Subject: [PATCH] Polish --- .../cloudfoundry/CloudFoundryHealthMvcEndpoint.java | 3 ++- .../actuate/endpoint/mvc/HealthMvcEndpoint.java | 7 ++++--- .../mvc/MvcEndpointSecurityInterceptor.java | 2 +- .../CloudFoundryHealthMvcEndpointTests.java | 2 +- .../endpoint/mvc/HealthMvcEndpointTests.java | 3 ++- ...ngSecurityHealthMvcEndpointIntegrationTests.java | 12 +++++++++--- .../boot/autoconfigure/mongo/MongoProperties.java | 13 ++++++------- .../autoconfigure/mongo/MongoPropertiesTests.java | 2 +- .../JettyEmbeddedServletContainerFactoryTests.java | 2 +- 9 files changed, 27 insertions(+), 19 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryHealthMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryHealthMvcEndpoint.java index f6f1791074..49c4e10974 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryHealthMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cloudfoundry/CloudFoundryHealthMvcEndpoint.java @@ -38,7 +38,8 @@ class CloudFoundryHealthMvcEndpoint extends HealthMvcEndpoint { } @Override - protected boolean exposeHealthDetails(HttpServletRequest request, Principal principal) { + protected boolean exposeHealthDetails(HttpServletRequest request, + Principal principal) { return true; } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java index 8299a33c9c..9ebaf80d24 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java @@ -183,7 +183,8 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter= getDelegate().getTimeToLive(); } - protected boolean exposeHealthDetails(HttpServletRequest request, Principal principal) { + protected boolean exposeHealthDetails(HttpServletRequest request, + Principal principal) { if (!this.secure) { return true; } @@ -192,7 +193,7 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter authorities = Collections.singleton(new SimpleGrantedAuthority("HERO")); + Set authorities = Collections + .singleton(new SimpleGrantedAuthority("HERO")); doReturn(authorities).when(principal).getAuthorities(); given(this.endpoint.invoke()) .willReturn(new Health.Builder().up().withDetail("foo", "bar").build()); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java index d56a754cb4..1885a14839 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NoSpringSecurityHealthMvcEndpointIntegrationTests.java @@ -68,13 +68,15 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests { } @Test - public void healthWhenRightRoleNotPresentShouldExposeHealthDetails() throws Exception { + public void healthWhenRightRoleNotPresentShouldExposeHealthDetails() + throws Exception { this.context = new AnnotationConfigWebApplicationContext(); this.context.setServletContext(new MockServletContext()); this.context.register(TestConfiguration.class); this.context.refresh(); MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build(); - mockMvc.perform(get("/health").with(getRequestPostProcessor())).andExpect(status().isOk()) + mockMvc.perform(get("/health").with(getRequestPostProcessor())) + .andExpect(status().isOk()) .andExpect(content().string(containsString("\"status\":\"UP\""))); } @@ -94,12 +96,15 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests { private RequestPostProcessor getRequestPostProcessor() { return new RequestPostProcessor() { + @Override - public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) { + public MockHttpServletRequest postProcessRequest( + MockHttpServletRequest request) { Principal principal = mock(Principal.class); request.setUserPrincipal(principal); return request; } + }; } @@ -119,6 +124,7 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests { public Health health() { return Health.up().withDetail("hello", "world").build(); } + }; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java index 43e2444771..1d57a632c5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -227,8 +227,7 @@ public class MongoProperties { options = MongoClientOptions.builder().build(); } String host = this.host == null ? "localhost" : this.host; - return new MongoClient( - Collections.singletonList(new ServerAddress(host, port)), + return new MongoClient(Collections.singletonList(new ServerAddress(host, port)), Collections.emptyList(), options); } @@ -245,14 +244,14 @@ public class MongoProperties { if (hasCustomCredentials()) { String database = this.authenticationDatabase == null ? getMongoClientDatabase() : this.authenticationDatabase; - credentials.add(MongoCredential.createCredential(this.username, - database, this.password)); + credentials.add(MongoCredential.createCredential(this.username, database, + this.password)); } String host = this.host == null ? "localhost" : this.host; int port = this.port != null ? this.port : DEFAULT_PORT; return new MongoClient( - Collections.singletonList(new ServerAddress(host, port)), - credentials, options); + Collections.singletonList(new ServerAddress(host, port)), credentials, + options); } // The options and credentials are in the URI return new MongoClient(new MongoClientURI(determineUri(), builder(options))); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java index 5f6d44f312..5304a5f528 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactoryTests.java index 28c23cfd92..bdc527eb9e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.