/* * Copyright (c) 2007 Mockito contributors * This program is made available under the terms of the MIT License. */ package org.mockito.internal.util.reflection; import org.junit.Test; import java.lang.reflect.Field; import java.lang.reflect.Type; import java.util.*; import static org.junit.Assert.assertEquals; public class GenericMasterTest { GenericMaster m = new GenericMaster(); List one; Set two; Map map; String nonGeneric; List> nested; List>> multiNested; public interface ListSet extends List> {} public interface MapNumberString extends Map {} public class HashMapNumberString extends HashMap {} public List numberList() { return null; } public Comparable numberComparable() { return null; } @SuppressWarnings("rawtypes") public List rawList() { return null; } public List typeList() { return null; } @Test public void should_find_generic_class() throws Exception { assertEquals(String.class, m.getGenericType(field("one"))); assertEquals(Integer.class, m.getGenericType(field("two"))); assertEquals(Double.class, m.getGenericType(field("map"))); } @Test public void should_get_object_for_non_generic() throws Exception { assertEquals(Object.class, m.getGenericType(field("nonGeneric"))); } @Test public void should_deal_with_nested_generics() throws Exception { assertEquals(Set.class, m.getGenericType(field("nested"))); assertEquals(Set.class, m.getGenericType(field("multiNested"))); } private Field field(String fieldName) throws SecurityException, NoSuchFieldException { return this.getClass().getDeclaredField(fieldName); } }