From 2b1653d009478d26b26f3e02aea35ace5010fdf2 Mon Sep 17 00:00:00 2001 From: igor-suhorukov Date: Sun, 9 Dec 2018 15:28:33 +0300 Subject: [PATCH] Simplify code by using try-with-resources statement Closes gh-15427 --- .../CloudFoundryWebEndpointDiscovererTests.java | 8 ++------ .../CloudFoundryMvcWebEndpointIntegrationTests.java | 8 ++------ .../web/annotation/WebEndpointDiscovererTests.java | 8 ++------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscovererTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscovererTests.java index 3b43c9c466..8a3f81c8f9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscovererTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscovererTests.java @@ -86,9 +86,8 @@ public class CloudFoundryWebEndpointDiscovererTests { private void load(Function timeToLive, PathMapper endpointPathMapper, Class configuration, Consumer consumer) { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( - configuration); - try { + try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( + configuration)) { ConversionServiceParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper( DefaultConversionService.getSharedInstance()); EndpointMediaTypes mediaTypes = new EndpointMediaTypes( @@ -101,9 +100,6 @@ public class CloudFoundryWebEndpointDiscovererTests { Collections.emptyList()); consumer.accept(discoverer); } - finally { - context.close(); - } } @Configuration diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java index d4906b9dd3..7958981b86 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryMvcWebEndpointIntegrationTests.java @@ -163,15 +163,11 @@ public class CloudFoundryMvcWebEndpointIntegrationTests { private void load(Class configuration, Consumer clientConsumer) { BiConsumer consumer = (context, client) -> clientConsumer.accept(client); - AnnotationConfigServletWebServerApplicationContext context = createApplicationContext( - configuration, CloudFoundryMvcConfiguration.class); - try { + try (AnnotationConfigServletWebServerApplicationContext context = createApplicationContext( + configuration, CloudFoundryMvcConfiguration.class)) { consumer.accept(context, WebTestClient.bindToServer() .baseUrl("http://localhost:" + getPort(context)).build()); } - finally { - context.close(); - } } private String mockAccessToken() { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscovererTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscovererTests.java index 8ca57e42c8..300f7a4f1c 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscovererTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscovererTests.java @@ -252,9 +252,8 @@ public class WebEndpointDiscovererTests { private void load(Function timeToLive, PathMapper endpointPathMapper, Class configuration, Consumer consumer) { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( - configuration); - try { + try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( + configuration)) { ConversionServiceParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper( DefaultConversionService.getSharedInstance()); EndpointMediaTypes mediaTypes = new EndpointMediaTypes( @@ -267,9 +266,6 @@ public class WebEndpointDiscovererTests { Collections.emptyList()); consumer.accept(discoverer); } - finally { - context.close(); - } } private Map mapEndpoints(