Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus committed Mar 14, 2017
1 parent c2403e1 commit 5a46a4b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import java.util.ArrayList;

@SuppressWarnings("serial")
public class ClassThatBindsAGenericType extends ArrayList<File> {
class ClassThatBindsAGenericType extends ArrayList<File> {

public static void main(String[] args) throws Exception {
}

}

class ClassThatDefinesANewTypeArgument<T> {
void foo(T t){}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package spoon.test.generics;

public class ClassThatDefinesANewTypeArgument<T> {
void foo(T t){}
}
23 changes: 7 additions & 16 deletions src/test/java/spoon/test/generics/GenericsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ public void testModelBuildingSimilarSignatureMethods() throws Exception {

@Test
public void testTypeParameterReference() throws Exception {
CtClass<?> classThatBindsAGenericType = build("spoon.test.generics", "ClassThatBindsAGenericType");
CtClass<?> classThatDefinesANewTypeArgument = classThatBindsAGenericType.getPackage().getElements(new NameFilter<CtClass<?>>("ClassThatDefinesANewTypeArgument")).get(0);
Factory factory = build(ClassThatBindsAGenericType.class, ClassThatDefinesANewTypeArgument.class);
CtClass<?> classThatBindsAGenericType = factory.Class().get(ClassThatBindsAGenericType.class);
CtClass<?> classThatDefinesANewTypeArgument = factory.Class().get(ClassThatDefinesANewTypeArgument.class);

CtTypeReference<?> tr1 = classThatBindsAGenericType.getSuperclass();
CtTypeReference<?> trExtends = tr1.getActualTypeArguments().get(0);
Expand All @@ -165,21 +166,11 @@ public void testTypeParameterReference() throws Exception {

@Test
public void testTypeParameterDeclarer() throws Exception {
CtClass<?> classThatBindsAGenericType = build("spoon.test.generics", "ClassThatBindsAGenericType");
CtClass<?> classThatDefinesANewTypeArgument = classThatBindsAGenericType.getPackage().getElements(new NameFilter<CtClass<?>>("ClassThatDefinesANewTypeArgument")).get(0);

CtTypeParameter typeParam = classThatDefinesANewTypeArgument.getFormalCtTypeParameters().get(0);
assertSame(typeParam.getParent(CtFormalTypeDeclarer.class), typeParam.getTypeParameterDeclarer());
}

@Test
public void testTypeParameterReferenceDeclaration() throws Exception {
CtClass<?> classThatBindsAGenericType = build("spoon.test.generics", "ClassThatBindsAGenericType");
CtClass<?> classThatDefinesANewTypeArgument = classThatBindsAGenericType.getPackage().getElements(new NameFilter<CtClass<?>>("ClassThatDefinesANewTypeArgument")).get(0);

// contract: one can navigate to the declarer of a type parameter
CtClass<?> classThatDefinesANewTypeArgument = build("spoon.test.generics", "ClassThatDefinesANewTypeArgument");
CtTypeParameter typeParam = classThatDefinesANewTypeArgument.getFormalCtTypeParameters().get(0);
//contract: the the reference to type parameter must be able to return the same type parameter
assertSame(typeParam, typeParam.getReference().getDeclaration());
assertSame(classThatDefinesANewTypeArgument, typeParam.getTypeParameterDeclarer());
assertSame(typeParam, typeParam.getReference().getDeclaration());
}

@Test
Expand Down

0 comments on commit 5a46a4b

Please sign in to comment.