Skip to content

Commit dc9c674

Browse files
committed
Use try-with-resources, avoids compiler warnings.
1 parent 6926849 commit dc9c674

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/test/java/org/apache/commons/io/IOUtilsTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,13 @@ public void write(final int b) throws IOException {
299299
}
300300

301301
@Test
302-
public void testAsWriterAppendable() {
302+
public void testAsWriterAppendable() throws IOException {
303303
final Appendable a = new StringBuffer();
304-
final Writer w = IOUtils.writer(a);
305-
assertNotSame(w, a);
306-
assertEquals(AppendableWriter.class, w.getClass());
307-
assertSame(w, IOUtils.writer(w));
304+
try (final Writer w = IOUtils.writer(a)) {
305+
assertNotSame(w, a);
306+
assertEquals(AppendableWriter.class, w.getClass());
307+
assertSame(w, IOUtils.writer(w));
308+
}
308309
}
309310

310311
@Test
@@ -313,12 +314,13 @@ public void testAsWriterNull() {
313314
}
314315

315316
@Test
316-
public void testAsWriterStringBuilder() {
317+
public void testAsWriterStringBuilder() throws IOException {
317318
final Appendable a = new StringBuilder();
318-
final Writer w = IOUtils.writer(a);
319-
assertNotSame(w, a);
320-
assertEquals(StringBuilderWriter.class, w.getClass());
321-
assertSame(w, IOUtils.writer(w));
319+
try (final Writer w = IOUtils.writer(a)) {
320+
assertNotSame(w, a);
321+
assertEquals(StringBuilderWriter.class, w.getClass());
322+
assertSame(w, IOUtils.writer(w));
323+
}
322324
}
323325

324326
/**

0 commit comments

Comments
 (0)