Polish "Use try-with-resources to close resources automatically"
- Apply code formatting - Use try-with-resources in many other places that were missed in the pull request Closes gh-8045
This commit is contained in:
@@ -60,16 +60,12 @@ public class TestDatabaseAutoConfigurationTests {
|
||||
DataSource datasource = this.context.getBean(DataSource.class);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
|
||||
jdbcTemplate.execute("create table example (id int, name varchar);");
|
||||
ConfigurableApplicationContext anotherContext = doLoad(
|
||||
ExistingDataSourceConfiguration.class);
|
||||
try {
|
||||
try (ConfigurableApplicationContext anotherContext = doLoad(
|
||||
ExistingDataSourceConfiguration.class)) {
|
||||
DataSource anotherDatasource = anotherContext.getBean(DataSource.class);
|
||||
JdbcTemplate anotherJdbcTemplate = new JdbcTemplate(anotherDatasource);
|
||||
anotherJdbcTemplate.execute("create table example (id int, name varchar);");
|
||||
}
|
||||
finally {
|
||||
anotherContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void load(Class<?> config, String... environment) {
|
||||
|
||||
@@ -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.
|
||||
@@ -42,25 +42,13 @@ class ContentContainingCondition extends Condition<File> {
|
||||
|
||||
@Override
|
||||
public boolean matches(File value) {
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = new FileReader(value);
|
||||
try (Reader reader = new FileReader(value)) {
|
||||
String content = FileCopyUtils.copyToString(reader);
|
||||
return content.contains(this.toContain);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user