Skip to content

Commit 4cede9a

Browse files
committed
Try with resources
1 parent 61031aa commit 4cede9a

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
2121
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertThrows;
2223
import static org.junit.jupiter.api.Assertions.assertTrue;
2324
import static org.junit.jupiter.api.Assertions.fail;
2425

@@ -110,12 +111,11 @@ private List<String> createStringLines(final int lineCount) {
110111

111112
@Test
112113
public void testConstructor() throws Exception {
113-
try {
114-
new LineIterator(null);
115-
fail();
116-
} catch (final IllegalArgumentException ex) {
117-
// expected
118-
}
114+
assertThrows(IllegalArgumentException.class, () -> {
115+
try (
116+
LineIterator li = new LineIterator(null);
117+
) { }
118+
});
119119
}
120120

121121
@Test
@@ -243,12 +243,13 @@ public String readLine() throws IOException {
243243
throw new IOException("hasNext");
244244
}
245245
};
246-
try {
247-
new LineIterator(reader).hasNext();
248-
fail("Expected IllegalStateException");
249-
} catch (final IllegalStateException e) {
250-
// expected
251-
}
246+
try (
247+
LineIterator li = new LineIterator(reader);
248+
) {
249+
assertThrows(IllegalStateException.class, () -> {
250+
li.hasNext();
251+
});
252+
}
252253
}
253254

254255
@Test

0 commit comments

Comments
 (0)