Types { public static ParameterizedType newParameterizedType(Type rawType, Type... typeArguments) { return new ParameterizedTypeImpl(null, rawType, typeArguments); } private  Types(); static ParameterizedType newParameterizedType(Type rawType, Type... typeArguments); static ParameterizedType newParameterizedTypeWithOwner(
            Type ownerType, Type rawType, Type... typeArguments); static GenericArrayType arrayOf(Type componentType); static WildcardType subtypeOf(Type bound); static WildcardType supertypeOf(Type bound); static Class<?> getRawType(Type type); static boolean equals(@Nullable Type a, @Nullable Type b); static Type collectionElementType(Type context, Class<?> contextRawType);  }
@Test public void newParameterizedType() throws Exception { Type type = Types.newParameterizedType(List.class, A.class); assertThat(getFirstTypeArgument(type), is(Matchers.<Type>equalTo(A.class))); type = Types.newParameterizedTypeWithOwner(TypesTest.class, A.class, B.class); assertThat(getFirstTypeArgument(type), is(Matchers.<Type>equalTo(B.class))); }
@Test public void parameterizedTypeWithRequiredOwnerMissing() throws Exception { try { Types.newParameterizedType(A.class, B.class); fail(); } catch (IllegalArgumentException expected) { String message = "unexpected owner type for " + A.class + ": null"; assertThat(expected.getMessage(), is(equalTo(message))); } }
@Test public void newParameterizedTypeObjectMethods() throws Exception { Type mapOfStringIntegerType = TypesTest.class.getDeclaredField( "mapOfStringInteger").getGenericType(); ParameterizedType newMapType = Types.newParameterizedType(Map.class, String.class, Integer.class); assertThat(newMapType, is(equalTo(mapOfStringIntegerType))); assertThat(newMapType.hashCode(), is(equalTo(mapOfStringIntegerType.hashCode()))); assertThat(newMapType.toString(), is(equalTo(mapOfStringIntegerType.toString()))); Type arrayListOfMapOfStringIntegerType = TypesTest.class.getDeclaredField( "arrayListOfMapOfStringInteger").getGenericType(); ParameterizedType newListType = Types.newParameterizedType(ArrayList.class, newMapType); assertThat(newListType, is(equalTo(arrayListOfMapOfStringIntegerType))); assertThat(newListType.hashCode(), is(equalTo(arrayListOfMapOfStringIntegerType.hashCode()))); assertThat(newListType.toString(), is(equalTo(arrayListOfMapOfStringIntegerType.toString()))); }