Move test methods to separate class
This commit is contained in:
+6
-78
@@ -41,7 +41,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
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 String PATH = "compiler/testData/resolveAnnotations/testFile.kt";
|
||||||
|
|
||||||
private static final FqName NAMESPACE = new FqName("test");
|
private static final FqName NAMESPACE = new FqName("test");
|
||||||
@@ -53,79 +53,7 @@ public class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture {
|
|||||||
return JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable());
|
return JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIntAnnotation() throws IOException {
|
protected void doTest(@NotNull String content, @NotNull String expectedAnnotation) {
|
||||||
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<jet.String>]";
|
|
||||||
doTest(content, expectedAnnotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testStringArrayAnnotation() throws IOException {
|
|
||||||
String content = getContent("AnnStringArray(array(\"a\"))");
|
|
||||||
String expectedAnnotation = "AnnStringArray[a = [\"a\"]: jet.Array<jet.String>]";
|
|
||||||
doTest(content, expectedAnnotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEnumArrayAnnotation() throws IOException {
|
|
||||||
String content = getContent("AnnArrayOfEnum(array(MyEnum.A))");
|
|
||||||
String expectedAnnotation = "AnnArrayOfEnum[a = [MyEnum.A]: jet.Array<test.MyEnum>]";
|
|
||||||
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<MyClass>())");
|
|
||||||
String expectedAnnotation = "AnnClass[a = MyClass.class: java.lang.Class<test.MyClass>]";
|
|
||||||
doTest(content, expectedAnnotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doTest(@NotNull String content, @NotNull String expectedAnnotation) {
|
|
||||||
NamespaceDescriptor test = getNamespaceDescriptor(content);
|
NamespaceDescriptor test = getNamespaceDescriptor(content);
|
||||||
ClassDescriptor myClass = getClassDescriptor(test, "MyClass");
|
ClassDescriptor myClass = getClassDescriptor(test, "MyClass");
|
||||||
checkDescriptor(expectedAnnotation, myClass);
|
checkDescriptor(expectedAnnotation, myClass);
|
||||||
@@ -205,7 +133,7 @@ public class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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);
|
Name className = Name.identifier(name);
|
||||||
ClassifierDescriptor aClass = namespaceDescriptor.getMemberScope().getClassifier(className);
|
ClassifierDescriptor aClass = namespaceDescriptor.getMemberScope().getClassifier(className);
|
||||||
assertNotNull("Failed to find class: " + namespaceDescriptor.getName() + "." + className, aClass);
|
assertNotNull("Failed to find class: " + namespaceDescriptor.getName() + "." + className, aClass);
|
||||||
@@ -329,7 +257,7 @@ public class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private NamespaceDescriptor getNamespaceDescriptor(@NotNull String content) {
|
protected NamespaceDescriptor getNamespaceDescriptor(@NotNull String content) {
|
||||||
JetFile ktFile = JetTestUtils.createFile("dummy.kt", content, getProject());
|
JetFile ktFile = JetTestUtils.createFile("dummy.kt", content, getProject());
|
||||||
context = JetTestUtils.analyzeFile(ktFile).getBindingContext();
|
context = JetTestUtils.analyzeFile(ktFile).getBindingContext();
|
||||||
|
|
||||||
@@ -338,13 +266,13 @@ public class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture {
|
|||||||
return namespaceDescriptor;
|
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);
|
File file = new File(PATH);
|
||||||
String content = JetTestUtils.doLoadFile(file).replaceAll("ANNOTATION", annotationText);
|
String content = JetTestUtils.doLoadFile(file).replaceAll("ANNOTATION", annotationText);
|
||||||
return content;
|
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<AnnotationDescriptor, String>() {
|
String actual = StringUtil.join(member.getAnnotations(), new Function<AnnotationDescriptor, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String fun(AnnotationDescriptor annotationDescriptor) {
|
public String fun(AnnotationDescriptor annotationDescriptor) {
|
||||||
|
|||||||
+93
@@ -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<jet.String>]";
|
||||||
|
doTest(content, expectedAnnotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStringArrayAnnotation() throws IOException {
|
||||||
|
String content = getContent("AnnStringArray(array(\"a\"))");
|
||||||
|
String expectedAnnotation = "AnnStringArray[a = [\"a\"]: jet.Array<jet.String>]";
|
||||||
|
doTest(content, expectedAnnotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEnumArrayAnnotation() throws IOException {
|
||||||
|
String content = getContent("AnnArrayOfEnum(array(MyEnum.A))");
|
||||||
|
String expectedAnnotation = "AnnArrayOfEnum[a = [MyEnum.A]: jet.Array<test.MyEnum>]";
|
||||||
|
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<MyClass>())");
|
||||||
|
String expectedAnnotation = "AnnClass[a = MyClass.class: java.lang.Class<test.MyClass>]";
|
||||||
|
doTest(content, expectedAnnotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user