package com.googlecode.gentyref;

import java.lang.reflect.Type;

import junit.framework.TestCase;

/**
 * Simple samples of what gentyref does, in the form of tests.
 * See http://code.google.com/p/gentyref/wiki/ExampleUsage
 * 
 * @author Wouter Coekaerts <wouter@coekaerts.be>
 */
public class SamplesTest extends TestCase {
	interface Processor<T> {
		void process(T t);
	}
	
	class StringProcessor implements Processor<String> {
		public void process(String s) {
			System.out.println("processing " + s);
		}
	}
	
	class IntegerProcessor implements Processor<Integer> {
		public void process(Integer i) {
			System.out.println("processing " + i);
		}
	}
	
	/*
	 * Returns true if processorClass extends Processor<String>
	 */
	public boolean isStringProcessor(Class<? extends Processor<?>> processorClass) {
		// Use TypeToken to get an instanceof a specific Type
		Type type = new TypeToken<Processor<String>>(){}.getType();
		// Use GenericTypeReflector.isSuperType to check if a type is a supertype of another
		return GenericTypeReflector.isSuperType(type, processorClass);
	}
	
	public void testProsessor() {
		assertTrue(isStringProcessor(StringProcessor.class));
		assertFalse(isStringProcessor(IntegerProcessor.class));
	}
}

@@ -52,20 +52,159 @@
 reflect.
-Type
+Method;%0Aimport java.lang.reflect.ParameterizedType;%0Aimport java.lang.reflect.Type;%0Aimport java.lang.reflect.TypeVariable;%0Aimport java.util.List
 ;%0A%0Aimpor
@@ -1368,10 +1368,701 @@
 s));%0A%09%7D%0A
+%09%0A%09abstract class Lister%3CT%3E %7B%0A%09%09public List%3CT%3E list() %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%7D%0A%09%0A%09class StringLister extends Lister%3CString%3E %7B%0A%09%7D%0A%09%0A%09public void testFooBar() throws NoSuchMethodException %7B%0A%09%09Method listMethod = StringLister.class.getMethod(%22list%22);%0A%09%09%0A%09%09// java returns List%3CT%3E%0A%09%09Type returnType = listMethod.getGenericReturnType();%0A%09%09assertTrue(returnType instanceof ParameterizedType);%0A%09%09assertTrue(((ParameterizedType)returnType).getActualTypeArguments()%5B0%5D instanceof TypeVariable);%0A%09%09%0A%09%09// we get List%3CString%3E%0A%09%09Type exactReturnType = GenericTypeReflector.getExactReturnType(listMethod, StringLister.class);%0A%09%09assertEquals(new TypeToken%3CList%3CString%3E%3E()%7B%7D.getType(), exactReturnType);%0A%09%7D%0A
 %7D%0A

add sample for getExactReturnType