Skip to content

Commit e629e9e

Browse files
committed
DfsPackFileMidx tests: Compare byte[] for checksum
We cannot precalculate the checkum of the midx, because it includes the file names and these change between tests. The test validates that the first 4 bytes are not the header (MIDX), so at least we are not reading from the beginning of the buffer. It compares 4 bytes independently and we run the risk of finding them by chance in the actual checksum. Compare the 4 bytes as array, so we fail only if the 4 of them match. Change-Id: Id26a7722bb564670db68dc3102b38f8b6a6a6964
1 parent 11c702b commit e629e9e

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileMidxNPacksTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.junit.Assert.assertArrayEquals;
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertFalse;
23-
import static org.junit.Assert.assertNotEquals;
2423
import static org.junit.Assert.assertNotNull;
2524
import static org.junit.Assert.assertNull;
2625
import static org.junit.Assert.assertThrows;
@@ -1054,10 +1053,9 @@ public void getChecksum() throws Exception {
10541053
byte[] checksum = midx.getChecksum(ctx);
10551054
assertNotNull(checksum);
10561055
assertEquals(20, checksum.length);
1057-
assertNotEquals('M', checksum[0]);
1058-
assertNotEquals('I', checksum[1]);
1059-
assertNotEquals('D', checksum[2]);
1060-
assertNotEquals('X', checksum[3]);
1056+
1057+
byte[] mdixHeader = { 'M', 'I', 'D', 'X' };
1058+
assertFalse(Arrays.equals(mdixHeader, 0, 4, checksum, 0, 4));
10611059
}
10621060
}
10631061

org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileMidxSingleTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.junit.Assert.assertArrayEquals;
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertFalse;
23-
import static org.junit.Assert.assertNotEquals;
2423
import static org.junit.Assert.assertNotNull;
2524
import static org.junit.Assert.assertNull;
2625
import static org.junit.Assert.assertThrows;
@@ -1023,10 +1022,9 @@ public void getChecksum() throws Exception {
10231022
byte[] checksum = midx.getChecksum(ctx);
10241023
assertNotNull(checksum);
10251024
assertEquals(20, checksum.length);
1026-
assertNotEquals('M', checksum[0]);
1027-
assertNotEquals('I', checksum[1]);
1028-
assertNotEquals('D', checksum[2]);
1029-
assertNotEquals('X', checksum[3]);
1025+
1026+
byte[] mdixHeader = { 'M', 'I', 'D', 'X' };
1027+
assertFalse(Arrays.equals(mdixHeader, 0, 4, checksum, 0, 4));
10301028
}
10311029
}
10321030

0 commit comments

Comments
 (0)