summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2019-01-21 13:36:31 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2019-01-21 13:36:31 +0900
commitdf774825f56a0f0b51c8c73b81dc605e4c0646c0 (patch)
treef4fcbd806767b9b0a327a988efd1bb128c54bd30
parentecd16a790630be02986c519655aa5f0fe1e51c47 (diff)
downloadjgit-df774825f56a0f0b51c8c73b81dc605e4c0646c0.tar.gz
jgit-df774825f56a0f0b51c8c73b81dc605e4c0646c0.zip
SideBandOutputStreamTest: Open SideBandOutputStream in try-with-resource
Change-Id: I34041a556a5a83afcd0c1bab00e5d8088c30ea3f Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java96
1 files changed, 49 insertions, 47 deletions
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 b6cf3564c1..0bf9a8026e 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]);
}