Javafx: "Wrap field with JavaFx property" intention - added test for adding/deleting FXML files (IDEA-102430)

This commit is contained in:
Pavel Dolgov
2016-10-28 14:59:42 +03:00
parent d136f9d79e
commit 74e42ee761
3 changed files with 47 additions and 4 deletions
@@ -1,6 +1,12 @@
package org.jetbrains.plugins.javaFX;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import java.io.IOException;
/**
* Same as the base test, but detects the presence of JavaFX using imports and FXMLs, not artifacts
@@ -9,11 +15,45 @@ import com.intellij.codeInsight.intention.IntentionAction;
public class JavaFxFieldToPropertyNoArtifactTest extends JavaFxFieldToPropertyTest {
public void testArtifactPresenceFieldToProperty() throws Exception {
final IntentionAction intentionAction = getIntentionAction(getTestName(false) + ".java");
configureByFiles(null, getTestName(false) + ".java");
final IntentionAction intentionAction = getIntentionAction();
// no artifact, no fxml, no javafx.* imports: the intention shoudn't be available
assertNull(intentionAction);
}
public void testAddRemoveFxmlFile() throws Exception {
final VirtualFile sourceRootDir = configureByFiles(null, getTestName(false) + ".java");
IntentionAction intentionAction = getIntentionAction();
assertNull(intentionAction);
final Ref<VirtualFile> fileRef = new Ref<>();
ApplicationManager.getApplication().runWriteAction(() -> {
try {
VirtualFile file = sourceRootDir.createChildData(JavaFxFieldToPropertyNoArtifactTest.this, "sample.fxml");
VfsUtil.saveText(file, "<?import javafx.scene.layout.VBox?>\n<VBox/>");
fileRef.set(file);
}
catch (IOException e) {
fail(e.toString());
}
});
intentionAction = getIntentionAction();
assertNotNull("when created", intentionAction);
ApplicationManager.getApplication().runWriteAction(() -> {
try {
fileRef.get().delete(JavaFxFieldToPropertyNoArtifactTest.this);
}
catch (IOException e) {
fail(e.toString());
}
});
intentionAction = getIntentionAction();
assertNull("when deleted", intentionAction);
}
@Override
protected boolean isArtifactNeeded() {
return false;
@@ -82,7 +82,8 @@ public class JavaFxFieldToPropertyTest extends DaemonAnalyzerTestCase {
private void doTest(String... fileNames) throws Exception {
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_7);
final IntentionAction intentionAction = getIntentionAction(fileNames);
configureByFiles(null, fileNames);
final IntentionAction intentionAction = getIntentionAction();
assertNotNull(intentionAction);
Editor editor = getEditor();
@@ -92,8 +93,7 @@ public class JavaFxFieldToPropertyTest extends DaemonAnalyzerTestCase {
checkResultByFile(getTestName(false) + "_after.java");
}
protected IntentionAction getIntentionAction(String... fileNames) throws Exception {
configureByFiles(null, fileNames);
protected IntentionAction getIntentionAction() throws Exception {
final List<HighlightInfo> infos = doHighlighting();
final Editor editor = getEditor();
final PsiFile file = getFile();
@@ -0,0 +1,3 @@
class FloatDemo {
float <caret>f;
}