Browse Source

SideBandOutputStreamTest: Open SideBandOutputStream in try-with-resource

Change-Id: I34041a556a5a83afcd0c1bab00e5d8088c30ea3f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.4
David Pursehouse 6 years ago
parent
commit
df774825f5
  1. 54
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java

54
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java

@ -77,76 +77,76 @@ public class SideBandOutputStreamTest {
@Test @Test
public void testWrite_CH_DATA() throws IOException { public void testWrite_CH_DATA() throws IOException {
@SuppressWarnings("resource" /* java 7 */) try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA,
final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, SMALL_BUF, rawOut)) {
SMALL_BUF, rawOut);
out.write(new byte[] { 'a', 'b', 'c' }); out.write(new byte[] { 'a', 'b', 'c' });
out.flush(); out.flush();
}
assertBuffer("0008\001abc"); assertBuffer("0008\001abc");
} }
@Test @Test
public void testWrite_CH_PROGRESS() throws IOException { public void testWrite_CH_PROGRESS() throws IOException {
@SuppressWarnings("resource" /* java 7 */) try (SideBandOutputStream out = new SideBandOutputStream(CH_PROGRESS,
final SideBandOutputStream out = new SideBandOutputStream(CH_PROGRESS, SMALL_BUF, rawOut)) {
SMALL_BUF, rawOut);
out.write(new byte[] { 'a', 'b', 'c' }); out.write(new byte[] { 'a', 'b', 'c' });
out.flush(); out.flush();
}
assertBuffer("0008\002abc"); assertBuffer("0008\002abc");
} }
@Test @Test
public void testWrite_CH_ERROR() throws IOException { public void testWrite_CH_ERROR() throws IOException {
@SuppressWarnings("resource" /* java 7 */) try (SideBandOutputStream out = new SideBandOutputStream(CH_ERROR,
final SideBandOutputStream out = new SideBandOutputStream(CH_ERROR, SMALL_BUF, rawOut)) {
SMALL_BUF, rawOut);
out.write(new byte[] { 'a', 'b', 'c' }); out.write(new byte[] { 'a', 'b', 'c' });
out.flush(); out.flush();
}
assertBuffer("0008\003abc"); assertBuffer("0008\003abc");
} }
@Test @Test
public void testWrite_Small() throws IOException { public void testWrite_Small() throws IOException {
@SuppressWarnings("resource" /* java 7 */) try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA,
final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, SMALL_BUF, rawOut)) {
SMALL_BUF, rawOut);
out.write('a'); out.write('a');
out.write('b'); out.write('b');
out.write('c'); out.write('c');
out.flush(); out.flush();
}
assertBuffer("0008\001abc"); assertBuffer("0008\001abc");
} }
@Test @Test
public void testWrite_SmallBlocks1() throws IOException { public void testWrite_SmallBlocks1() throws IOException {
@SuppressWarnings("resource" /* java 7 */) try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 6,
final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 6, rawOut)) {
rawOut);
out.write('a'); out.write('a');
out.write('b'); out.write('b');
out.write('c'); out.write('c');
out.flush(); out.flush();
}
assertBuffer("0006\001a0006\001b0006\001c"); assertBuffer("0006\001a0006\001b0006\001c");
} }
@Test @Test
public void testWrite_SmallBlocks2() throws IOException { public void testWrite_SmallBlocks2() throws IOException {
@SuppressWarnings("resource" /* java 7 */) try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 6,
final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 6, rawOut)) {
rawOut);
out.write(new byte[] { 'a', 'b', 'c' }); out.write(new byte[] { 'a', 'b', 'c' });
out.flush(); out.flush();
}
assertBuffer("0006\001a0006\001b0006\001c"); assertBuffer("0006\001a0006\001b0006\001c");
} }
@Test @Test
public void testWrite_SmallBlocks3() throws IOException { public void testWrite_SmallBlocks3() throws IOException {
@SuppressWarnings("resource" /* java 7 */) try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 7,
final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, 7, rawOut)) {
rawOut);
out.write('a'); out.write('a');
out.write(new byte[] { 'b', 'c' }); out.write(new byte[] { 'b', 'c' });
out.flush(); out.flush();
}
assertBuffer("0007\001ab0006\001c"); assertBuffer("0007\001ab0006\001c");
} }
@ -158,11 +158,11 @@ public class SideBandOutputStreamTest {
buf[i] = (byte) i; buf[i] = (byte) i;
} }
@SuppressWarnings("resource" /* java 7 */) try (SideBandOutputStream out = new SideBandOutputStream(CH_DATA,
final SideBandOutputStream out = new SideBandOutputStream(CH_DATA, MAX_BUF, rawOut)) {
MAX_BUF, rawOut);
out.write(buf); out.write(buf);
out.flush(); out.flush();
}
final byte[] act = rawOut.toByteArray(); final byte[] act = rawOut.toByteArray();
final String explen = Integer.toString(buf.length + HDR_SIZE, 16); final String explen = Integer.toString(buf.length + HDR_SIZE, 16);
@ -174,7 +174,6 @@ public class SideBandOutputStreamTest {
} }
} }
@SuppressWarnings("resource" /* java 7 */)
@Test @Test
public void testFlush() throws IOException { public void testFlush() throws IOException {
final int[] flushCnt = new int[1]; 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]); assertEquals(1, flushCnt[0]);
} }

Loading…
Cancel
Save