Simplify code by using try-with-resources statement

Closes gh-15427
This commit is contained in:
igor-suhorukov 2018-12-09 15:28:33 +03:00 committed by Stephane Nicoll
parent 075a2b10bb
commit 2b1653d009
3 changed files with 6 additions and 18 deletions

View File

@ -86,9 +86,8 @@ public class CloudFoundryWebEndpointDiscovererTests {
private void load(Function<EndpointId, Long> timeToLive,
PathMapper endpointPathMapper, Class<?> configuration,
Consumer<CloudFoundryWebEndpointDiscoverer> 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

View File

@ -163,15 +163,11 @@ public class CloudFoundryMvcWebEndpointIntegrationTests {
private void load(Class<?> configuration, Consumer<WebTestClient> clientConsumer) {
BiConsumer<ApplicationContext, WebTestClient> 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() {

View File

@ -252,9 +252,8 @@ public class WebEndpointDiscovererTests {
private void load(Function<EndpointId, Long> timeToLive,
PathMapper endpointPathMapper, Class<?> configuration,
Consumer<WebEndpointDiscoverer> 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<EndpointId, ExposableWebEndpoint> mapEndpoints(