Browse Source

TemporaryBufferTest: Suppress "should be managed by try-with-resource"

In most of the tests, the temporary buffer is explicitly destroyed in
a finally block after being closed. This is not possible if using the
try-with-resource construct, because the variable is not accessible in
the finally block scope.

Change-Id: I3bab30695ddd12e1a0ae107989638428fe3ef551
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.0
David Pursehouse 7 years ago committed by Matthias Sohn
parent
commit
bf757cd1c6
  1. 13
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java

13
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java

@ -61,6 +61,7 @@ import org.junit.Test;
public class TemporaryBufferTest {
@Test
public void testEmpty() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
try {
b.close();
@ -75,6 +76,7 @@ public class TemporaryBufferTest {
@Test
public void testOneByte() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte test = (byte) new TestRng(getName()).nextInt();
try {
@ -100,6 +102,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlock_BulkWrite() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ);
@ -129,6 +132,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlockAndHalf_BulkWrite() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
@ -158,6 +162,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlockAndHalf_SingleWrite() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
@ -185,6 +190,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlockAndHalf_Copy() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
@ -213,6 +219,7 @@ public class TemporaryBufferTest {
@Test
public void testLarge_SingleWrite() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
@ -252,6 +259,7 @@ public class TemporaryBufferTest {
@Test
public void testInCoreLimit_SwitchOnAppendByte() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT + 1);
@ -279,6 +287,7 @@ public class TemporaryBufferTest {
@Test
public void testInCoreLimit_SwitchBeforeAppendByte() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
@ -306,6 +315,7 @@ public class TemporaryBufferTest {
@Test
public void testInCoreLimit_SwitchOnCopy() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2);
@ -336,7 +346,7 @@ public class TemporaryBufferTest {
@Test
public void testDestroyWhileOpen() throws IOException {
@SuppressWarnings("resource" /* java 7 */)
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
try {
b.write(new TestRng(getName())
@ -348,6 +358,7 @@ public class TemporaryBufferTest {
@Test
public void testRandomWrites() throws IOException {
@SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final TestRng rng = new TestRng(getName());
final int max = TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2;

Loading…
Cancel
Save