1717package org .apache .commons .io .output ;
1818
1919import static org .apache .commons .io .test .TestUtils .checkFile ;
20- import static org .junit .jupiter .api .Assertions .assertFalse ;
2120import static org .junit .jupiter .api .Assertions .assertEquals ;
21+ import static org .junit .jupiter .api .Assertions .assertFalse ;
2222import static org .junit .jupiter .api .Assertions .assertThrows ;
2323import static org .junit .jupiter .api .Assertions .assertTrue ;
2424import static org .junit .jupiter .api .Assertions .fail ;
2929import java .io .OutputStreamWriter ;
3030import java .io .Writer ;
3131import java .nio .charset .Charset ;
32- import java .nio .charset .CharsetEncoder ;
3332import java .nio .file .Files ;
3433
3534import org .junit .jupiter .api .BeforeEach ;
@@ -108,13 +107,16 @@ public void constructor_fileName_nullFile() {
108107
109108 @ Test
110109 public void sameEncoding_Charset_constructor () throws Exception {
111- successfulRun (new FileWriterWithEncoding (file2 , Charset .defaultCharset ()));
110+ try (final FileWriterWithEncoding writer = new FileWriterWithEncoding (file2 , Charset .defaultCharset ())) {
111+ successfulRun (writer );
112+ }
112113 }
113114
114115 @ Test
115116 public void sameEncoding_CharsetEncoder_constructor () throws Exception {
116- final CharsetEncoder enc = Charset .defaultCharset ().newEncoder ();
117- successfulRun (new FileWriterWithEncoding (file2 , enc ));
117+ try (final FileWriterWithEncoding writer = new FileWriterWithEncoding (file2 , Charset .defaultCharset ().newEncoder ())) {
118+ successfulRun (writer );
119+ }
118120 }
119121
120122 @ Test
@@ -129,23 +131,30 @@ public void sameEncoding_null_Charset_constructor() throws Exception {
129131
130132 @ Test
131133 public void sameEncoding_string_Charset_constructor () throws Exception {
132- successfulRun (new FileWriterWithEncoding (file2 .getPath (), Charset .defaultCharset ()));
134+ try (final FileWriterWithEncoding writer = new FileWriterWithEncoding (file2 .getPath (), Charset .defaultCharset ())) {
135+ successfulRun (writer );
136+ }
133137 }
134138
135139 @ Test
136140 public void sameEncoding_string_CharsetEncoder_constructor () throws Exception {
137- final CharsetEncoder enc = Charset .defaultCharset ().newEncoder ();
138- successfulRun (new FileWriterWithEncoding (file2 .getPath (), enc ));
141+ try (final FileWriterWithEncoding writer = new FileWriterWithEncoding (file2 .getPath (), Charset .defaultCharset ().newEncoder ())) {
142+ successfulRun (writer );
143+ }
139144 }
140145
141146 @ Test
142147 public void sameEncoding_string_constructor () throws Exception {
143- successfulRun (new FileWriterWithEncoding (file2 , defaultEncoding ));
148+ try (final FileWriterWithEncoding writer = new FileWriterWithEncoding (file2 , defaultEncoding )) {
149+ successfulRun (writer );
150+ }
144151 }
145152
146153 @ Test
147154 public void sameEncoding_string_string_constructor () throws Exception {
148- successfulRun (new FileWriterWithEncoding (file2 .getPath (), defaultEncoding ));
155+ try (final FileWriterWithEncoding writer = new FileWriterWithEncoding (file2 .getPath (), defaultEncoding )) {
156+ successfulRun (writer );
157+ }
149158 }
150159
151160 @ BeforeEach
0 commit comments