use of org.syncany.database.FileVersionComparator.FileVersionComparison in project syncany by syncany.
the class TestAssertUtil method assertFileEquals.
public static void assertFileEquals(File expectedFile, File actualFile, FileChange... allowedChanges) throws ArrayComparisonFailure, Exception {
if (expectedFile == null && actualFile == null) {
return;
}
assertNotNull("Files are not equal: Actual file is " + actualFile + ", expected file is null.", expectedFile);
assertNotNull("Files are not equal: Expected file is " + expectedFile + ", actual file is null.", actualFile);
Path root = Paths.get(actualFile.getAbsolutePath()).getRoot();
FileVersionComparator fileVersionComparator = new FileVersionComparator(root.toFile(), "SHA1");
if (!FileUtil.exists(expectedFile)) {
fail("Files are not equal: Expected file " + expectedFile + " does not exist.");
}
if (!FileUtil.exists(actualFile)) {
fail("Files are not equal: Actual file " + actualFile + " does not exist.");
}
if (FileUtil.isSymlink(actualFile) && FileUtil.isSymlink(expectedFile)) {
return;
}
if (actualFile.isDirectory() != expectedFile.isDirectory()) {
fail("Files are not equal: Comparing a directory with a file (actual is dir = " + actualFile.isDirectory() + ", expected is dir = " + expectedFile.isDirectory() + ")");
}
if (actualFile.isDirectory() && expectedFile.isDirectory()) {
return;
}
if (actualFile.length() != expectedFile.length()) {
fail("Files are not equal: Actual file size (" + actualFile + " = " + actualFile.length() + ") does not match expected file size (" + expectedFile + " = " + expectedFile.length() + ")");
}
byte[] expectedFileChecksum = TestFileUtil.createChecksum(expectedFile);
byte[] actualFileChecksum = TestFileUtil.createChecksum(actualFile);
assertArrayEquals("Files are not equal: Actual file checksum (" + StringUtil.toHex(actualFileChecksum) + ") and expected file checksum (" + StringUtil.toHex(expectedFileChecksum) + ") do not match.", expectedFileChecksum, actualFileChecksum);
FileProperties actualFileProperties = fileVersionComparator.captureFileProperties(actualFile, null, true);
FileProperties expectedFileProperties = fileVersionComparator.captureFileProperties(expectedFile, null, true);
FileVersionComparison fileVersionComparison = fileVersionComparator.compare(expectedFileProperties, actualFileProperties, true);
List<FileChange> allowedChangesList = new ArrayList<FileChange>(Arrays.asList(allowedChanges));
allowedChangesList.add(FileChange.CHANGED_PATH);
if (!CollectionUtil.containsOnly(fileVersionComparison.getFileChanges(), allowedChangesList)) {
fail("Files are not equal: Actual file differs from expected file: " + fileVersionComparison.getFileChanges());
}
}
Aggregations