From 20e5d8d818eaba58f46cffef4f09589a7f4ea7f6 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 20 Aug 2012 17:06:41 +0400 Subject: [PATCH] Fix test Make any modification, so that Document and file content differ. Otherwise save won't be, and "on-save" actions won't be called. --- .../openapi/editor/StripTrailingSpacesTest.java | 6 ++++-- .../LightPlatformCodeInsightTestCase.java | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/StripTrailingSpacesTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/StripTrailingSpacesTest.java index cc898893f54c..a30d175ddb33 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/StripTrailingSpacesTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/StripTrailingSpacesTest.java @@ -130,9 +130,11 @@ public class StripTrailingSpacesTest extends LightPlatformCodeInsightTestCase { settings.setStripTrailingSpaces(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE); settings.setEnsureNewLineAtEOF(true); - configureFromFileText("x.txt", "xxx \nyyy\n\t\t\t"); + Document document = configureFromFileText("x.txt", "xxx \nyyy\n\t\t\t"); + // make any modification, so that Document and file content differ. Otherwise save won't be, and "on-save" actions won't be called. + document.insertString(0, " "); FileDocumentManager.getInstance().saveAllDocuments(); - checkResultByText("xxx \nyyy\n\t\t\t\n"); + checkResultByText(" xxx \nyyy\n\t\t\t\n"); } } diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java index 6d3ec85e2459..b2bfc2a3df3a 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java @@ -36,6 +36,7 @@ import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.fileEditor.impl.TrailingSpacesStripper; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.CharsetToolkit; @@ -139,10 +140,11 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest * @param fileText - data file text. * @throws java.io.IOException */ - protected static void configureFromFileText(@NonNls final String fileName, @NonNls final String fileText) throws IOException { - ApplicationManager.getApplication().runWriteAction(new Runnable() { + @NotNull + protected static Document configureFromFileText(@NonNls final String fileName, @NonNls final String fileText) throws IOException { + return ApplicationManager.getApplication().runWriteAction(new Computable() { @Override - public void run() { + public Document compute() { final Document fakeDocument = new DocumentImpl(fileText); int caretIndex = fileText.indexOf(CARET_MARKER); @@ -166,8 +168,9 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest } String newFileText = fakeDocument.getText(); + Document document; try { - setupFileEditorAndDocument(fileName, newFileText); + document = setupFileEditorAndDocument(fileName, newFileText); } catch (IOException e) { throw new RuntimeException(e); @@ -175,6 +178,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest setupCaret(caretMarker, newFileText); setupSelection(selStartMarker, selEndMarker); setupEditorForInjectedLanguage(); + return document; } }); } @@ -202,7 +206,8 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest return editor; } - private static void setupFileEditorAndDocument(final String fileName, String fileText) throws IOException { + @NotNull + private static Document setupFileEditorAndDocument(final String fileName, String fileText) throws IOException { EncodingProjectManager.getInstance(getProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET); EncodingProjectManager.getInstance(ProjectManager.getInstance().getDefaultProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET); PostprocessReformattingAspect.getInstance(ourProject).doPostponedFormatting(); @@ -222,6 +227,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest myVFile.setCharset(CharsetToolkit.UTF8_CHARSET); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); + return document; } private static void setupEditorForInjectedLanguage() {