Set virtual files in LightQuickFixTestCase.java to readonly to check if quick-fix clears the read-only flag

This commit is contained in:
Tagir Valeev
2016-09-19 09:45:37 +07:00
parent 5e422160c6
commit 8995233c22
2 changed files with 16 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler;
import com.intellij.lang.Commenter;
import com.intellij.lang.LanguageCommenters;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
@@ -36,6 +37,7 @@ import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ObjectUtils;
import com.intellij.util.io.ReadOnlyAttributeUtil;
import com.intellij.util.ui.UIUtil;
import org.intellij.lang.annotations.RegExp;
import org.jetbrains.annotations.NonNls;
@@ -43,6 +45,7 @@ import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -180,7 +183,17 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
}
protected static void invoke(@NotNull IntentionAction action) throws IncorrectOperationException {
ShowIntentionActionsHandler.chooseActionAndInvoke(getFile(), getEditor(), action, action.getText());
PsiFile file = getFile();
WriteAction.run(() -> {
try {
// Test that action will automatically clear the read-only attribute if modification is necessary
ReadOnlyAttributeUtil.setReadOnlyAttribute(file.getVirtualFile(), true);
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
});
ShowIntentionActionsHandler.chooseActionAndInvoke(file, getEditor(), action, action.getText());
UIUtil.dispatchAllInvocationEvents();
}
@@ -24,7 +24,6 @@ import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.MultiValuesMap;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -96,6 +95,7 @@ public class ReadonlyStatusHandlerImpl extends ReadonlyStatusHandler implements
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
processFiles(new ArrayList<>(Arrays.asList(fileInfos)), null);
return createResultStatus(files);
}