diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java
index d9d39a9a68bc..c2655b28e60e 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java
@@ -1,12 +1,17 @@
/*
- * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
- */
-
-/*
- * Created by IntelliJ IDEA.
- * User: Anna.Kozlova
- * Date: 18-Aug-2006
- * Time: 13:42:59
+ * Copyright 2000-2011 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.intellij.codeInspection;
@@ -14,32 +19,34 @@ import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.profile.codeInspection.InspectionProfileManager;
-import com.intellij.testFramework.UsefulTestCase;
-import com.intellij.testFramework.fixtures.IdeaTestFixture;
-import com.intellij.testFramework.fixtures.JavaTestFixtureFactory;
+import com.intellij.testFramework.LightIdeaTestCase;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import java.io.IOException;
-import java.io.StringWriter;
-public class InspectionProfileTest extends UsefulTestCase {
+import static com.intellij.testFramework.PlatformTestUtil.assertElementsEqual;
+
+/**
+ * @author Anna.Kozlova
+ * Date: 18-Aug-2006
+ */
+public class InspectionProfileTest extends LightIdeaTestCase {
private static final String PROFILE = "ToConvert";
- private final IdeaTestFixture myFixture = JavaTestFixtureFactory.getFixtureFactory().createLightFixtureBuilder().getFixture();
@Override
protected void setUp() throws Exception {
+ //noinspection AssignmentToStaticFieldFromInstanceMethod
InspectionProfileImpl.INIT_INSPECTIONS = true;
super.setUp();
- myFixture.setUp();
InspectionToolRegistrar.getInstance().ensureInitialized();
}
@Override
protected void tearDown() throws Exception {
- myFixture.tearDown();
super.tearDown();
+ //noinspection AssignmentToStaticFieldFromInstanceMethod
InspectionProfileImpl.INIT_INSPECTIONS = false;
InspectionProfileManager.getInstance().deleteProfile(PROFILE);
}
@@ -52,9 +59,7 @@ public class InspectionProfileTest extends UsefulTestCase {
model.commit();
final Element copy = new Element("inspections");
profile.writeExternal(copy);
- StringWriter writer = new StringWriter();
- JDOMUtil.writeElement(copy, writer, "\n");
- assertTrue(writer.getBuffer().toString(), JDOMUtil.areElementsEqual(element, copy));
+ assertElementsEqual(element, copy);
}
public void testConvertOldProfile() throws Exception {
@@ -65,9 +70,7 @@ public class InspectionProfileTest extends UsefulTestCase {
model.commit();
final Element copy = new Element("inspections");
profile.writeExternal(copy);
- StringWriter writer = new StringWriter();
- JDOMUtil.writeElement(copy, writer, "\n");
- assertTrue(writer.getBuffer().toString(), JDOMUtil.areElementsEqual(loadProfile(), copy));
+ assertElementsEqual(loadProfile(), copy);
}
private static Element loadOldStyleProfile() throws IOException, JDOMException {
@@ -143,11 +146,10 @@ public class InspectionProfileTest extends UsefulTestCase {
" \n" +
" \n" +
"");
-
return document.getRootElement();
}
- public void testReloadProfileWithUnknownScopes() throws Exception {
+ public void testReloadProfileWithUnknownScopes() throws Exception {
final Element element = JDOMUtil.loadDocument("\n" +
" \n" +
" \n" +
@@ -167,8 +169,6 @@ public class InspectionProfileTest extends UsefulTestCase {
model.commit();
final Element copy = new Element("inspections");
profile.writeExternal(copy);
- StringWriter writer = new StringWriter();
- JDOMUtil.writeElement(copy, writer, "\n");
- assertTrue(writer.getBuffer().toString(), JDOMUtil.areElementsEqual(element, copy));
+ assertElementsEqual(element, copy);
}
}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java
index e80c2a0cef69..ec7f8933c3e6 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java
@@ -1,6 +1,17 @@
/*
- * User: anna
- * Date: 13-Apr-2009
+ * Copyright 2000-2011 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.intellij.codeInspection;
@@ -10,12 +21,16 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.testFramework.LightIdeaTestCase;
-import org.jdom.Document;
+import com.intellij.testFramework.PlatformTestUtil;
import org.jdom.Element;
import java.io.File;
import java.util.List;
+/**
+ * @author anna
+ * Date: 13-Apr-2009
+ */
public class InspectionProfilesConverterTest extends LightIdeaTestCase {
public void testOptions() throws Exception {
doTest("options");
@@ -25,12 +40,11 @@ public class InspectionProfilesConverterTest extends LightIdeaTestCase {
doTest("scope");
}
- public static void doTest(final String dirName) throws Exception {
+ private static void doTest(final String dirName) throws Exception {
try {
final String relativePath = "/inspection/converter/";
- final List children =
- JDOMUtil.loadDocument(new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.ipr")).getRootElement()
- .getChildren("component");
+ final File projectFile = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.ipr");
+ final List children = JDOMUtil.loadDocument(projectFile).getRootElement().getChildren("component");
for (Object child : children) {
final Element element = (Element)child;
@@ -39,11 +53,10 @@ public class InspectionProfilesConverterTest extends LightIdeaTestCase {
InspectionProfileImpl.INIT_INSPECTIONS = true;
profileManager.readExternal(element);
- final Element confElement = new Element("config");
- profileManager.writeExternal(confElement);
- assertTrue(new String(JDOMUtil.printDocument(new Document(confElement), "\n")),
- JDOMUtil.areElementsEqual(confElement, JDOMUtil.loadDocument(new File(JavaTestUtil.getJavaTestDataPath() +
- relativePath + dirName + "/options.after.xml")).getRootElement()));
+ final Element configElement = new Element("config");
+ profileManager.writeExternal(configElement);
+ final File file = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.after.xml");
+ PlatformTestUtil.assertElementsEqual(configElement, JDOMUtil.loadDocument(file).getRootElement());
break;
}
}
diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java
index 52823807adfd..39d72cea67f7 100644
--- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java
+++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java
@@ -36,6 +36,7 @@ import com.intellij.openapi.ui.Queryable;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
@@ -47,6 +48,7 @@ import com.intellij.util.SystemProperties;
import com.intellij.util.containers.HashMap;
import com.intellij.util.io.ZipUtil;
import com.intellij.util.ui.UIUtil;
+import org.jdom.Element;
import org.junit.Assert;
import junit.framework.AssertionFailedError;
import org.jetbrains.annotations.NonNls;
@@ -62,6 +64,7 @@ import java.awt.event.InvocationEvent;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
+import java.io.StringWriter;
import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -528,6 +531,18 @@ public class PlatformTestUtil {
assertDirectoriesEqual(dirAfter, dirBefore, CVS_FILE_FILTER);
}
+ public static void assertElementsEqual(final Element expected, final Element actual) throws IOException {
+ if (!JDOMUtil.areElementsEqual(expected, actual)) {
+ junit.framework.Assert.assertEquals(printElement(expected), printElement(actual));
+ }
+ }
+
+ 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 class CvsVirtualFileFilter implements VirtualFileFilter, FilenameFilter {
@Override
public boolean accept(VirtualFile file) {