@Test public void testAddToDictionary() throws UnsupportedEncodingException, NoSuchAlgorithmException { byte[] chunk1 = new byte[1024]; String hash = testlocker.md5ToString(testlocker.md5(chunk1)); testlocker.addToDictionary(hash, chunk1); Assert.assertTrue(testlocker.dictionary.contains(chunk1)); Assert.assertTrue(testlocker.dictionary.containsKey(hash)); }
@Test public void testcontentsMatch() throws UnsupportedEncodingException, NoSuchAlgorithmException { byte[] chunk2 = new byte[1024]; String hash = testlocker.md5ToString(testlocker.md5(chunk2)); String hash2 = hash + "false"; testlocker.addToDictionary(hash, chunk2); Assert.assertTrue(testlocker.contentsMatch(hash, chunk2)); Assert.assertFalse(testlocker.contentsMatch(hash2, chunk2)); }
@Test public void testgetSizeOfLocker() { int size = 0; for (FileInfo f : testlocker.files) { size += f.getSize(); } Assert.assertEquals(size, testlocker.getSizeOfLocker()); }
@Test public void testgetSizeOfDB() throws IOException { RandomAccessFile locker1 = new RandomAccessFile("locker.txt", "r"); FileChannel l = locker1.getChannel(); long dbSize = l.size(); Assert.assertEquals(testlocker.getSizeOfDB(), dbSize); }
@Test public void testHashExists() { byte[] chunk1 = new byte[1024]; testlocker.dictionary.put("1", chunk1); Assert.assertEquals(testlocker.hashExists("1"), testlocker.dictionary.containsKey("1")); }
@Test public void tetGetProgress() { Assert.assertEquals(testlocker.getProgress(), testlocker.progress); }
@Test(expected = FileNotFoundException.class) public void testDynamicBlockInsert() { testlocker.dynamicBlockInsert("nosuchfile"); }