1717package org .apache .commons .io .input ;
1818
1919import static org .junit .jupiter .api .Assertions .assertEquals ;
20- import static org .junit .jupiter .api .Assertions .fail ;
20+ import static org .junit .jupiter .api .Assertions .assertThrows ;
2121
2222import java .io .IOException ;
2323import java .io .InputStream ;
2828/**
2929 * JUnit Test Case for {@link BrokenInputStream}.
3030 */
31- @ SuppressWarnings ("ResultOfMethodCallIgnored" )
3231public class BrokenInputStreamTest {
3332
3433 private IOException exception ;
@@ -42,67 +41,30 @@ public void setUp() {
4241 }
4342
4443 @ Test
45- public void testRead () {
46- try {
47- stream .read ();
48- fail ("Expected exception not thrown." );
49- } catch (final IOException e ) {
50- assertEquals (exception , e );
51- }
52-
53- try {
54- stream .read (new byte [1 ]);
55- fail ("Expected exception not thrown." );
56- } catch (final IOException e ) {
57- assertEquals (exception , e );
58- }
59-
60- try {
61- stream .read (new byte [1 ], 0 , 1 );
62- fail ("Expected exception not thrown." );
63- } catch (final IOException e ) {
64- assertEquals (exception , e );
65- }
44+ public void testAvailable () {
45+ assertEquals (exception , assertThrows (IOException .class , () -> stream .available ()));
6646 }
6747
6848 @ Test
69- public void testAvailable () {
70- try {
71- stream .available ();
72- fail ("Expected exception not thrown." );
73- } catch (final IOException e ) {
74- assertEquals (exception , e );
75- }
49+ public void testClose () {
50+ assertEquals (exception , assertThrows (IOException .class , () -> stream .close ()));
7651 }
7752
7853 @ Test
79- public void testSkip () {
80- try {
81- stream .skip (1 );
82- fail ("Expected exception not thrown." );
83- } catch (final IOException e ) {
84- assertEquals (exception , e );
85- }
54+ public void testRead () {
55+ assertEquals (exception , assertThrows (IOException .class , () -> stream .read ()));
56+ assertEquals (exception , assertThrows (IOException .class , () -> stream .read (new byte [1 ])));
57+ assertEquals (exception , assertThrows (IOException .class , () -> stream .read (new byte [1 ], 0 , 1 )));
8658 }
8759
8860 @ Test
8961 public void testReset () {
90- try {
91- stream .reset ();
92- fail ("Expected exception not thrown." );
93- } catch (final IOException e ) {
94- assertEquals (exception , e );
95- }
62+ assertEquals (exception , assertThrows (IOException .class , () -> stream .reset ()));
9663 }
9764
9865 @ Test
99- public void testClose () {
100- try {
101- stream .close ();
102- fail ("Expected exception not thrown." );
103- } catch (final IOException e ) {
104- assertEquals (exception , e );
105- }
66+ public void testSkip () {
67+ assertEquals (exception , assertThrows (IOException .class , () -> stream .skip (1 )));
10668 }
10769
10870}
0 commit comments