From cf79dfa709009975e7ceee25d4bae60c3fe369d1 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 28 Dec 2023 15:17:38 +0100 Subject: [PATCH] Java: cleanup test GitOrigin-RevId: d5679c33a9ae8501227f38d23679e653ace4d591 --- ...taticContainerForCompileTimeConstant.java} | 0 ...ContainerForCompileTimeConstant_after.java | 9 +++ ...ticContainerForCompilerConstant_after.java | 11 --- .../refactoring/IntroduceConstantTest.java | 72 ++++++------------- 4 files changed, 32 insertions(+), 60 deletions(-) rename java/java-tests/testData/refactoring/introduceConstant/{NonStaticContainerForCompilerConstant.java => NonStaticContainerForCompileTimeConstant.java} (100%) create mode 100644 java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompileTimeConstant_after.java delete mode 100644 java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompilerConstant_after.java diff --git a/java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompilerConstant.java b/java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompileTimeConstant.java similarity index 100% rename from java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompilerConstant.java rename to java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompileTimeConstant.java diff --git a/java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompileTimeConstant_after.java b/java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompileTimeConstant_after.java new file mode 100644 index 000000000000..143ca154cecb --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompileTimeConstant_after.java @@ -0,0 +1,9 @@ +class Foo { + class Bar { + public static final String xxx = "42"; + + void foo() { + String str = xxx; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompilerConstant_after.java b/java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompilerConstant_after.java deleted file mode 100644 index 9143a7a17fd4..000000000000 --- a/java/java-tests/testData/refactoring/introduceConstant/NonStaticContainerForCompilerConstant_after.java +++ /dev/null @@ -1,11 +0,0 @@ -import org.jetbrains.annotations.NonNls; - -class Foo { - class Bar { - @NonNls - private static final String xxx = "42"; - - void foo() { - } - } -} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceConstantTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceConstantTest.java index 6fa49003805b..567dace8c832 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceConstantTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceConstantTest.java @@ -34,7 +34,7 @@ public class IntroduceConstantTest extends LightJavaCodeInsightTestCase { doTest(false); } - public void testNonStaticContainerForCompilerConstant() { + public void testNonStaticContainerForCompileTimeConstant() { configureByFile(BASE_PATH + getTestName(false) + ".java"); PsiLocalVariable local = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class); new MockLocalToFieldHandler(getProject(), true, false){ @@ -49,14 +49,13 @@ public class IntroduceConstantTest extends LightJavaCodeInsightTestCase { private void doTest(boolean makeEnumConstant) { configureByFile(BASE_PATH + getTestName(false) + ".java"); - convertLocal(makeEnumConstant); + PsiLocalVariable local = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class); + new MockLocalToFieldHandler(getProject(), true, makeEnumConstant).convertLocalToField(local, getEditor()); checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); } public void testFromEnumConstantInitializer() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testUnresolvedReferenceInEnum() { @@ -66,9 +65,7 @@ public class IntroduceConstantTest extends LightJavaCodeInsightTestCase { } public void testFromEnumConstantInitializer1() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testFromEnumConstantInitializer2() { @@ -82,44 +79,27 @@ public class IntroduceConstantTest extends LightJavaCodeInsightTestCase { } public void testAnonymousClassWithThrownClause() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testAnnotationDescription() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testTailingErrorUnacceptableWholeLineSelection() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); - } - - private void convertLocal(final boolean makeEnumConstant) { - PsiLocalVariable local = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class); - new MockLocalToFieldHandler(getProject(), true, makeEnumConstant).convertLocalToField(local, getEditor()); + doTest(); } public void testPartialStringLiteral() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testPartialStringLiteralConvertibleToInt() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testStringLiteralConvertibleToInt() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testPartialStringLiteralQualified() { @@ -133,39 +113,27 @@ public class IntroduceConstantTest extends LightJavaCodeInsightTestCase { } public void testPartialStringLiteralAnchor() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testPartialStringLiteralAnchorFromAnnotation() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testIntroduceConstantFromThisCall() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testForwardReferences() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testArrayFromVarargs() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testWithMethodReferenceBySecondSearch() { - configureByFile(BASE_PATH + getTestName(false) + ".java"); - new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + doTest(); } public void testComments() { @@ -237,4 +205,10 @@ public class IntroduceConstantTest extends LightJavaCodeInsightTestCase { } }.invoke(getProject(), getEditor(), getFile(), null); } + + private void doTest() { + configureByFile(BASE_PATH + getTestName(false) + ".java"); + new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null); + checkResultByFile(BASE_PATH + getTestName(false) + "_after.java"); + } }