From 9dcee96734c135bd7f8528bd8a34df297109b8a6 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Wed, 30 Oct 2013 18:59:44 +0400 Subject: [PATCH] Move test methods to separate class --- ...stractAnnotationDescriptorResolveTest.java | 84 ++--------------- .../AnnotationDescriptorResolveTest.java | 93 +++++++++++++++++++ 2 files changed, 99 insertions(+), 78 deletions(-) create mode 100644 compiler/tests/org/jetbrains/jet/resolve/annotation/AnnotationDescriptorResolveTest.java diff --git a/compiler/tests/org/jetbrains/jet/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java b/compiler/tests/org/jetbrains/jet/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java index 6e3b2e00eec..7de3bfe6421 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java +++ b/compiler/tests/org/jetbrains/jet/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java @@ -41,7 +41,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -public class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture { +public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture { private static final String PATH = "compiler/testData/resolveAnnotations/testFile.kt"; private static final FqName NAMESPACE = new FqName("test"); @@ -53,79 +53,7 @@ public class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture { return JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable()); } - public void testIntAnnotation() throws IOException { - String content = getContent("AnnInt(1)"); - String expectedAnnotation = "AnnInt[a = 1.toInt(): jet.Int]"; - doTest(content, expectedAnnotation); - } - - public void testStringAnnotation() throws IOException { - String content = getContent("AnnString(\"test\")"); - String expectedAnnotation = "AnnString[a = \"test\": jet.String]"; - doTest(content, expectedAnnotation); - } - - public void testEnumAnnotation() throws IOException { - String content = getContent("AnnEnum(MyEnum.A)"); - String expectedAnnotation = "AnnEnum[a = MyEnum.A: test.MyEnum]"; - doTest(content, expectedAnnotation); - } - - public void testQualifiedEnumAnnotation() throws IOException { - String content = getContent("AnnEnum(test.MyEnum.A)"); - String expectedAnnotation = "AnnEnum[a = MyEnum.A: test.MyEnum]"; - doTest(content, expectedAnnotation); - } - - public void testUnqualifiedEnumAnnotation() throws IOException { - String content = getContent("AnnEnum(A)"); - String expectedAnnotation = "AnnEnum[a = MyEnum.A: test.MyEnum]"; - doTest(content, expectedAnnotation); - } - - public void testIntArrayAnnotation() throws IOException { - String content = getContent("AnnIntArray(intArray(1, 2))"); - String expectedAnnotation = "AnnIntArray[a = [1.toInt(), 2.toInt()]: jet.IntArray]"; - doTest(content, expectedAnnotation); - } - - public void testIntArrayVarargAnnotation() throws IOException { - String content = getContent("AnnIntVararg(1, 2)"); - String expectedAnnotation = "AnnIntVararg[a = [1.toInt(), 2.toInt()]: jet.IntArray]"; - doTest(content, expectedAnnotation); - } - - public void testStringArrayVarargAnnotation() throws IOException { - String content = getContent("AnnStringVararg(\"a\", \"b\")"); - String expectedAnnotation = "AnnStringVararg[a = [\"a\", \"b\"]: jet.Array]"; - doTest(content, expectedAnnotation); - } - - public void testStringArrayAnnotation() throws IOException { - String content = getContent("AnnStringArray(array(\"a\"))"); - String expectedAnnotation = "AnnStringArray[a = [\"a\"]: jet.Array]"; - doTest(content, expectedAnnotation); - } - - public void testEnumArrayAnnotation() throws IOException { - String content = getContent("AnnArrayOfEnum(array(MyEnum.A))"); - String expectedAnnotation = "AnnArrayOfEnum[a = [MyEnum.A]: jet.Array]"; - doTest(content, expectedAnnotation); - } - - public void testAnnotationAnnotation() throws Exception { - String content = getContent("AnnAnn(AnnInt(1))"); - String expectedAnnotation = "AnnAnn[a = AnnInt[a = 1.toInt()]: test.AnnInt]"; - doTest(content, expectedAnnotation); - } - - public void testJavaClassAnnotation() throws Exception { - String content = getContent("AnnClass(javaClass())"); - String expectedAnnotation = "AnnClass[a = MyClass.class: java.lang.Class]"; - doTest(content, expectedAnnotation); - } - - private void doTest(@NotNull String content, @NotNull String expectedAnnotation) { + protected void doTest(@NotNull String content, @NotNull String expectedAnnotation) { NamespaceDescriptor test = getNamespaceDescriptor(content); ClassDescriptor myClass = getClassDescriptor(test, "MyClass"); checkDescriptor(expectedAnnotation, myClass); @@ -205,7 +133,7 @@ public class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture { } @NotNull - private static ClassDescriptor getClassDescriptor(@NotNull NamespaceDescriptor namespaceDescriptor, @NotNull String name) { + protected static ClassDescriptor getClassDescriptor(@NotNull NamespaceDescriptor namespaceDescriptor, @NotNull String name) { Name className = Name.identifier(name); ClassifierDescriptor aClass = namespaceDescriptor.getMemberScope().getClassifier(className); assertNotNull("Failed to find class: " + namespaceDescriptor.getName() + "." + className, aClass); @@ -329,7 +257,7 @@ public class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture { } @NotNull - private NamespaceDescriptor getNamespaceDescriptor(@NotNull String content) { + protected NamespaceDescriptor getNamespaceDescriptor(@NotNull String content) { JetFile ktFile = JetTestUtils.createFile("dummy.kt", content, getProject()); context = JetTestUtils.analyzeFile(ktFile).getBindingContext(); @@ -338,13 +266,13 @@ public class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture { return namespaceDescriptor; } - private static String getContent(@NotNull String annotationText) throws IOException { + protected static String getContent(@NotNull String annotationText) throws IOException { File file = new File(PATH); String content = JetTestUtils.doLoadFile(file).replaceAll("ANNOTATION", annotationText); return content; } - private static void checkDescriptor(String expectedAnnotation, DeclarationDescriptor member) { + protected static void checkDescriptor(String expectedAnnotation, DeclarationDescriptor member) { String actual = StringUtil.join(member.getAnnotations(), new Function() { @Override public String fun(AnnotationDescriptor annotationDescriptor) { diff --git a/compiler/tests/org/jetbrains/jet/resolve/annotation/AnnotationDescriptorResolveTest.java b/compiler/tests/org/jetbrains/jet/resolve/annotation/AnnotationDescriptorResolveTest.java new file mode 100644 index 00000000000..0166ee459c8 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/resolve/annotation/AnnotationDescriptorResolveTest.java @@ -0,0 +1,93 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.resolve.annotation; + +import java.io.IOException; + +public class AnnotationDescriptorResolveTest extends AbstractAnnotationDescriptorResolveTest { + public void testIntAnnotation() throws IOException { + String content = getContent("AnnInt(1)"); + String expectedAnnotation = "AnnInt[a = 1.toInt(): jet.Int]"; + doTest(content, expectedAnnotation); + } + + public void testStringAnnotation() throws IOException { + String content = getContent("AnnString(\"test\")"); + String expectedAnnotation = "AnnString[a = \"test\": jet.String]"; + doTest(content, expectedAnnotation); + } + + public void testEnumAnnotation() throws IOException { + String content = getContent("AnnEnum(MyEnum.A)"); + String expectedAnnotation = "AnnEnum[a = MyEnum.A: test.MyEnum]"; + doTest(content, expectedAnnotation); + } + + public void testQualifiedEnumAnnotation() throws IOException { + String content = getContent("AnnEnum(test.MyEnum.A)"); + String expectedAnnotation = "AnnEnum[a = MyEnum.A: test.MyEnum]"; + doTest(content, expectedAnnotation); + } + + public void testUnqualifiedEnumAnnotation() throws IOException { + String content = getContent("AnnEnum(A)"); + String expectedAnnotation = "AnnEnum[a = MyEnum.A: test.MyEnum]"; + doTest(content, expectedAnnotation); + } + + public void testIntArrayAnnotation() throws IOException { + String content = getContent("AnnIntArray(intArray(1, 2))"); + String expectedAnnotation = "AnnIntArray[a = [1.toInt(), 2.toInt()]: jet.IntArray]"; + doTest(content, expectedAnnotation); + } + + public void testIntArrayVarargAnnotation() throws IOException { + String content = getContent("AnnIntVararg(1, 2)"); + String expectedAnnotation = "AnnIntVararg[a = [1.toInt(), 2.toInt()]: jet.IntArray]"; + doTest(content, expectedAnnotation); + } + + public void testStringArrayVarargAnnotation() throws IOException { + String content = getContent("AnnStringVararg(\"a\", \"b\")"); + String expectedAnnotation = "AnnStringVararg[a = [\"a\", \"b\"]: jet.Array]"; + doTest(content, expectedAnnotation); + } + + public void testStringArrayAnnotation() throws IOException { + String content = getContent("AnnStringArray(array(\"a\"))"); + String expectedAnnotation = "AnnStringArray[a = [\"a\"]: jet.Array]"; + doTest(content, expectedAnnotation); + } + + public void testEnumArrayAnnotation() throws IOException { + String content = getContent("AnnArrayOfEnum(array(MyEnum.A))"); + String expectedAnnotation = "AnnArrayOfEnum[a = [MyEnum.A]: jet.Array]"; + doTest(content, expectedAnnotation); + } + + public void testAnnotationAnnotation() throws Exception { + String content = getContent("AnnAnn(AnnInt(1))"); + String expectedAnnotation = "AnnAnn[a = AnnInt[a = 1.toInt()]: test.AnnInt]"; + doTest(content, expectedAnnotation); + } + + public void testJavaClassAnnotation() throws Exception { + String content = getContent("AnnClass(javaClass())"); + String expectedAnnotation = "AnnClass[a = MyClass.class: java.lang.Class]"; + doTest(content, expectedAnnotation); + } +}