assertEqualsToFile() extracted as a common utility

This commit is contained in:
Andrey Breslav
2013-09-14 22:35:52 +04:00
parent f245d93eea
commit 67b23ceda7
2 changed files with 20 additions and 18 deletions
@@ -375,6 +375,24 @@ public class JetTestUtils {
return files;
}
public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull String actual) {
try {
if (!expectedFile.exists()) {
FileUtil.writeToFile(expectedFile, actual);
Assert.fail("Expected data file did not exist. Generating: " + expectedFile);
}
String expected = FileUtil.loadFile(expectedFile, true);
// compare with hard copy: make sure nothing is lost in output
Assert.assertEquals("Expected and actual namespaces differ from " + expectedFile.getName(),
StringUtil.convertLineSeparators(expected),
StringUtil.convertLineSeparators(actual));
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public interface TestFileFactory<F> {
F create(String fileName, String text, Map<String, String> directives);
}