assertThat(Element)

This commit is contained in:
Vladimir Krivosheev
2016-10-16 18:59:51 +02:00
parent 16b781a019
commit eedb2ad320
4 changed files with 11 additions and 14 deletions
@@ -846,7 +846,7 @@ public class PlatformTestUtil {
public static void assertElementsEqual(final Element expected, final Element actual) throws IOException {
if (!JDOMUtil.areElementsEqual(expected, actual)) {
Assert.assertEquals(printElement(expected), printElement(actual));
Assert.assertEquals(JDOMUtil.writeElement(expected), JDOMUtil.writeElement(actual));
}
}
@@ -859,12 +859,6 @@ public class PlatformTestUtil {
}
}
public static String printElement(final Element element) throws IOException {
final StringWriter writer = new StringWriter();
JDOMUtil.writeElement(element, writer, "\n");
return writer.getBuffer().toString();
}
public static String getCommunityPath() {
final String homePath = PathManager.getHomePath();
if (new File(homePath, "community/.idea").isDirectory()) {
@@ -877,7 +871,6 @@ public class PlatformTestUtil {
return getCommunityPath().replace(File.separatorChar, '/') + "/platform/platform-tests/testData/";
}
public static Comparator<AbstractTreeNode> createComparator(final Queryable.PrintInfo printInfo) {
return (o1, o2) -> {
String displayText1 = o1.toTestString(printInfo);
+1 -1
View File
@@ -25,7 +25,7 @@
<orderEntry type="module" module-name="images" exported="" scope="RUNTIME" />
<orderEntry type="module" module-name="RegExpSupport" exported="" scope="RUNTIME" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" scope="TEST" name="assertJ" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="assertJ" level="project" />
<orderEntry type="library" scope="TEST" name="memoryfilesystem" level="project" />
<orderEntry type="module" module-name="boot" />
</component>
@@ -24,6 +24,7 @@ import org.assertj.core.api.AbstractAssert
import org.assertj.core.api.PathAssert
import org.assertj.core.internal.Objects
import org.jdom.Element
import java.io.File
import java.nio.file.Files
import java.nio.file.LinkOption
import java.nio.file.Path
@@ -39,10 +40,14 @@ class JdomAssert(actual: Element?) : AbstractAssert<JdomAssert, Element?>(actual
return this
}
fun isEqualTo(file: File): JdomAssert {
return isEqualTo(file.readText())
}
fun isEqualTo(expected: String): JdomAssert {
isNotNull
Objects.instance().assertEqual(info, JDOMUtil.writeElement(actual!!), expected.trimIndent())
Objects.instance().assertEqual(info, JDOMUtil.writeElement(actual!!), expected.trimIndent().removePrefix("""<?xml version="1.0" encoding="UTF-8"?>""").trimStart())
return this
}
}
@@ -40,13 +40,14 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.IdeaTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader;
import java.io.File;
import static com.intellij.testFramework.Assertions.assertThat;
public class EclipseImlTest extends IdeaTestCase {
@NonNls private static final String JUNIT = "JUNIT";
@@ -100,11 +101,9 @@ public class EclipseImlTest extends IdeaTestCase {
PathMacroManager.getInstance(project).collapsePaths(actualImlElement);
PathMacros.getInstance().removeMacro(JUNIT);
Element expectedIml = JDOMUtil.load(new File(project.getBaseDir().getPath() + "/expected", "expected.iml"));
PlatformTestUtil.assertElementsEqual(expectedIml, actualImlElement);
assertThat(actualImlElement).isEqualTo(FileUtil.loadFile(new File(project.getBaseDir().getPath() + "/expected", "expected.iml")));
}
public void testWorkspaceOnly() throws Exception {
doTest();
}