@@ -68,47 +68,39 @@ public void testLoadsFromFile()
68
68
throws IOException
69
69
{
70
70
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 ))) {
73
72
out .print ("test: foo" );
74
- }
75
- catch (Exception e ) {
76
- out .close ();
77
- }
78
73
79
- System .setProperty ("config" , file .getAbsolutePath ());
74
+ System .setProperty ("config" , file .getAbsolutePath ());
80
75
81
- Map <String , String > properties = loadProperties ();
76
+ Map <String , String > properties = loadProperties ();
82
77
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 ());
85
80
86
- System .getProperties ().remove ("config" );
81
+ System .getProperties ().remove ("config" );
82
+ }
87
83
}
88
84
89
85
@ Test
90
86
public void testSystemOverridesFile ()
91
87
throws IOException
92
88
{
93
89
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 ))) {
96
91
out .println ("key1: original" );
97
92
out .println ("key2: original" );
98
- }
99
- catch (Exception e ) {
100
- out .close ();
101
- }
102
93
103
- System .setProperty ("config" , file .getAbsolutePath ());
104
- System .setProperty ("key1" , "overridden" );
94
+ System .setProperty ("config" , file .getAbsolutePath ());
95
+ System .setProperty ("key1" , "overridden" );
105
96
106
- Map <String , String > properties = loadProperties ();
97
+ Map <String , String > properties = loadProperties ();
107
98
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" );
111
102
112
- System .getProperties ().remove ("config" );
103
+ System .getProperties ().remove ("config" );
104
+ }
113
105
}
114
106
}
0 commit comments