Search in sources :

Example 1 with MockProblemDescriptor

use of com.intellij.testFramework.MockProblemDescriptor in project google-cloud-intellij by GoogleCloudPlatform.

the class ApiNamespaceInspectionTest method runQuickFixTest.

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());
}
Also used : Project(com.intellij.openapi.project.Project) MockProblemDescriptor(com.intellij.testFramework.MockProblemDescriptor) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Example 2 with MockProblemDescriptor

use of com.intellij.testFramework.MockProblemDescriptor in project google-cloud-intellij by GoogleCloudPlatform.

the class FullMethodNameInspectionTest method testQuickFix_ApiMethodAnnotation.

/**
 * Tests that the FullMethodNameInspection's quick fix updates the name attribute of {@link
 * GctConstants.APP_ENGINE_ANNOTATION_API_METHOD} by adding "_1" as a suffix.
 */
public void testQuickFix_ApiMethodAnnotation() {
    Project myProject = myFixture.getProject();
    String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_METHOD + "(name = \"someName\")";
    PsiAnnotation annotation = JavaPsiFacade.getInstance(myProject).getElementFactory().createAnnotationFromText(annotationString, null);
    FullMethodNameInspection.MyQuickFix myQuickFix = new FullMethodNameInspection().new MyQuickFix();
    MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(annotation, "", ProblemHighlightType.ERROR);
    myQuickFix.applyFix(myProject, problemDescriptor);
    Assert.assertEquals("@" + GctConstants.APP_ENGINE_ANNOTATION_API_METHOD + "(name = \"someName_1\")", annotation.getText());
}
Also used : Project(com.intellij.openapi.project.Project) MockProblemDescriptor(com.intellij.testFramework.MockProblemDescriptor) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Example 3 with MockProblemDescriptor

use of com.intellij.testFramework.MockProblemDescriptor in project google-cloud-intellij by GoogleCloudPlatform.

the class FullJavaNameInspectionTest method testQuickFix.

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());
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) MockProblemDescriptor(com.intellij.testFramework.MockProblemDescriptor)

Example 4 with MockProblemDescriptor

use of com.intellij.testFramework.MockProblemDescriptor in project google-cloud-intellij by GoogleCloudPlatform.

the class InvalidParameterAnnotationsInspectionTest method runQuickFixTest.

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());
}
Also used : MockProblemDescriptor(com.intellij.testFramework.MockProblemDescriptor)

Example 5 with MockProblemDescriptor

use of com.intellij.testFramework.MockProblemDescriptor in project google-cloud-intellij by GoogleCloudPlatform.

the class NamedResourceInspectionTest method testQuickFix_duplicateParameter.

/**
 * Tests that the NamedResourceInspection's quick fix flagged with {@link
 * NamedResourceError#DUPLICATE_PARAMETER} for an @Named annotation updates the query name by
 * adding "_1" as a suffix.
 */
public void testQuickFix_duplicateParameter() {
    Project myProject = myFixture.getProject();
    String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_NAMED + "(\"someName\")";
    PsiAnnotation annotation = JavaPsiFacade.getInstance(myProject).getElementFactory().createAnnotationFromText(annotationString, null);
    NamedResourceInspection.DuplicateNameQuickFix myQuickFix = new NamedResourceInspection().new DuplicateNameQuickFix();
    MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(annotation, "", ProblemHighlightType.ERROR);
    myQuickFix.applyFix(myProject, problemDescriptor);
    assertEquals("@" + GctConstants.APP_ENGINE_ANNOTATION_NAMED + "(\"someName_1\")", annotation.getText());
}
Also used : Project(com.intellij.openapi.project.Project) MockProblemDescriptor(com.intellij.testFramework.MockProblemDescriptor) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Aggregations

MockProblemDescriptor (com.intellij.testFramework.MockProblemDescriptor)9 Project (com.intellij.openapi.project.Project)7 PsiAnnotation (com.intellij.psi.PsiAnnotation)6 PsiParameter (com.intellij.psi.PsiParameter)2 PsiMethod (com.intellij.psi.PsiMethod)1