[java-decompiler] common file comparison method extracted; test data updated

This commit is contained in:
Roman Shevchenko
2015-09-07 19:23:12 +03:00
parent 9a06c52a8f
commit aab87019ef
6 changed files with 82 additions and 48 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,8 +15,10 @@
*/
package org.jetbrains.java.decompiler;
import org.hamcrest.Matchers;
import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import java.io.File;
import java.io.IOException;
@@ -24,6 +26,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class DecompilerTestFixture {
@@ -43,6 +46,7 @@ public class DecompilerTestFixture {
if (!isTestDataDir(testDataDir)) testDataDir = new File("../community/plugins/java-decompiler/engine/testData");
if (!isTestDataDir(testDataDir)) testDataDir = new File("../plugins/java-decompiler/engine/testData");
assertTrue("current dir: " + new File("").getAbsolutePath(), isTestDataDir(testDataDir));
testDataDir = testDataDir.getAbsoluteFile();
//noinspection SSBasedInspection
tempDir = File.createTempFile("decompiler_test_", "_dir");
@@ -96,4 +100,25 @@ public class DecompilerTestFixture {
}
assertTrue(file.delete());
}
public static void assertFilesEqual(File expected, File actual) {
if (expected.isDirectory()) {
assertThat(actual.list(), Matchers.arrayContainingInAnyOrder(expected.list()));
for (String name : expected.list()) {
assertFilesEqual(new File(expected, name), new File(actual, name));
}
}
else {
assertThat(getContent(actual), Matchers.equalTo(getContent(expected)));
}
}
private static String getContent(File expected) {
try {
return new String(InterpreterUtil.getBytes(expected), "UTF-8").replace("\r\n", "\n");
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}