@@ -71,9 +71,11 @@ void testClosed() {
71
71
@ DisplayName ("interrupt" )
72
72
void testInterrupt () throws InterruptedException {
73
73
TextPipe pipe = new TextPipe ();
74
+ @ SuppressWarnings ("resource" )
75
+ Reader input = pipe .input ();
74
76
AtomicReference <InterruptedIOException > exception = new AtomicReference <>();
75
77
Thread thread = new Thread (() -> {
76
- exception .set (assertThrows (InterruptedIOException .class , () -> pipe . input () .read ()));
78
+ exception .set (assertThrows (InterruptedIOException .class , () -> input .read ()));
77
79
});
78
80
thread .start ();
79
81
thread .interrupt ();
@@ -301,7 +303,9 @@ void testWriteInt() throws IOException, InterruptedException {
301
303
readLatch .await ();
302
304
assertEquals (SOURCE , result .get ());
303
305
304
- assertClosed (() -> pipe .output ().write ('*' ));
306
+ @ SuppressWarnings ("resource" )
307
+ Writer output = pipe .output ();
308
+ assertClosed (() -> output .write ('*' ));
305
309
}
306
310
307
311
@ Test
@@ -328,7 +332,9 @@ void testWriteCharArrayRange() throws IOException, InterruptedException {
328
332
readLatch .await ();
329
333
assertEquals (SOURCE , result .get ());
330
334
331
- assertClosed (() -> pipe .output ().write (chars ));
335
+ @ SuppressWarnings ("resource" )
336
+ Writer output = pipe .output ();
337
+ assertClosed (() -> output .write (chars ));
332
338
}
333
339
334
340
@ Test
@@ -353,7 +359,9 @@ void testWriteStringRange() throws IOException, InterruptedException {
353
359
readLatch .await ();
354
360
assertEquals (SOURCE , result .get ());
355
361
356
- assertClosed (() -> pipe .output ().write (SOURCE ));
362
+ @ SuppressWarnings ("resource" )
363
+ Writer output = pipe .output ();
364
+ assertClosed (() -> output .write (SOURCE ));
357
365
}
358
366
359
367
@ Test
@@ -382,7 +390,8 @@ private void testAppendCharSequence(Function<String, CharSequence> mapper) throw
382
390
readLatch .await ();
383
391
assertEquals (SOURCE + "null" , result .get ());
384
392
385
- assertClosed (() -> pipe .output ().append (SOURCE ));
393
+ Writer output = pipe .output ();
394
+ assertClosed (() -> output .append (SOURCE ));
386
395
}
387
396
388
397
@ Test
@@ -416,7 +425,9 @@ private void testAppendSubSequence(Function<String, CharSequence> mapper) throws
416
425
readLatch .await ();
417
426
assertEquals (SOURCE + "ul" , result .get ());
418
427
419
- assertClosed (() -> pipe .output ().write (SOURCE , 0 , 10 ));
428
+ @ SuppressWarnings ("resource" )
429
+ Writer output = pipe .output ();
430
+ assertClosed (() -> output .write (SOURCE , 0 , 10 ));
420
431
}
421
432
422
433
@ Test
@@ -434,7 +445,9 @@ void testAppendChar() throws IOException, InterruptedException {
434
445
readLatch .await ();
435
446
assertEquals (SOURCE , result .get ());
436
447
437
- assertClosed (() -> pipe .output ().write ('*' ));
448
+ @ SuppressWarnings ("resource" )
449
+ Writer output = pipe .output ();
450
+ assertClosed (() -> output .write ('*' ));
438
451
}
439
452
440
453
@ Test
@@ -453,8 +466,11 @@ void testOperationsWithReadError() throws IOException {
453
466
454
467
TextPipe pipe = new TextPipe ();
455
468
try (Writer output = pipe .output ()) {
469
+ @ SuppressWarnings ("resource" )
470
+ PipeReader input = pipe .input ();
471
+
456
472
IOException error = new IOException ();
457
- pipe . input () .close (error );
473
+ input .close (error );
458
474
459
475
assertSame (error , assertThrows (IOException .class , () -> output .write (chars [0 ])));
460
476
assertSame (error , assertThrows (IOException .class , () -> output .write (chars , 0 , 5 )));
@@ -464,7 +480,7 @@ void testOperationsWithReadError() throws IOException {
464
480
assertSame (error , assertThrows (IOException .class , () -> output .append (chars [0 ])));
465
481
assertSame (error , assertThrows (IOException .class , () -> output .flush ()));
466
482
467
- pipe . input () .close ();
483
+ input .close ();
468
484
469
485
assertSame (error , assertThrows (IOException .class , () -> output .write (chars [0 ])));
470
486
assertSame (error , assertThrows (IOException .class , () -> output .write (chars , 0 , 5 )));
@@ -474,7 +490,7 @@ void testOperationsWithReadError() throws IOException {
474
490
assertSame (error , assertThrows (IOException .class , () -> output .append (chars [0 ])));
475
491
assertSame (error , assertThrows (IOException .class , () -> output .flush ()));
476
492
477
- pipe . input () .close (null );
493
+ input .close (null );
478
494
479
495
assertClosed (() -> output .write (chars [0 ]));
480
496
assertClosed (() -> output .write (chars , 0 , 5 ));
@@ -517,7 +533,9 @@ void testWriteInt() throws InterruptedException {
517
533
Arrays .sort (actual );
518
534
assertArrayEquals (expected , actual );
519
535
520
- assertClosed (() -> pipe .output ().write (0 ));
536
+ @ SuppressWarnings ("resource" )
537
+ Writer output = pipe .output ();
538
+ assertClosed (() -> output .write (0 ));
521
539
}
522
540
523
541
@ Test
@@ -547,7 +565,9 @@ void testWriteCharArrayRange() throws InterruptedException {
547
565
Arrays .sort (actual );
548
566
assertArrayEquals (expected , actual );
549
567
550
- assertClosed (() -> pipe .output ().write (SOURCE ));
568
+ @ SuppressWarnings ("resource" )
569
+ Writer output = pipe .output ();
570
+ assertClosed (() -> output .write (SOURCE ));
551
571
}
552
572
553
573
@ Test
@@ -577,7 +597,9 @@ void testAppendSubSequence() throws InterruptedException {
577
597
Arrays .sort (actual );
578
598
assertArrayEquals (expected , actual );
579
599
580
- assertClosed (() -> pipe .output ().write (SOURCE ));
600
+ @ SuppressWarnings ("resource" )
601
+ Writer output = pipe .output ();
602
+ assertClosed (() -> output .write (SOURCE ));
581
603
}
582
604
}
583
605
@@ -665,7 +687,7 @@ void testAppendChar() throws IOException {
665
687
try (Writer output = pipe .output ()) {
666
688
output .write (0 );
667
689
IOException thrown = assertThrows (IOException .class , () -> {
668
- output .write ( 0 );
690
+ output .append ( '\0' );
669
691
});
670
692
assertEquals (Messages .pipe .readerDied (), thrown .getMessage ());
671
693
}
0 commit comments