Skip to content

Commit 1016fbd

Browse files
dnskrtdcmeehan
authored andcommitted
Close PrintStream properly in TestConfigurationLoader tests
1 parent 961ff31 commit 1016fbd

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

configuration/src/test/java/com/facebook/airlift/configuration/TestConfigurationLoader.java

+16-24
Original file line numberDiff line numberDiff line change
@@ -68,47 +68,39 @@ public void testLoadsFromFile()
6868
throws IOException
6969
{
7070
final File file = File.createTempFile("config", ".properties", tempDir);
71-
PrintStream out = new PrintStream(new FileOutputStream(file));
72-
try {
71+
try (PrintStream out = new PrintStream(new FileOutputStream(file))) {
7372
out.print("test: foo");
74-
}
75-
catch (Exception e) {
76-
out.close();
77-
}
7873

79-
System.setProperty("config", file.getAbsolutePath());
74+
System.setProperty("config", file.getAbsolutePath());
8075

81-
Map<String, String> properties = loadProperties();
76+
Map<String, String> properties = loadProperties();
8277

83-
assertEquals(properties.get("test"), "foo");
84-
assertEquals(properties.get("config"), file.getAbsolutePath());
78+
assertEquals(properties.get("test"), "foo");
79+
assertEquals(properties.get("config"), file.getAbsolutePath());
8580

86-
System.getProperties().remove("config");
81+
System.getProperties().remove("config");
82+
}
8783
}
8884

8985
@Test
9086
public void testSystemOverridesFile()
9187
throws IOException
9288
{
9389
final File file = File.createTempFile("config", ".properties", tempDir);
94-
PrintStream out = new PrintStream(new FileOutputStream(file));
95-
try {
90+
try (PrintStream out = new PrintStream(new FileOutputStream(file))) {
9691
out.println("key1: original");
9792
out.println("key2: original");
98-
}
99-
catch (Exception e) {
100-
out.close();
101-
}
10293

103-
System.setProperty("config", file.getAbsolutePath());
104-
System.setProperty("key1", "overridden");
94+
System.setProperty("config", file.getAbsolutePath());
95+
System.setProperty("key1", "overridden");
10596

106-
Map<String, String> properties = loadProperties();
97+
Map<String, String> properties = loadProperties();
10798

108-
assertEquals(properties.get("config"), file.getAbsolutePath());
109-
assertEquals(properties.get("key1"), "overridden");
110-
assertEquals(properties.get("key2"), "original");
99+
assertEquals(properties.get("config"), file.getAbsolutePath());
100+
assertEquals(properties.get("key1"), "overridden");
101+
assertEquals(properties.get("key2"), "original");
111102

112-
System.getProperties().remove("config");
103+
System.getProperties().remove("config");
104+
}
113105
}
114106
}

0 commit comments

Comments
 (0)