summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2016-01-22 14:51:52 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2016-01-22 14:51:59 +0900
commit84ac3cc3792ec164e304acf89d739bf724b619cc (patch)
tree1846d454ffb50db4939db21bda77ddcf87b8a3f2
parent3ee9e2ac076733298906b92965a27a532c1cd5f5 (diff)
downloadjgit-84ac3cc3792ec164e304acf89d739bf724b619cc.tar.gz
jgit-84ac3cc3792ec164e304acf89d739bf724b619cc.zip
UnpackedObjectTest: Create ObjectInserter.Formatter in try-with-resource
The ObjectInserter.Formatter instance is only used to call idFor. Factor out a utility method to do that. Change-Id: I4ef823110c2152ac7905681df3217eb8001f5bd9 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java
index 8c8c6c6d0c..c6653bfdb7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java
@@ -143,7 +143,7 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
public void testStandardFormat_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
- ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
+ ObjectId id = getId(type, data);
write(id, compressStandardFormat(type, data));
ObjectLoader ol;
@@ -306,7 +306,7 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
- ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
+ ObjectId id = getId(type, data);
byte[] gz = compressStandardFormat(type, data);
gz[gz.length - 1] = 0;
gz[gz.length - 2] = 0;
@@ -344,7 +344,7 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
- ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
+ ObjectId id = getId(type, data);
byte[] gz = compressStandardFormat(type, data);
byte[] tr = new byte[gz.length - 1];
System.arraycopy(gz, 0, tr, 0, tr.length);
@@ -379,7 +379,7 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
- ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
+ ObjectId id = getId(type, data);
byte[] gz = compressStandardFormat(type, data);
byte[] tr = new byte[gz.length + 1];
System.arraycopy(gz, 0, tr, 0, gz.length);
@@ -438,7 +438,7 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
public void testPackFormat_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
- ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
+ ObjectId id = getId(type, data);
write(id, compressPackFormat(type, data));
ObjectLoader ol;
@@ -578,4 +578,10 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
out.close();
}
}
+
+ private ObjectId getId(int type, byte[] data) {
+ try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
+ return formatter.idFor(type, data);
+ }
+ }
}