some testdata discoverability
[fedora-idea.git] / java / java-tests / testSrc / com / intellij / refactoring / IntroduceConstantTest.java
blobbb175be25c86df464f6074a1768f5ea2f17b46c9
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 com.intellij.testFramework.TestDataPath;
12 import junit.framework.Assert;
13 import org.jetbrains.annotations.NonNls;
15 /**
16 * @author ven
18 @TestDataPath("$CONTENT_ROOT/testData")
19 public class IntroduceConstantTest extends LightCodeInsightTestCase {
20 @NonNls private static final String BASE_PATH = "/refactoring/introduceConstant/";
22 @Override
23 protected String getTestDataPath() {
24 return JavaTestUtil.getJavaTestDataPath();
27 public void testInNonNls() throws Exception {
28 doTest(false);
31 private void doTest(boolean makeEnumConstant) throws Exception {
32 configureByFile(BASE_PATH + getTestName(false) + ".java");
33 convertLocal(makeEnumConstant);
34 checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
37 public void testEnumConstant() throws Exception {
38 doTest(true);
41 public void testAnnotationDescription() throws Exception {
42 configureByFile(BASE_PATH + getTestName(false) + ".java");
43 new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null);
44 checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
47 private static void convertLocal(final boolean makeEnumConstant) {
48 PsiLocalVariable local = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class);
49 new MockLocalToFieldHandler(getProject(), true, makeEnumConstant).convertLocalToField(local, getEditor());
52 public void testPartialStringLiteral() throws Exception {
53 configureByFile(BASE_PATH + getTestName(false) + ".java");
54 new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null);
55 checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
58 public void testPartialStringLiteralQualified() throws Exception {
59 configureByFile(BASE_PATH + getTestName(false) + ".java");
60 final PsiClass psiClass = ((PsiJavaFile)getFile()).getClasses()[0];
61 Assert.assertNotNull(psiClass);
62 final PsiClass targetClass = psiClass.findInnerClassByName("D", false);
63 Assert.assertNotNull(targetClass);
64 new MockIntroduceConstantHandler(targetClass).invoke(getProject(), getEditor(), getFile(), null);
65 checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
68 protected Sdk getProjectJDK() {
69 return JavaSdkImpl.getMockJdk15("java 1.5");