2020import static org .junit .jupiter .api .Assertions .assertEquals ;
2121import static org .junit .jupiter .api .Assertions .assertThrows ;
2222import static org .junit .jupiter .api .Assertions .assertTrue ;
23- import static org .junit .jupiter .api .Assertions .fail ;
2423
2524import java .io .ByteArrayInputStream ;
2625import java .io .IOException ;
@@ -262,12 +261,8 @@ void testGetAsIntMessage() {
262261 assertEquals (1 , atomicInt .get ());
263262 // exception
264263 final IOException expected = new IOException (CAUSE_MESSAGE );
265- try {
266- Uncheck .getAsInt (() -> new BrokenInputStream (expected ).read (), () -> CUSTOM_MESSAGE );
267- fail ();
268- } catch (final UncheckedIOException e ) {
269- assertUncheckedIOException (expected , e );
270- }
264+ assertUncheckedIOException (expected ,
265+ assertThrows (UncheckedIOException .class , () -> Uncheck .getAsInt (() -> new BrokenInputStream (expected ).read (), () -> CUSTOM_MESSAGE )));
271266 }
272267
273268 @ Test
@@ -291,12 +286,8 @@ void testGetAsLongMessage() {
291286 assertEquals (1L , atomicLong .get ());
292287 // exception
293288 final IOException expected = new IOException (CAUSE_MESSAGE );
294- try {
295- Uncheck .getAsLong (() -> new BrokenInputStream (expected ).read (), () -> CUSTOM_MESSAGE );
296- fail ();
297- } catch (final UncheckedIOException e ) {
298- assertUncheckedIOException (expected , e );
299- }
289+ assertUncheckedIOException (expected ,
290+ assertThrows (UncheckedIOException .class , () -> Uncheck .getAsLong (() -> new BrokenInputStream (expected ).read (), () -> CUSTOM_MESSAGE )));
300291 }
301292
302293 /**
@@ -308,12 +299,8 @@ void testGetMessage() {
308299 assertEquals ('a' , Uncheck .get (() -> newInputStream ().read ()).intValue (), () -> CUSTOM_MESSAGE );
309300 // Exception
310301 final IOException expected = new IOException (CAUSE_MESSAGE );
311- try {
312- Uncheck .get (() -> new BrokenInputStream (expected ).read (), () -> CUSTOM_MESSAGE );
313- fail ();
314- } catch (final UncheckedIOException e ) {
315- assertUncheckedIOException (expected , e );
316- }
302+ assertUncheckedIOException (expected ,
303+ assertThrows (UncheckedIOException .class , () -> Uncheck .get (() -> new BrokenInputStream (expected ).read (), () -> CUSTOM_MESSAGE )));
317304 }
318305
319306 /**
@@ -334,7 +321,7 @@ void testRun() {
334321 }
335322
336323 /**
337- * Tests {@link Uncheck#run(IORunnable, Supplier)) }.
324+ * Tests {@link Uncheck#run(IORunnable, Supplier)}.
338325 *
339326 * @throws IOException Thrown on a test failure.
340327 */
@@ -346,12 +333,8 @@ void testRunMessage() throws IOException {
346333 assertEquals ('b' , Uncheck .get (stream ::read ).intValue ());
347334 final IOException expected = new IOException (CAUSE_MESSAGE );
348335 // Exception
349- try {
350- Uncheck .run (() -> new BrokenInputStream (expected ).read (), () -> CUSTOM_MESSAGE );
351- fail ();
352- } catch (final UncheckedIOException e ) {
353- assertUncheckedIOException (expected , e );
354- }
336+ assertUncheckedIOException (expected ,
337+ assertThrows (UncheckedIOException .class , () -> Uncheck .run (() -> new BrokenInputStream (expected ).read (), () -> CUSTOM_MESSAGE )));
355338 }
356339
357340 @ Test
0 commit comments