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 d0d3d3f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 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){}
}
18 changes: 4 additions & 14 deletions src/test/java/spoon/test/generics/GenericsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,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 d0d3d3f

Please sign in to comment.