@Override public void setUp() throws Exception { super.setUp(); Settings.getInstance(myFixture.getProject()).pluginEnabled = true; }
/** * Tests that {@link ApiParameterInspection.MyQuickFix} does not add any annotation to a {@link * PsiParameter} that already has an @Named annotation. */ public void testQuickFix_parameterWithNamedAnnotation() { Project myProject = myFixture.getProject(); String parameterText = "@" + GctConstants.APP_ENGINE_ANNOTATION_NAMED + "(\"foo\")int someParam"; runQuickFixTest(parameterText, parameterText); }
protected void createDummyFiles(String... files) { for (String file : files) { String path = myFixture.getProject().getBaseDir().getPath() + "/" + file; File f = new File(path); try { f.getParentFile().mkdirs(); f.createNewFile(); } catch (IOException e) { e.printStackTrace(); fail(String.format("failed to create file '%s'", file)); } } }
@Nonnull @CheckReturnValue protected Project getProject() { if (fixture == null) { throw new AssertionError("getProject() must call after setUp()"); } return fixture.getProject(); } }
@Override protected void setUp() throws Exception { super.setUp(); myTemplateToolkitTestSettings = new TemplateToolkitTestSettings(myFixture.getProject()); }
protected Project getProject() { final String path = getProjectPath(); if (path != null) return ProjectUtil.ensureProject(path); return myFixture.getProject(); }
@Override protected void setUp() throws Exception { super.setUp(); myTestSettings = new TemplateToolkitTestSettings(myFixture.getProject()); myTestSettings.setUp(); }
public void testQuickFix_noConstructor() { ProblemDescriptorImpl problemDescriptorMock = mock(ProblemDescriptorImpl.class); MockitoAnnotations.initMocks(this); PsiClass psiClass = JavaPsiFacade.getInstance(myFixture.getProject()) .getElementFactory() .createClass(getName()); ConstructorInspection constructorInspection = new ConstructorInspection(); ConstructorInspection.MyQuickFix myQuickFix = constructorInspection.new MyQuickFix(psiClass); myQuickFix.applyFix(myFixture.getProject(), problemDescriptorMock); Assert.assertEquals(1, psiClass.getConstructors().length); Assert.assertTrue(EndpointUtilities.isPublicNullaryConstructor(psiClass.getConstructors()[0])); }
private void runQuickFixTest(String parameterText, String expectedString) { Project myProject = myFixture.getProject(); PsiParameter parameter = JavaPsiFacade.getInstance(myProject) .getElementFactory() .createParameterFromText(parameterText, null); ApiParameterInspection.MyQuickFix myQuickFix = new ApiParameterInspection().new MyQuickFix(); MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(parameter, "", ProblemHighlightType.ERROR); myQuickFix.applyFix(myFixture.getProject(), problemDescriptor); Assert.assertEquals(expectedString, parameter.getText()); }
/** * Tests that the Quick fix for a parameter with no annotation returns the same parameter * unchanged. */ public void testQuickFix_noAnnotation() { Project myProject = myFixture.getProject(); PsiParameter parameter = JavaPsiFacade.getInstance(myProject) .getElementFactory() .createParameter("param", PsiType.BOOLEAN); runQuickFixTest(parameter, "boolean param"); }
public void testQuickFix() { PsiMethod someFunction = JavaPsiFacade.getInstance(myFixture.getProject()) .getElementFactory() .createMethod("someFunction", PsiType.VOID); MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(someFunction, "", ProblemHighlightType.ERROR); FullJavaNameInspection.MyQuickFix myQuickFix = new FullJavaNameInspection().new MyQuickFix(); myQuickFix.applyFix(myFixture.getProject(), problemDescriptor); assertEquals("someFunction_1", someFunction.getName()); myQuickFix.applyFix(myFixture.getProject(), problemDescriptor); assertEquals("someFunction_1_1", someFunction.getName()); }
private void runQuickFixTest(PsiParameter parameter, String expectedString) { InvalidParameterAnnotationsInspection.MyQuickFix myQuickFix = new InvalidParameterAnnotationsInspection.MyQuickFix(); MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(parameter, "", ProblemHighlightType.ERROR); myQuickFix.applyFix(myFixture.getProject(), problemDescriptor); assertEquals(expectedString, parameter.getText()); }
/** Test that the Quick fix for a parameter with @Named returns the same parameter unchanged. */ public void testQuickFix_withNamedAnnotation() { Project myProject = myFixture.getProject(); PsiParameter parameter = JavaPsiFacade.getInstance(myProject) .getElementFactory() .createParameter("param", PsiType.BOOLEAN); parameter.getModifierList().addAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED); runQuickFixTest(parameter, "@" + GctConstants.APP_ENGINE_ANNOTATION_NAMED + " boolean param"); }
/** * Tests that the Quick fix for a parameter with the javax @Nullable returns the parameter * without @Nullable. */ public void testQuickFix_withJavaxNullableAnnotation() { Project myProject = myFixture.getProject(); PsiParameter parameter = JavaPsiFacade.getInstance(myProject) .getElementFactory() .createParameter("param", PsiType.BOOLEAN); parameter.getModifierList().addAnnotation("javax.annotation.Nullable"); runQuickFixTest(parameter, " boolean param"); }
/** * Tests that the Quick fix for a parameter with @DefaultValue returns the parameter * without @DefaultValue. */ public void testQuickFix_withDefaultAnnotation() { Project myProject = myFixture.getProject(); PsiParameter parameter = JavaPsiFacade.getInstance(myProject) .getElementFactory() .createParameter("param", PsiType.BOOLEAN); parameter.getModifierList().addAnnotation(GctConstants.APP_ENGINE_ANNOTATION_DEFAULT_VALUE); runQuickFixTest(parameter, " boolean param"); }
/** * Tests that the Quick fix for a parameter with the App Engine @Nullable returns the parameter * without @Nullable. */ public void testQuickFix_withGaeNullableAnnotation() { Project myProject = myFixture.getProject(); PsiParameter parameter = JavaPsiFacade.getInstance(myProject) .getElementFactory() .createParameter("param", PsiType.BOOLEAN); parameter.getModifierList().addAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NULLABLE); runQuickFixTest(parameter, " boolean param"); }
public void testCsvEditorIsTextEditorWithInitialCsvEditorSettings() { FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(myFixture.getProject(), myFixture.getFile().getVirtualFile()); FileEditor fileEditor = fileEditorProviders[0].createEditor(myFixture.getProject(), myFixture.getFile().getVirtualFile()); assertInstanceOf(fileEditor, TextEditor.class); TextEditor textEditor = (TextEditor)fileEditor; CsvEditorSettingsExternalizable csvEditorSettingsExternalizable = CsvEditorSettingsExternalizable.getInstance(); EditorSettings editorSettings = textEditor.getEditor().getSettings(); assertEquals(csvEditorSettingsExternalizable.isCaretRowShown(), editorSettings.isCaretRowShown()); assertEquals(csvEditorSettingsExternalizable.isUseSoftWraps(), editorSettings.isUseSoftWraps()); disposeTextEditor(textEditor); }
public void testCsvEditorStateReadsAndWritesStates() { TextEditor textEditor = getCurrentTextEditor(); FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(myFixture.getProject(), myFixture.getFile().getVirtualFile()); CsvFileEditorProvider fileEditorProvider = (CsvFileEditorProvider)fileEditorProviders[0]; Element dummy = new Element("dummy"); FileEditorState state = fileEditorProvider.readState(dummy, this.getProject(), this.getFile().getVirtualFile()); assertInstanceOf(state, TextEditorState.class); textEditor.setState(state); fileEditorProvider.writeState(state, this.getProject(), dummy); disposeTextEditor(textEditor); }
private void runQuickFixTest(String annotationString, String expectedString) { final Project myProject = myFixture.getProject(); PsiAnnotation annotation = JavaPsiFacade.getInstance(myProject) .getElementFactory() .createAnnotationFromText(annotationString, null); MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(annotation, "", ProblemHighlightType.ERROR); ApiNamespaceInspection.MyQuickFix myQuickFix = new ApiNamespaceInspection().new MyQuickFix(); myQuickFix.applyFix(myProject, problemDescriptor); assertEquals(expectedString, annotation.getText()); }
public void testCsvFileEditorProviderIsAvailableAndHasCorrectNameAndPolicy() { FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(myFixture.getProject(), myFixture.getFile().getVirtualFile()); assertEquals(2, fileEditorProviders.length); assertInstanceOf(fileEditorProviders[0], CsvFileEditorProvider.class); FileEditorProvider fileEditorProvider = fileEditorProviders[0]; assertEquals(CsvFileEditorProvider.EDITOR_TYPE_ID, fileEditorProvider.getEditorTypeId()); assertEquals(FileEditorPolicy.HIDE_DEFAULT_EDITOR, fileEditorProvider.getPolicy()); CsvEditorSettingsExternalizable csvEditorSettingsExternalizable = CsvEditorSettingsExternalizable.getInstance(); csvEditorSettingsExternalizable.setEditorPrio(CsvEditorSettingsExternalizable.EditorPrio.TEXT_ONLY); assertEquals(FileEditorPolicy.HIDE_DEFAULT_EDITOR, fileEditorProvider.getPolicy()); csvEditorSettingsExternalizable.setEditorPrio(CsvEditorSettingsExternalizable.EditorPrio.TABLE_FIRST); assertEquals(FileEditorPolicy.PLACE_AFTER_DEFAULT_EDITOR, fileEditorProvider.getPolicy()); }