package com.googlecode.gentyref;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

/**
 * see http://code.google.com/p/gentyref/wiki/CaptureType
 * 
 * @author Wouter Coekaerts <wouter@coekaerts.be>
 */
public class CaptureSamplesTest extends TestCase {
		class Foo<T> {
			public List<? extends Number> listWildcard;
			public List<T> listT;
		}
	
	public void testFoo() throws NoSuchFieldException {
		Foo<? extends Number> foo = new Foo<Integer>();
		foo.listWildcard = new ArrayList<Long>();
		//foo.listT = new ArrayList<Long>(); // does not compile
		
		Type fooWildcard = new TypeToken<Foo<? extends Number>>(){}.getType();
		
		Type listWildcardFieldType = GenericTypeReflector.getExactFieldType(Foo.class.getField("listWildcard"), fooWildcard);
		Type listTFieldType = GenericTypeReflector.getExactFieldType(Foo.class.getField("listT"), fooWildcard);
		
		assertEquals(new TypeToken<List<? extends Number>>(){}.getType(), listWildcardFieldType);
		assertTrue(GenericTypeReflector.isSuperType(listWildcardFieldType, new TypeToken<ArrayList<Long>>(){}.getType()));
		assertFalse(GenericTypeReflector.isSuperType(listTFieldType, new TypeToken<ArrayList<Long>>(){}.getType()));
	}
}

@@ -315,17 +315,16 @@
 tCase %7B%0A
-%09
 %09class F
@@ -333,24 +333,16 @@
 %3CT%3E %7B%0A%09%09
-%09public 
 List%3C? e
@@ -372,24 +372,16 @@
 card;%0A%09%09
-%09public 
 List%3CT%3E 
@@ -387,17 +387,16 @@
  listT;%0A
-%09
 %09%7D%0A%09%0A%09pu
@@ -752,32 +752,40 @@
 pe(Foo.class.get
+Declared
 Field(%22listWildc
@@ -881,16 +881,24 @@
 lass.get
+Declared
 Field(%22l
@@ -1245,10 +1245,430 @@
 )));%0A%09%7D%0A
+%09%0A%09class Bar%3CT extends Number%3E %7B%0A%09%09T t;%0A%09%7D%0A%09%0A%09@SuppressWarnings(%22unused%22)%0A%09public void testBar() throws NoSuchFieldException %7B%0A%09%09Bar%3C?%3E bar = new Bar%3CInteger%3E();%0A%09%09Number n = bar.t;%0A%09%09%0A%09%09Type barType = new TypeToken%3CBar%3C?%3E%3E()%7B%7D.getType();%0A%09%09Type captureType = GenericTypeReflector.getExactFieldType(Bar.class.getDeclaredField(%22t%22), barType);%0A%09%09assertTrue(GenericTypeReflector.isSuperType(Number.class, captureType));%0A%09%7D%0A
 %7D%0A

Test for new sample for capture conversion added in wiki