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
public void testWrite_CH_DATA() throws IOException {
@SuppressWarnings("resource" /* java 7 */)
final SideBandOutputStream out = new SideBandOutputStream(CH_DATA,
SMALL_BUF, rawOut);
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);
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);
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);
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);
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);
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);
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);
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]);
}

Loading…
Cancel
Save