diff options
author | Siva Velusamy <vsiva@google.com> | 2014-02-11 18:27:57 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-02-11 18:27:57 +0000 |
commit | b3c54bfc83f00b9acde7375dd2efda25dbe70448 (patch) | |
tree | 1d8d267ea9795e51a9fdd2e8d5bd8f793b094e28 /testSrc | |
parent | 838d57a120b30f4557b75287eccda388a1eb9288 (diff) | |
parent | e0af0de1df97c6033b4e806de0b12f208773fab8 (diff) | |
download | cloud-b3c54bfc83f00b9acde7375dd2efda25dbe70448.tar.gz |
Merge "Quick Fix(Suggestion) for Api Namespace inspection" into idea133
Diffstat (limited to 'testSrc')
-rw-r--r-- | testSrc/com/google/gct/intellij/endpoints/validation/ApiNamespaceInspectionTest.java | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/testSrc/com/google/gct/intellij/endpoints/validation/ApiNamespaceInspectionTest.java b/testSrc/com/google/gct/intellij/endpoints/validation/ApiNamespaceInspectionTest.java index 8344365..9fb03e9 100644 --- a/testSrc/com/google/gct/intellij/endpoints/validation/ApiNamespaceInspectionTest.java +++ b/testSrc/com/google/gct/intellij/endpoints/validation/ApiNamespaceInspectionTest.java @@ -16,14 +16,23 @@ package com.google.gct.intellij.endpoints.validation; +import com.google.gct.intellij.endpoints.GctConstants; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; +import com.intellij.codeInspection.ex.ProblemDescriptorImpl; +import com.intellij.openapi.project.Project; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiAnnotation; +import org.junit.Assert; +import org.mockito.MockitoAnnotations; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Tests for {@link ApiNamespaceInspection} */ public class ApiNamespaceInspectionTest extends EndpointTestBase { - public void testApiNamespaceAttribute_complete() { doTest(); } @@ -44,6 +53,68 @@ public class ApiNamespaceInspectionTest extends EndpointTestBase { doTest(); } + public void testQuickFix_allAttributesSpecified() throws Exception { + String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"myName\", ownerDomain = \"myDomain\", packagePath = \"myPath\")"; + String expectedString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"myName\", ownerDomain = \"myDomain\", packagePath = \"myPath\")"; + runQuickFixTest(annotationString, expectedString); + } + + public void testQuickFix_noAttributesSpecified() throws Exception { + String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"\", ownerDomain = \"\", packagePath = \"\")"; + String expectedString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"YourCo\", ownerDomain = \"your-company.com\", packagePath = \"\")"; + runQuickFixTest(annotationString, expectedString); + } + + public void testQuickFix_nameAndDomainSet(){ + String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"myName\", ownerDomain = \"myDomain\", packagePath = \"\")"; + String expectedString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"myName\", ownerDomain = \"myDomain\", packagePath = \"\")"; + runQuickFixTest(annotationString, expectedString); + } + + public void testQuickFix_domainAndPathSet(){ + String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"\", ownerDomain = \"myDomain\", packagePath = \"myPath\")"; + String expectedString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"YourCo\", ownerDomain = \"myDomain\", packagePath = \"myPath\")"; + runQuickFixTest(annotationString, expectedString); + } + + public void testQuickFix_nameSet(){ + String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"myName\", ownerDomain = \"\", packagePath = \"\")"; + String expectedString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"myName\", ownerDomain = \"your-company.com\", packagePath = \"\")"; + runQuickFixTest(annotationString, expectedString); + } + + public void testQuickFix_pathSet(){ + String annotationString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"\", ownerDomain = \"\", packagePath = \"myPath\")"; + String expectedString = "@" + GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE + + "(ownerName = \"YourCo\", ownerDomain = \"your-company.com\", packagePath = \"myPath\")"; + runQuickFixTest(annotationString, expectedString); + } + + private void runQuickFixTest(String annotationString, String expectedString) { + Project myProject = myFixture.getProject(); + PsiAnnotation annotation = JavaPsiFacade.getInstance(myProject).getElementFactory() + .createAnnotationFromText(annotationString, null); + ProblemDescriptorImpl problemDescriptorMock = mock(ProblemDescriptorImpl.class); + when(problemDescriptorMock.getPsiElement()).thenReturn(annotation); + MockitoAnnotations.initMocks(this); + + + ApiNamespaceInspection.MyQuickFix myQuickFix = new ApiNamespaceInspection().new MyQuickFix(); + myQuickFix.applyFix(myProject, problemDescriptorMock); + Assert.assertEquals(expectedString, annotation.getText()); + } + private void doTest() { LocalInspectionTool localInspectionTool = new ApiNamespaceInspection(); String testName = getTestName(true); |