1 package com.intellij.refactoring;
3 import com.intellij.JavaTestUtil;
4 import com.intellij.openapi.projectRoots.Sdk;
5 import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
6 import com.intellij.psi.PsiClass;
7 import com.intellij.psi.PsiJavaFile;
8 import com.intellij.psi.PsiLocalVariable;
9 import com.intellij.psi.util.PsiTreeUtil;
10 import com.intellij.testFramework.LightCodeInsightTestCase;
11 import junit.framework.Assert;
12 import org.jetbrains.annotations.NonNls;
17 public class IntroduceConstantTest extends LightCodeInsightTestCase {
18 @NonNls private static final String BASE_PATH = "/refactoring/introduceConstant/";
21 protected String getTestDataPath() {
22 return JavaTestUtil.getJavaTestDataPath();
25 public void testInNonNls() throws Exception {
29 private void doTest(boolean makeEnumConstant) throws Exception {
30 configureByFile(BASE_PATH + getTestName(false) + ".java");
31 convertLocal(makeEnumConstant);
32 checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
35 public void testEnumConstant() throws Exception {
39 public void testAnnotationDescription() throws Exception {
40 configureByFile(BASE_PATH + getTestName(false) + ".java");
41 new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null);
42 checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
45 private static void convertLocal(final boolean makeEnumConstant) {
46 PsiLocalVariable local = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class);
47 new MockLocalToFieldHandler(getProject(), true, makeEnumConstant).convertLocalToField(local, getEditor());
50 public void testPartialStringLiteral() throws Exception {
51 configureByFile(BASE_PATH + getTestName(false) + ".java");
52 new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null);
53 checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
56 public void testPartialStringLiteralQualified() throws Exception {
57 configureByFile(BASE_PATH + getTestName(false) + ".java");
58 final PsiClass psiClass = ((PsiJavaFile)getFile()).getClasses()[0];
59 Assert.assertNotNull(psiClass);
60 final PsiClass targetClass = psiClass.findInnerClassByName("D", false);
61 Assert.assertNotNull(targetClass);
62 new MockIntroduceConstantHandler(targetClass).invoke(getProject(), getEditor(), getFile(), null);
63 checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
66 protected Sdk getProjectJDK() {
67 return JavaSdkImpl.getMockJdk15("java 1.5");