diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java index b6cf3564c..0bf9a8026 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java @@ -77,76 +77,76 @@ public class SideBandOutputStreamTest { @Test public void testWrite_CH_DATA() throws IOException { - @SuppressWarnings("resource" /* java 7 */) - final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, - SMALL_BUF, rawOut); - out.write(new byte[] { 'a', 'b', 'c' }); - out.flush(); + try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA, + SMALL_BUF, rawOut)) { + out.write(new byte[] { 'a', 'b', 'c' }); + out.flush(); + } assertBuffer("0008\001abc"); } @Test public void testWrite_CH_PROGRESS() throws IOException { - @SuppressWarnings("resource" /* java 7 */) - final SideBandOutputStream out = new SideBandOutputStream(CH_PROGRESS, - SMALL_BUF, rawOut); - out.write(new byte[] { 'a', 'b', 'c' }); - out.flush(); + try (SideBandOutputStream out = new SideBandOutputStream(CH_PROGRESS, + SMALL_BUF, rawOut)) { + out.write(new byte[] { 'a', 'b', 'c' }); + out.flush(); + } assertBuffer("0008\002abc"); } @Test public void testWrite_CH_ERROR() throws IOException { - @SuppressWarnings("resource" /* java 7 */) - final SideBandOutputStream out = new SideBandOutputStream(CH_ERROR, - SMALL_BUF, rawOut); - out.write(new byte[] { 'a', 'b', 'c' }); - out.flush(); + try (SideBandOutputStream out = new SideBandOutputStream(CH_ERROR, + SMALL_BUF, rawOut)) { + out.write(new byte[] { 'a', 'b', 'c' }); + out.flush(); + } assertBuffer("0008\003abc"); } @Test public void testWrite_Small() throws IOException { - @SuppressWarnings("resource" /* java 7 */) - final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, - SMALL_BUF, rawOut); - out.write('a'); - out.write('b'); - out.write('c'); - out.flush(); + try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA, + SMALL_BUF, rawOut)) { + out.write('a'); + out.write('b'); + out.write('c'); + out.flush(); + } assertBuffer("0008\001abc"); } @Test public void testWrite_SmallBlocks1() throws IOException { - @SuppressWarnings("resource" /* java 7 */) - final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 6, - rawOut); - out.write('a'); - out.write('b'); - out.write('c'); - out.flush(); + try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 6, + rawOut)) { + out.write('a'); + out.write('b'); + out.write('c'); + out.flush(); + } assertBuffer("0006\001a0006\001b0006\001c"); } @Test public void testWrite_SmallBlocks2() throws IOException { - @SuppressWarnings("resource" /* java 7 */) - final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 6, - rawOut); - out.write(new byte[] { 'a', 'b', 'c' }); - out.flush(); + try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 6, + rawOut)) { + out.write(new byte[] { 'a', 'b', 'c' }); + out.flush(); + } assertBuffer("0006\001a0006\001b0006\001c"); } @Test public void testWrite_SmallBlocks3() throws IOException { - @SuppressWarnings("resource" /* java 7 */) - final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 7, - rawOut); - out.write('a'); - out.write(new byte[] { 'b', 'c' }); - out.flush(); + try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 7, + rawOut)) { + out.write('a'); + out.write(new byte[] { 'b', 'c' }); + out.flush(); + } assertBuffer("0007\001ab0006\001c"); } @@ -158,11 +158,11 @@ public class SideBandOutputStreamTest { buf[i] = (byte) i; } - @SuppressWarnings("resource" /* java 7 */) - final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, - MAX_BUF, rawOut); - out.write(buf); - out.flush(); + try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA, + MAX_BUF, rawOut)) { + out.write(buf); + out.flush(); + } final byte[] act = rawOut.toByteArray(); final String explen = Integer.toString(buf.length + HDR_SIZE, 16); @@ -174,7 +174,6 @@ public class SideBandOutputStreamTest { } } - @SuppressWarnings("resource" /* java 7 */) @Test public void testFlush() throws IOException { final int[] flushCnt = new int[1]; @@ -190,7 +189,10 @@ public class SideBandOutputStreamTest { } }; - new SideBandOutputStream(CH_DATA, SMALL_BUF, mockout).flush(); + try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA, + SMALL_BUF, mockout)) { + out.flush(); + } assertEquals(1, flushCnt[0]); }