Procházet zdrojové kódy

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>
tags/v4.3.0.201603230630-rc1
David Pursehouse před 8 roky
rodič
revize
84ac3cc379

+ 11
- 5
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java Zobrazit soubor

public void testStandardFormat_LargeObject() throws Exception { public void testStandardFormat_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB; final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5); byte[] data = getRng().nextBytes(streamThreshold + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
ObjectId id = getId(type, data);
write(id, compressStandardFormat(type, data)); write(id, compressStandardFormat(type, data));


ObjectLoader ol; ObjectLoader ol;
throws Exception { throws Exception {
final int type = Constants.OBJ_BLOB; final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5); 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[] gz = compressStandardFormat(type, data);
gz[gz.length - 1] = 0; gz[gz.length - 1] = 0;
gz[gz.length - 2] = 0; gz[gz.length - 2] = 0;
throws Exception { throws Exception {
final int type = Constants.OBJ_BLOB; final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5); 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[] gz = compressStandardFormat(type, data);
byte[] tr = new byte[gz.length - 1]; byte[] tr = new byte[gz.length - 1];
System.arraycopy(gz, 0, tr, 0, tr.length); System.arraycopy(gz, 0, tr, 0, tr.length);
throws Exception { throws Exception {
final int type = Constants.OBJ_BLOB; final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5); 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[] gz = compressStandardFormat(type, data);
byte[] tr = new byte[gz.length + 1]; byte[] tr = new byte[gz.length + 1];
System.arraycopy(gz, 0, tr, 0, gz.length); System.arraycopy(gz, 0, tr, 0, gz.length);
public void testPackFormat_LargeObject() throws Exception { public void testPackFormat_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB; final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5); byte[] data = getRng().nextBytes(streamThreshold + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
ObjectId id = getId(type, data);
write(id, compressPackFormat(type, data)); write(id, compressPackFormat(type, data));


ObjectLoader ol; ObjectLoader ol;
out.close(); out.close();
} }
} }

private ObjectId getId(int type, byte[] data) {
try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
return formatter.idFor(type, data);
}
}
} }

Načítá se…
Zrušit
Uložit