File tree Expand file tree Collapse file tree
src/test/java/org/apache/commons/io Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919import static org .junit .jupiter .api .Assertions .assertEquals ;
2020import static org .junit .jupiter .api .Assertions .assertFalse ;
2121import static org .junit .jupiter .api .Assertions .assertNotNull ;
22+ import static org .junit .jupiter .api .Assertions .assertThrows ;
2223import static org .junit .jupiter .api .Assertions .assertTrue ;
2324import 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
You can’t perform that action at this time.
0 commit comments