Search in sources :

Example 6 with MockProblemDescriptor

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

the class NamedResourceInspectionTest method testQuickFix_noQueryNameSpecifiedWithoutParameter.

/**
 * Tests that the NamedResourceInspection's quick fix flagged with {@link
 * NamedResourceError#MISSING_NAME} for an @Named annotation with no parent updates the query name
 * to "myName".
 */
public void testQuickFix_noQueryNameSpecifiedWithoutParameter() {
    Project myProject = myFixture.getProject();
    String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_NAMED + "()";
    PsiAnnotation annotation = JavaPsiFacade.getInstance(myProject).getElementFactory().createAnnotationFromText(annotationString, null);
    NamedResourceInspection.MissingNameQuickFix myQuickFix = new NamedResourceInspection().new MissingNameQuickFix();
    MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(annotation, "", ProblemHighlightType.ERROR);
    myQuickFix.applyFix(myProject, problemDescriptor);
    assertEquals("@" + GctConstants.APP_ENGINE_ANNOTATION_NAMED + "(\"myName\")", annotation.getText());
}
Also used : Project(com.intellij.openapi.project.Project) MockProblemDescriptor(com.intellij.testFramework.MockProblemDescriptor) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Example 7 with MockProblemDescriptor

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

the class NamedResourceInspectionTest method testQuickFix_noQueryNameSpecifiedWithParameter.

/**
 * Tests that the NamedResourceInspection's quick fix flagged with {@link
 * NamedResourceError#MISSING_NAME} for an @Named annotation with a {@link PsiParameter} parent
 * updates the query name to to the name of the {@link PsiParameter}.
 */
public void testQuickFix_noQueryNameSpecifiedWithParameter() {
    Project myProject = myFixture.getProject();
    PsiParameter parameter = JavaPsiFacade.getInstance(myProject).getElementFactory().createParameterFromText("@javax.inject.Named() String foobar", null);
    PsiAnnotation[] annotationsList = parameter.getModifierList().getAnnotations();
    assert (annotationsList.length == 1);
    NamedResourceInspection.MissingNameQuickFix myQuickFix = new NamedResourceInspection().new MissingNameQuickFix();
    MockProblemDescriptor problemDescriptor = new MockProblemDescriptor(annotationsList[0], "", ProblemHighlightType.ERROR);
    myQuickFix.applyFix(myProject, problemDescriptor);
    assertEquals("@javax.inject.Named(\"foobar\")", annotationsList[0].getText());
}
Also used : Project(com.intellij.openapi.project.Project) PsiParameter(com.intellij.psi.PsiParameter) MockProblemDescriptor(com.intellij.testFramework.MockProblemDescriptor) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Example 8 with MockProblemDescriptor

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

the class ApiParameterInspectionTest method runQuickFixTest.

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

Example 9 with MockProblemDescriptor

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

the class FullMethodNameInspectionTest method testQuickFix_NonApiMethodAnnotation.

/**
 * Tests that the FullMethodNameInspection's quick fix does not update an annotation that is not
 * {@link GctConstants.APP_ENGINE_ANNOTATION_API_METHOD}
 */
public void testQuickFix_NonApiMethodAnnotation() {
    Project myProject = myFixture.getProject();
    String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_NAMED + "(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(annotationString, 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