Merge pull request #15427 from igor-suhorukov

* pr/15427:
  Simplify code by using try-with-resources statement
pull/15438/head
Stephane Nicoll 6 years ago
commit 83de570f33

@ -86,9 +86,8 @@ public class CloudFoundryWebEndpointDiscovererTests {
private void load(Function<EndpointId, Long> timeToLive, private void load(Function<EndpointId, Long> timeToLive,
PathMapper endpointPathMapper, Class<?> configuration, PathMapper endpointPathMapper, Class<?> configuration,
Consumer<CloudFoundryWebEndpointDiscoverer> consumer) { Consumer<CloudFoundryWebEndpointDiscoverer> consumer) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
configuration); configuration)) {
try {
ConversionServiceParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper( ConversionServiceParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper(
DefaultConversionService.getSharedInstance()); DefaultConversionService.getSharedInstance());
EndpointMediaTypes mediaTypes = new EndpointMediaTypes( EndpointMediaTypes mediaTypes = new EndpointMediaTypes(
@ -101,9 +100,6 @@ public class CloudFoundryWebEndpointDiscovererTests {
Collections.emptyList()); Collections.emptyList());
consumer.accept(discoverer); consumer.accept(discoverer);
} }
finally {
context.close();
}
} }
@Configuration @Configuration

@ -163,15 +163,11 @@ public class CloudFoundryMvcWebEndpointIntegrationTests {
private void load(Class<?> configuration, Consumer<WebTestClient> clientConsumer) { private void load(Class<?> configuration, Consumer<WebTestClient> clientConsumer) {
BiConsumer<ApplicationContext, WebTestClient> consumer = (context, BiConsumer<ApplicationContext, WebTestClient> consumer = (context,
client) -> clientConsumer.accept(client); client) -> clientConsumer.accept(client);
AnnotationConfigServletWebServerApplicationContext context = createApplicationContext( try (AnnotationConfigServletWebServerApplicationContext context = createApplicationContext(
configuration, CloudFoundryMvcConfiguration.class); configuration, CloudFoundryMvcConfiguration.class)) {
try {
consumer.accept(context, WebTestClient.bindToServer() consumer.accept(context, WebTestClient.bindToServer()
.baseUrl("http://localhost:" + getPort(context)).build()); .baseUrl("http://localhost:" + getPort(context)).build());
} }
finally {
context.close();
}
} }
private String mockAccessToken() { private String mockAccessToken() {

@ -252,9 +252,8 @@ public class WebEndpointDiscovererTests {
private void load(Function<EndpointId, Long> timeToLive, private void load(Function<EndpointId, Long> timeToLive,
PathMapper endpointPathMapper, Class<?> configuration, PathMapper endpointPathMapper, Class<?> configuration,
Consumer<WebEndpointDiscoverer> consumer) { Consumer<WebEndpointDiscoverer> consumer) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
configuration); configuration)) {
try {
ConversionServiceParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper( ConversionServiceParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper(
DefaultConversionService.getSharedInstance()); DefaultConversionService.getSharedInstance());
EndpointMediaTypes mediaTypes = new EndpointMediaTypes( EndpointMediaTypes mediaTypes = new EndpointMediaTypes(
@ -267,9 +266,6 @@ public class WebEndpointDiscovererTests {
Collections.emptyList()); Collections.emptyList());
consumer.accept(discoverer); consumer.accept(discoverer);
} }
finally {
context.close();
}
} }
private Map<EndpointId, ExposableWebEndpoint> mapEndpoints( private Map<EndpointId, ExposableWebEndpoint> mapEndpoints(

Loading…
Cancel
Save